Skip to content

Instantly share code, notes, and snippets.

Created September 15, 2015 14:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/a95bad3aaf6b7f344460 to your computer and use it in GitHub Desktop.
Save anonymous/a95bad3aaf6b7f344460 to your computer and use it in GitHub Desktop.
An ant script saved from https://github.com/jywarren/antfarm
// set basic attributes here;
// "this" means this ant you're editing now
this.speed = 1;
this.color = 'red';
this.height = 40;
this.width = 40;
// runs every frame:
onRun = function () {
this.direction += Math.random()*10-5; // vary direction slightly, randomly, in degrees
field.trail(this.x,this.y,'blue',100); // leave a trail at x, y, color, amount
// every 30 frames:
if (field.time % 30 == 0) {
// make a new ant
var ant = field.populate(AntFarm.Ant, 1)[0];
ant.x = this.x;
ant.y = this.y;
ant.color = "blue";
ant.speed = 3;
ant.onRun = function () {
if (this.age < 300) {
this.direction += Math.random()*10-5;
field.trail(this.x, this.y, 'blue', 50); // x, y, rgb, amount
} else {
this.speed = 0;
this.color = "grey";
}
}
}
}
onBump = function () {
// change direction by 90 degrees:
this.direction += 90;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment