Create a gist now

Instantly share code, notes, and snippets.

anonymous /ant.js
Created Sep 15, 2015

What would you like to do?
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