diff --git a/extra/boids/boids.factor b/extra/boids/boids.factor index e6c97b90dd..cff33c9d19 100644 --- a/extra/boids/boids.factor +++ b/extra/boids/boids.factor @@ -6,14 +6,17 @@ USING: combinators.short-circuit kernel namespaces math.order math.vectors math.trig + math.physics.pos + math.physics.vel combinators arrays sequences random vars - combinators.lib ; + combinators.lib + accessors ; IN: boids ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -TUPLE: boid pos vel ; +TUPLE: boid < vel ; C: boid @@ -70,7 +73,7 @@ VAR: separation-radius ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -: distance ( boid boid -- n ) [ boid-pos ] [ boid-pos ] bi* v- norm ; +: distance ( boid boid -- n ) [ pos>> ] [ pos>> ] bi* v- norm ; ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! @@ -81,10 +84,10 @@ VAR: separation-radius ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -: relative-position ( self other -- v ) swap [ boid-pos ] bi@ v- ; +: relative-position ( self other -- v ) swap [ pos>> ] bi@ v- ; : relative-angle ( self other -- angle ) -over boid-vel -rot relative-position angle-between ; +over vel>> -rot relative-position angle-between ; ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! @@ -92,9 +95,9 @@ over boid-vel -rot relative-position angle-between ; : vaverage ( seq-of-vectors -- seq ) [ vsum ] [ length ] bi v/n ; -: average-position ( boids -- pos ) [ boid-pos ] map vaverage ; +: average-position ( boids -- pos ) [ pos>> ] map vaverage ; -: average-velocity ( boids -- vel ) [ boid-vel ] map vaverage ; +: average-velocity ( boids -- vel ) [ vel>> ] map vaverage ; ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! @@ -123,7 +126,7 @@ over boid-vel -rot relative-position angle-between ; dup cohesion-neighborhood dup empty? [ 2drop { 0 0 } ] - [ average-position swap boid-pos v- normalize* cohesion-weight> v*n ] + [ average-position swap pos>> v- normalize* cohesion-weight> v*n ] if ; ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! @@ -143,7 +146,7 @@ over boid-vel -rot relative-position angle-between ; dup separation-neighborhood dup empty? [ 2drop { 0 0 } ] - [ average-position swap boid-pos swap v- normalize* separation-weight> v*n ] + [ average-position swap pos>> swap v- normalize* separation-weight> v*n ] if ; ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! @@ -206,10 +209,10 @@ cond ; ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -: new-pos ( boid -- pos ) [ boid-pos ] [ boid-vel time-slice> v*n ] bi v+ ; +: new-pos ( boid -- pos ) [ pos>> ] [ vel>> time-slice> v*n ] bi v+ ; : new-vel ( boid -- vel ) - [ boid-vel ] [ acceleration time-slice> v*n ] bi v+ normalize* ; + [ vel>> ] [ acceleration time-slice> v*n ] bi v+ normalize* ; : wrap-pos ( pos -- pos ) { [ wrap-x ] [ wrap-y ] } parallel-call ; diff --git a/extra/boids/ui/ui.factor b/extra/boids/ui/ui.factor index e3c54e0744..ab1f8e5f80 100755 --- a/extra/boids/ui/ui.factor +++ b/extra/boids/ui/ui.factor @@ -19,7 +19,8 @@ USING: combinators.short-circuit kernel namespaces ui.gadgets.packs ui.gadgets.grids ui.gestures - assocs.lib vars rewrite-closures boids ; + assocs.lib vars rewrite-closures boids accessors + math.geometry.rect ; IN: boids.ui @@ -27,9 +28,9 @@ IN: boids.ui ! draw-boid ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -: point-a ( boid -- a ) boid-pos ; +: point-a ( boid -- a ) pos>> ; -: point-b ( boid -- b ) [ boid-pos ] [ boid-vel normalize* 20 v*n ] bi v+ ; +: point-b ( boid -- b ) [ pos>> ] [ vel>> normalize* 20 v*n ] bi v+ ; : boid-points ( boid -- point-a point-b ) [ point-a ] [ point-b ] bi ;