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!

Friday 13 June 2014

Little bit o' Javascript

I don't know much about Javascript. Embarassing, I know. I never got into it, even though it looks like lots of fun, and it has lots of advantages due to running on just about everything including tablets.
Anyway, I bought a book because I like learning from books instead of web sites. Don't get me wrong, sites like Codecademy have some nice challenges and reference sites like W3Schools are very useful for... reference, but there's nothing like a well written book to take you through a language and show you the ropes.

So, I've just been playing, and there's what I did this evening:

http://www.pagetworld.co.uk/js/test_dots.html

It's dead simple, but I wanted to see how easy it was to track mouse movement on a canvas and to use some Object Oriented stuff, including an array of objects. I learnt a bit in the process, which is always fun. Next thing I want to do is try a bit of flocking behaviour with randomly generated "birds".

Keep tinkering!