Skip to content

Instantly share code, notes, and snippets.

@jywarren
Last active October 1, 2015 18:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jywarren/130619c76cc6fd56bf1f to your computer and use it in GitHub Desktop.
Save jywarren/130619c76cc6fd56bf1f to your computer and use it in GitHub Desktop.
// set basic attributes here;
// "this" means this ant you're editing now
ant.speed = 1;
ant.color = 'red';
ant.height = 40;
ant.width = 40;
// runs every frame:
onRun = function () {
ant.direction += Math.random()*10-5; // vary direction slightly, randomly, in degrees
ant.trail('blue', 100); // leave a trail of <color>, <amount>
// every 30 frames:
if (field.time % 30 == 0) {
// make a new ant
var child = field.populate(AntFarm.Ant, 1)[0];
child.x = ant.x;
child.y = ant.y;
child.color = "blue";
child.speed = 3;
child.queen = ant;
}
}
onBump = function () {
// change direction by 90 degrees:
ant.direction += 90;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment