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 » Mon Jan 18, 2016 4:08 pm

Just a visual toy. Made for fun.
Attachments
boids.love
(1.51 KiB) Downloaded 352 times

User avatar
alberto_lara
Party member
Posts: 331
Joined: Wed Oct 30, 2013 8:59 pm

Re: Boids

Post by alberto_lara » Mon Jan 18, 2016 5:10 pm

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

User avatar
ivan
Party member
Posts: 1548
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Boids

Post by ivan » Mon Jan 18, 2016 5:11 pm

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: 720
Joined: Sat Apr 26, 2014 7:46 pm

Re: Boids

Post by bobbyjones » Mon Jan 18, 2016 5:24 pm

I haven't looked at the code but it seems to get horrible performance on Android. Do you use spritebatches to render the triangles?
Do you frequently have great ideas but immediately lose them? Check out the MVP for my website called IdeaVault. It is designed to solve that problem. Desktop browsers only currently.

User avatar
alberto_lara
Party member
Posts: 331
Joined: Wed Oct 30, 2013 8:59 pm

Re: Boids

Post by alberto_lara » Mon Jan 18, 2016 5:41 pm

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 and Katsudö
Thank you for taking the time to read this

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

Re: Boids

Post by bobbyjones » Mon Jan 18, 2016 6:28 pm

Using a spritebatch would too. He just needs a triangle image.
Do you frequently have great ideas but immediately lose them? Check out the MVP for my website called IdeaVault. It is designed to solve that problem. Desktop browsers only currently.

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

Re: Boids

Post by rmcode » Tue Jan 19, 2016 12:40 am

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 » Sat Jan 23, 2016 8:07 pm

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: 292
Joined: Tue Jan 01, 2013 9:18 pm
Location: Cyberspace, Room 6502
Contact:

Re: Boids

Post by NightKawata » Thu Jan 28, 2016 10:14 pm

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: 331
Joined: Wed Oct 30, 2013 8:59 pm

Re: Boids

Post by alberto_lara » Tue Feb 02, 2016 8:54 pm

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

Post Reply

Who is online

Users browsing this forum: No registered users and 46 guests