A hungry swarm indeed.
First, study the Boid Algorithm .
I’m new to Ruby. I’m seeking refactors to:- Increase code clarity
- Reduce code size
- Destroy bugs
- Optimize for speed (especially for large swarms)
Tested with Shoes 0.r811, OSX, Windows XP & Ubuntu Linux.
Change Log:- v0.1 – The initial swarm.
- v0.2 – Replaced custom random method with (min..max).rand. Mouse clicks now add food. Careful not to add too much as all food re-spawns.
- v0.3 – Magnus Adamsson – Seems Shoes 0.r646 can no longer draw a zero radius circle
- v0.4 – Wally Glutton – No longer using a $app global to access Shoes methods within the Food and Boid classes. – Moved class definitions above Shoes.app block as this was causing a problem for OSX builds. – Decreased the Stay Visible Damper by 50. – Fixed some spelling errors. – Assigned explicit app title, height & width.
Speak now or forever hold your peace:
rmulliga@rtmlap:~/rb/shoes$ diff hungry_boids_v0.1.rb hungry_boids_v0.2.rb 28a29,31 > click do |_,x,y| > foodstuff.push Food.new(x,y) > end 58,59c61,62 < def initialize < spawn
> def initialize(x=(rand$app.width),y=(rand$app.height)) > spawn(x,y) 61c64 < def spawn
> def spawn(x=(rand$app.width),y=(rand$app.height)) 63c66 < @position = VectorK.new rand * $app.width, rand * $app.height
@position = VectorK.new x,y
actually i see one bug in os x: the shapes sometimes flicker in and out, showing the white background instead. if i add more food, it gets worse. i can only really observe this on the food. the boids themselves move too fast for me to tell if this happens.
I noticed this food flashing under Ubuntu Linux too.
I really like this. Used to play around with boids like agent sims for years in qbasic wayyyyy back. I’m thinking I might have to have a play with your code. Thanks :)
it doesnt work any more with the new build of shoes :(
oh and i’m using osx..
Seems Shoes 0.r646 can’t draw a zero radius circle. I took the liberty of fixing the code.

cute! works fine in os x. i would also like to see how an experienced rubyist would refactor this.