From 7f95ed0b3ee14ca0a14a193d7bb7ac78680d5207 Mon Sep 17 00:00:00 2001 From: Anton Gorenko Date: Sun, 22 May 2011 17:07:55 +0600 Subject: [PATCH] fix 'boids' and move it from unmantained to extra; --- {unmaintained => extra}/boids/authors.txt | 1 + extra/boids/boids.factor | 159 ++++++++++ extra/boids/simulation/authors.txt | 2 + extra/boids/simulation/simulation.factor | 101 ++++++ extra/boids/summary.txt | 1 + unmaintained/boids/boids.factor | 363 ---------------------- unmaintained/boids/summary.txt | 1 - 7 files changed, 264 insertions(+), 364 deletions(-) rename {unmaintained => extra}/boids/authors.txt (53%) create mode 100644 extra/boids/boids.factor create mode 100644 extra/boids/simulation/authors.txt create mode 100644 extra/boids/simulation/simulation.factor create mode 100644 extra/boids/summary.txt delete mode 100644 unmaintained/boids/boids.factor delete mode 100644 unmaintained/boids/summary.txt diff --git a/unmaintained/boids/authors.txt b/extra/boids/authors.txt similarity index 53% rename from unmaintained/boids/authors.txt rename to extra/boids/authors.txt index 6cfd5da273..0eab06eae8 100644 --- a/unmaintained/boids/authors.txt +++ b/extra/boids/authors.txt @@ -1 +1,2 @@ Eduardo Cavazos +Anton Gorenko diff --git a/extra/boids/boids.factor b/extra/boids/boids.factor new file mode 100644 index 0000000000..27afc062b3 --- /dev/null +++ b/extra/boids/boids.factor @@ -0,0 +1,159 @@ +! Copyright (C) 2008 Eduardo Cavazos. +! Copyright (C) 2011 Anton Gorenko. +! See http://factorcode.org/license.txt for BSD license. +USING: accessors arrays boids.simulation calendar classes kernel +literals locals math math.functions math.trig models namespaces +opengl opengl.demo-support opengl.gl sequences threads ui +ui.gadgets ui.gadgets.borders ui.gadgets.buttons +ui.gadgets.frames ui.gadgets.grids ui.gadgets.labeled +ui.gadgets.labels ui.gadgets.packs ui.gadgets.sliders ui.render ; +QUALIFIED-WITH: models.range mr +IN: boids + +TUPLE: boids-gadget < gadget paused boids behaviours dt ; + +CONSTANT: initial-population 100 +CONSTANT: initial-dt 5 + +: initial-behaviours ( -- seq ) + 1.0 75 -0.1 + 1.0 40 -0.5 + 1.0 25 -1.0 + 3array ; + +: ( -- gadget ) + boids-gadget new + t >>clipped? + ${ width height } >>pref-dim + initial-population random-boids >>boids + initial-behaviours >>behaviours + initial-dt >>dt ; + +M: boids-gadget ungraft* + t >>paused drop ; + +: vec>deg ( vec -- deg ) + first2 rect> arg rad>deg ; inline + +: draw-boid ( boid -- ) + dup pos>> [ + vel>> vec>deg 0 0 1 glRotated + GL_TRIANGLES [ + -6.0 4.0 glVertex2f + -6.0 -4.0 glVertex2f + 8.0 0.0 glVertex2f + ] do-state + ] with-translation ; + +: draw-boids ( boids -- ) + 0.0 0.0 0.0 0.5 glColor4f + [ draw-boid ] each ; + +M:: boids-gadget draw-gadget* ( boids-gadget -- ) + origin get + [ boids-gadget boids>> draw-boids ] with-translation ; + +: iterate-system ( boids-gadget -- ) + dup [ boids>> ] [ behaviours>> ] [ dt>> ] tri + simulate >>boids drop ; + +:: start-boids-thread ( gadget -- ) + [ + [ gadget paused>> ] + [ + gadget iterate-system + gadget relayout-1 + 10 milliseconds sleep + ] until + ] in-thread ; + +TUPLE: range-observer quot ; + +M: range-observer model-changed + [ range-value ] dip quot>> call( value -- ) ; + +: connect ( range-model quot -- ) + range-observer boa swap add-connection ; + +:: behavior-panel ( behavior -- gadget ) + 2 3 { 2 4 } >>gap { 0 0 } >>filled-cell + + "weight"