]> gitweb.factorcode.org Git - factor.git/commitdiff
boids: fix wrap-pos to wrap at row/col 511 instead of 510. clean-macosx-x86-32
authorJohn Benediktsson <mrjbq7@gmail.com>
Sat, 27 Jul 2019 01:38:08 +0000 (18:38 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Sat, 27 Jul 2019 01:38:08 +0000 (18:38 -0700)
extra/boids/boids.factor
extra/boids/simulation/simulation.factor

index 665488d62d68bd96321e42a6eeeca4068aa7a0a8..037ba4acca1efb6103b070e3ed443b1592a35b23 100644 (file)
@@ -26,7 +26,7 @@ CONSTANT: initial-dt 5
 : <boids-gadget> ( -- gadget )
     boids-gadget new
         t >>clipped?
-        ${ width height } >>pref-dim
+        ${ WIDTH HEIGHT } >>pref-dim
         initial-population random-boids >>boids
         initial-behaviours >>behaviours
         initial-dt >>dt ;
index 62fb1d8e98ed2da530435d1da233ba5937e0bd14..f5a153171064d4532bf0ede130fb165c5d53879d 100644 (file)
@@ -5,8 +5,8 @@ USING: accessors arrays combinators.short-circuit kernel
 locals math math.vectors random sequences ;
 IN: boids.simulation
 
-CONSTANT: width 512
-CONSTANT: height 512
+CONSTANT: WIDTH 512
+CONSTANT: HEIGHT 512
 
 TUPLE: behaviour
     { weight float }
@@ -51,7 +51,6 @@ C: <boid> boid
 :: neighbors ( boid boids behaviour -- neighbors )
     boid boids [ behaviour within-neighborhood? ] with filter ;
 
-
 GENERIC: force ( neighbors boid behaviour -- force )
 
 :: (force) ( boid boids behaviour -- force )
@@ -59,8 +58,7 @@ GENERIC: force ( neighbors boid behaviour -- force )
     [ { 0.0 0.0 } ] [ boid behaviour force ] if-empty ;
 
 : wrap-pos ( pos -- pos )
-    width height [ 1 - ] bi@ 2array
-    [ [ + ] keep mod ] 2map ;
+    WIDTH HEIGHT 2array [ [ + ] keep mod ] 2map ;
 
 :: simulate ( boids behaviours dt -- boids )
     boids [| boid |
@@ -75,7 +73,7 @@ GENERIC: force ( neighbors boid behaviour -- force )
 
 : random-boids ( count -- boids )
     [
-        width height [ random ] bi@ 2array
+        WIDTH HEIGHT [ random ] bi@ 2array
         2 [ 0 1 normal-random-float ] replicate
         <boid>
     ] replicate ;