From 4201c2149b66d5ce45a9e45be95459256486a7ea Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Fri, 26 Jul 2019 18:38:08 -0700 Subject: [PATCH] boids: fix wrap-pos to wrap at row/col 511 instead of 510. --- extra/boids/boids.factor | 2 +- extra/boids/simulation/simulation.factor | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/extra/boids/boids.factor b/extra/boids/boids.factor index 665488d62d..037ba4acca 100644 --- a/extra/boids/boids.factor +++ b/extra/boids/boids.factor @@ -26,7 +26,7 @@ CONSTANT: initial-dt 5 : ( -- 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 ; diff --git a/extra/boids/simulation/simulation.factor b/extra/boids/simulation/simulation.factor index 62fb1d8e98..f5a1531710 100644 --- a/extra/boids/simulation/simulation.factor +++ b/extra/boids/simulation/simulation.factor @@ -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 :: 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 ] replicate ;