Lonely Lion

Chris McAvoy likes kites

Archive for the ‘BeeSim’ Category

Pyglet Great, Math Hard

with 2 comments

I’ve blogged about my random obsession with bees in the past. The release of Pyglet encouraged me to pick it up again and try to make a bee-system associated with coordinates rather than with abstract “locations.”

Over the weekend, I started to write a trig library that could compute angles and distances, so I could move my bees around a grid. It turns out, I’m pretty bad at math. Brant Harris sat down and explained Vectors to me in about 15 minutes. I immediately ditched my trig library, and built a basic Vector bee demo in a half hour or so last night. The code for it is in my expansive public-works repository. In that same module is trig.py, which is the start of the trig library I ended up ditching. The Vector work was already written in PyEuclid, the very excellent Euclidian Geometry library written especially for Pygame development.

The code, suitable for cutting and pasting, is as follows:

[source:python]
#!/usr/bin/env python
# notes on how to use vectors to move the bees around in pyglet
from euclid import Vector2 as v
from pyglet import window
from pyglet import font
from random import randint

b = v(1,1) # bee at 1,1
h = v(150,150) # hive at 4,4

def in_range(b, h):
# return true if magnitude (distance) is less than 1
return (b – h).magnitude() < 1

# move the bee one tick towards the hive
def move_towards_hive(b,h):
return b + ( h – b ).normalized()

def move_random(b):
return b + (v(randint(0,100), randint(0,100)) – b).normalized() * 5

win = window.Window()
ft = font.load(‘Arial’, 18)

while not win.has_exit:
win.dispatch_events()
while not in_range(b,h):
b = move_random(b)
print “b: %s h: %s” % (b, h)
win.clear()
b_text = font.Text(ft, ‘b’, x=b.x, y=b.y).draw()
h_text = font.Text(ft, ‘h’, x=h.x, y=h.y).draw()
win.flip()
[/source]

Written by Chris

November 14th, 2007 at 3:00 pm

Posted in BeeSim,Blog,Python

Ants Beat Bees!

without comments

I just saw this ant simulator on reddit, very cool looking. It’s almost exactly what I was shooting for when I started messing around with my various bee simulators. I never buckled down and finished any of them. The bees have lost to the ants. Sorry bees.

Written by Chris

March 16th, 2007 at 8:44 am

Posted in BeeSim,Blog

Today is my Birthday

with 3 comments

I’m 30!

So, expect a lot more mature blogging now, instead of all this hot open source stuff I’ve been tossing out at you. Now that I’m an old man, I’m pretty sure I’ll be writing Java or C#, kicking back with my enterprise friends, chatting about the power of waterfall.

So long 20′s, I barely knew you.

Written by Chris

August 17th, 2006 at 7:51 am

Ruby Bees

with one comment

I finished the Ruby implementation of my world famous Bee Simulator. It’s especially fun as it’s the first functional implementation. I’ve made starts in Perl, Python, and Rails, but gave up on each in turn. Feel free to read into that as you see fit.

I’m really happy with how the ultimate “Bee API” turned out. Here’s the Bee logic method in all its glory:

def tick
if @nectar > 0 and is_hive?
log("dumping nectar in hive")
deposit
return
elsif @nectar > 0
go(where_hive?)
return
end

if ! is_flower?
direction = Cardinal[rand(Cardinal.length)]
move.send(direction)
return
end
f = get_flower
log("found flower")
suck_nectar if f.has_nectar?
log("sucked nectar")
end

Kind of a neat API, in my humble opinion. It needs tweaked, but it’s good for now. I’d also like to give the Bee’s their own DSL, so that I can easily make this into a web app that lets users test their own theories of bee logic. If you want to take a look at the code, it’s available via subversion here: http://lonelylion.com/mcavoy_public/trunk/bee_ruby/

Written by Chris

July 7th, 2006 at 9:18 am

Posted in BeeSim,Projects,Ruby

So Many Bees

without comments

