## Boids

prixt
Prole
Posts: 26
Joined: Sat Sep 12, 2015 5:53 am

### Boids

Just a visual toy. Made for fun.
Attachments
boids.love

alberto_lara
Party member
Posts: 327
Joined: Wed Oct 30, 2013 8:59 pm

### Re: Boids

Nice, that's a swarm algorithm right?
LÖVE Projects: GOOi, Süsse, Dyzön and Katsudö
Thanks for taking the time and read this

ivan
Party member
Posts: 1399
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

### Re: Boids

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.

bobbyjones
Party member
Posts: 695
Joined: Sat Apr 26, 2014 7:46 pm

### Re: Boids

I haven't looked at the code but it seems to get horrible performance on Android. Do you use spritebatches to render the triangles?

alberto_lara
Party member
Posts: 327
Joined: Wed Oct 30, 2013 8:59 pm

### Re: Boids

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?
LÖVE Projects: GOOi, Süsse, Dyzön and Katsudö
Thanks for taking the time and read this

bobbyjones
Party member
Posts: 695
Joined: Sat Apr 26, 2014 7:46 pm

### Re: Boids

Using a spritebatch would too. He just needs a triangle image.

rmcode
Party member
Posts: 453
Joined: Tue Jul 15, 2014 12:04 pm
Location: Germany
Contact:

### Re: Boids

Very cool! Would love to have this as a screensaver.

qubodup
Inner party member
Posts: 775
Joined: Sat Jun 21, 2008 9:21 pm
Location: Berlin, Germany
Contact:

### Re: Boids

lg.newImage("cat.png") -- made possible by lg = love.graphics
-- Don't force fullscreen (it frustrates those who want to try your game real quick) -- Develop for 1280x720 (so people can make HD videos)

NightKawata
Party member
Posts: 290
Joined: Tue Jan 01, 2013 9:18 pm
Location: Cyberspace, Room 6502
Contact:

### Re: Boids

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.
Would turn into a nice Ant Simulator or Cockroach Simulator; I mean seriously, who doesn't love anthills
"I view Python for game usage about the same as going fishing with a stick of dynamite. It will do the job but it's big, noisy, you'll probably get soaking wet and you've still got to get the damn fish out of the water." -taylor

alberto_lara
Party member
Posts: 327
Joined: Wed Oct 30, 2013 8:59 pm

### Re: Boids

then the next step is to make an anthill background
Or flying birds!
LÖVE Projects: GOOi, Süsse, Dyzön and Katsudö
Thanks for taking the time and read this

### Who is online

Users browsing this forum: Exabot [Bot] and 5 guests