Skip to content
Permalink
Browse files

boids: fix wrap-pos to wrap at row/col 511 instead of 510.

  • Loading branch information...
mrjbq7 committed Jul 27, 2019
1 parent 9135c82 commit 4201c2149b66d5ce45a9e45be95459256486a7ea
Showing with 5 additions and 7 deletions.
  1. +1 −1 extra/boids/boids.factor
  2. +4 −6 extra/boids/simulation/simulation.factor
@@ -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 ;
@@ -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,16 +51,14 @@ 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 )
boid boids behaviour neighbors
[ { 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 ;

0 comments on commit 4201c21

Please sign in to comment.
You can’t perform that action at this time.