Boids

Showcase your libraries, tools and other projects that help your fellow love users.
prixt
Prole
Posts: 26
Joined: Sat Sep 12, 2015 5:53 am

Boids

Post by prixt »

Just a visual toy. Made for fun.
Attachments
boids.love
(1.51 KiB) Downloaded 474 times
User avatar
alberto_lara
Party member
Posts: 372
Joined: Wed Oct 30, 2013 8:59 pm

Re: Boids

Post by alberto_lara »

Nice, that's a swarm algorithm right?
User avatar
ivan
Party member
Posts: 1911
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Boids

Post 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.
bobbyjones
Party member
Posts: 730
Joined: Sat Apr 26, 2014 7:46 pm

Re: Boids

Post 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?
User avatar
alberto_lara
Party member
Posts: 372
Joined: Wed Oct 30, 2013 8:59 pm

Re: Boids

Post 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?
bobbyjones
Party member
Posts: 730
Joined: Sat Apr 26, 2014 7:46 pm

Re: Boids

Post by bobbyjones »

Using a spritebatch would too. He just needs a triangle image.
User avatar
rmcode
Party member
Posts: 454
Joined: Tue Jul 15, 2014 12:04 pm
Location: Germany
Contact:

Re: Boids

Post by rmcode »

Very cool! Would love to have this as a screensaver.
User avatar
qubodup
Inner party member
Posts: 775
Joined: Sat Jun 21, 2008 9:21 pm
Location: Berlin, Germany
Contact:

Re: Boids

Post by qubodup »

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)
User avatar
NightKawata
Party member
Posts: 294
Joined: Tue Jan 01, 2013 9:18 pm
Location: Cyberspace, Room 6502
Contact:

Re: Boids

Post 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
"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
User avatar
alberto_lara
Party member
Posts: 372
Joined: Wed Oct 30, 2013 8:59 pm

Re: Boids

Post by alberto_lara »

then the next step is to make an anthill background
Or flying birds!
Post Reply

Who is online

Users browsing this forum: No registered users and 33 guests