«Boids Example» by xffff
on 21 Dec'12 23:37 inExample of BoidRoids in use
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
// quick example to show use of BoidRoids class ( var numboids, boids, run, w, m, boidcolour, maxvel; numboids = 100; run=true; boids=BoidRoids(numboids); boids.separation(0.5); boids.alignment(0.3); boids.coherence(0.5); boids.inertia(0.3); boids.friction(0.5); boids.septhresh(0.02); maxvel = 0.75; boids.maxvel(maxvel); boids.gravity(0.25); boids.gravpoint(0.5,0.5); boidcolour = Array.fill(numboids,{Color.rand}); w = Window.new.front; w.view.background_(Color.white); w.drawFunc = { var theseboids = boids.getBoids; numboids.do{ |i| QPen.fillColor = boidcolour[i]; QPen.use{ QPen.fillOval( Rect(theseboids[i][0].linlin(0,1,0,400), theseboids[i][1].linlin(0,1,0,400), theseboids[i][2].linlin(0,maxvel/2,10,100), theseboids[i][3].linlin(0,maxvel/2,10,100)) ); QPen.perform(\fill); }; }; }; { while { run } { w.refresh; (1/24).wait;} }.fork(AppClock); w.onClose_({run=false}); )
reception
Nice! Thank you so much for posting this.