Skip to content

Instantly share code, notes, and snippets.

@jywarren
Forked from anonymous/ant.js
Last active September 15, 2015 15:42
Show Gist options
  • Save jywarren/ecb17224e568e332995c to your computer and use it in GitHub Desktop.
Save jywarren/ecb17224e568e332995c 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;
}
@jywarren
Copy link
Author

Dead queens become zombies! Problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment