Friday 27 June 2014

Predator & Prey

Some more Javascript and HTML5 tinkering. This time I have been experimenting with adding some more behaviours to my little ball objects. I started off by making them move around the screen randomly, and added a little bit of mouse-cursor avoidance.

Then I started looking into how to make them exhibit flocking behaviour, like a group of birds or fish. I was greatly helped by this article on the three main rules of simple flocking.

I started with some attraction principles, which makes these dots gradually draw towards each other.

Then I looked at making them try to keep a distance from their neighbours, so they tend to jostle for position. This looked very nice. I also added a behaviour to make them avoid the mouse cursor.

This last example should also work on tablets, as I have learned how to grab touch events as well as mouse events.

The end result is something that looks quite hypnotic, which is especially satisfying as it is based on such simple rules!

No comments:

Post a Comment