Page 1 of 2

Boids

Posted: Mon Jan 18, 2016 4:08 pm
by prixt
Just a visual toy. Made for fun.

Re: Boids

Posted: Mon Jan 18, 2016 5:10 pm
by alberto_lara
Nice, that's a swarm algorithm right?

Re: Boids

Posted: Mon Jan 18, 2016 5:11 pm
by ivan
Cool demo.
I have a couple of suggestions about the code:

Code: Select all

closest = {x=boid.x,y=boid.y}
The line above creates a lot of intermediate tables, you can just use 2 variables or do:

Code: Select all

closest.x, closest.y = boid.x, boid.y
Another thing:

Code: Select all

	local angle_diff = target_angle - self.angle
	if math.abs(angle_diff) > math.pi then
		if angle_diff > 0 then
			angle_diff = -(2*math.pi-target_angle+self.angle)
		else
			angle_diff = 2*math.pi-self.angle+target_angle
		end
	end
	if angle_diff > 0 then
		self.angle = self.angle + power*dt
	else
		self.angle = self.angle - power*dt
	end
Could become:

Code: Select all

local angle_diff = (self.angle - target_angle + math.pi)%(2*math.pi) - math.pi
if angle_diff ~= 0 then
  local dir = angle_diff/math.abs(angle_diff)
  self.angle = self.angle + dir*power*dt
end
The examples are untested, but should work as I've used these before.

Re: Boids

Posted: Mon Jan 18, 2016 5:24 pm
by bobbyjones
I haven't looked at the code but it seems to get horrible performance on Android. Do you use spritebatches to render the triangles?

Re: Boids

Posted: Mon Jan 18, 2016 5:41 pm
by alberto_lara
He's calling love.graphics.polygon for each triangle so I guess this is equivalent to start and end the batch once per triangle, in Android. Maybe drawing all of them to a canvas would solve it?

Re: Boids

Posted: Mon Jan 18, 2016 6:28 pm
by bobbyjones
Using a spritebatch would too. He just needs a triangle image.

Re: Boids

Posted: Tue Jan 19, 2016 12:40 am
by rmcode
Very cool! Would love to have this as a screensaver.

Re: Boids

Posted: Sat Jan 23, 2016 8:07 pm
by qubodup

Re: Boids

Posted: Thu Jan 28, 2016 10:14 pm
by NightKawata
now the next step is for someone to create texture mods

i recommend ants

i would like to see ants swarming around

then the next step is to make an anthill background

duuuuuude ant simulator 2016 that's official as f*** yo


-------------------------------------------------

I like the music and really cannot stop being reminded of ants, though. :P
Would turn into a nice Ant Simulator or Cockroach Simulator; I mean seriously, who doesn't love anthills

Re: Boids

Posted: Tue Feb 02, 2016 8:54 pm
by alberto_lara
then the next step is to make an anthill background
Or flying birds!