I set up a Trac page for the handful of projects I’ve released out to the world. The one I’ve been messing with most recently is a Rails implementation of my favorite “make a bunch of bees fly around and gather nectar” project that I’ve part-way implemented in Perl and Python.

The overall projects page is at http://projects.lonelylion.com

One of the somewhat clever things I’m trying to do with this latest Rails’d version of Bees, is to use the Firefox / Safari canvas object.

I can’t believe how much basic geometry I’m forgotten. How do I find the distance between two points? How do I find the angle between two points? Given an angle and a distance, what’s the second point?

Yikes. I’ve been scouring the internet looking for a free resource to catch me up, but I can’t find any. If anyone has any advice, I’m all ears. Otherwise, I’m going to hit the used bookstore to see if they have any 8th grade geometry books.

Written by Chris

February 20th, 2006 at 9:02 pm

Posted in BeeSim,Ruby

Threaded Bees

without comments

ASPN : Python Cookbook : Easy to use object-oriented thread pool framework

I saw this recipe this morning in the Python Cookbook, and wanted to mark it down for later digestion. Distributed computing, in it’s many forms, is something that I’m not terribly comfortable with a relatively new professional programmer. I mostly just rely on server “containers” to handle any sort of asynchronise-ness that may come up.

However, the whole idea of big multi-threaded / forked stuff is appealing. The BeeSim project that started as a Perl OOP exploration project, and is now getting ported to Python for further development is a good candidate for some threads. It would be neat to have each bee be a thread. I haven’t checked any of the Python code into the public Subversion repository as it’s mostly just stubs anyways. Hopefully I’ll flesh it out in the next couple of weeks. As fun as the Bee project is, it’s really on the waaaaaay back burner.

One of the reasons I’m moving it to Python (apart from the fact that Python is awesome) is to build out some sort of Myghty based web-front end. For now, the immediate goal is to port, class for class, method for method, the whole Bee backend from Perl to Python.

I’ve also had this book on my virtual safari bookshelf for a while: SCTHUMBZZZ.jpg” alt=”AI for Game Developers” />. The world that I’m creating for the Bees, and the Bees themselves, are great candidates for some AI exploration. All in all, I’m enjoying the project as a sort of “thing to do on the train.”

Written by Chris

July 20th, 2005 at 8:47 pm

Posted in BeeSim,Projects,Python

Wired News: Decoding Bees' Wild Waggle Dances

without comments

Wired News: Decoding Bees’ Wild Waggle Dances

Very cool…I might look into getting a copy of that Nature. My Bee project is buzzing along nicely. This morning on the train, I got the Bees to find flowers and bring nectar back to the hive. I’ll try and do a check in soon.

I think I’m going to build a Cocoa interface to the library, just to sort of monitor stuff. I still haven’t decided what I ultimately want to do with the library, most likely it will just be a fun OO Perl exercise, but there’s some potential for more fun with it. It is super slow right now. The map is one big array of location objects. All map “math” is done by traversing that array, which is sort of ridiculous, given each location has it’s own x,y coordinate. I did the array thing because it was easiest to get started with. If I can optimize that a bit, I’ll be in much better shape. I’ve read a teeny tiny bit about representing chess boards in memory, I’m not sure if this is a situation that that sort of idea could be applied to.

I’m really not sure what the industry standard way to represent “space” in memory is. Fun fun.

Written by Chris

May 13th, 2005 at 4:20 pm

Posted in BeeSim,Perl,Projects

Backpack: Bee Sim Project

without comments

My first public Backpack page: Backpack: Bee Sim Project.

Not much up there, but it’s a start. I’ve been tinkering with the package here and there over the past couple of train rides. I can create a world, and am working on the stuff to populate it. I’m going to put my design cards into some sort of UML and pop a picture up on the Backpack page. For now, it’s all on index cards.

Also, I’ve been working on it on my laptop, and haven’t added it to my public Subversion repository just yet. I will. Get ready.

Written by Chris

May 4th, 2005 at 11:21 pm

Posted in BeeSim,Perl,Projects

Switch to our mobile site