Created
September 15, 2015 14:48
-
-
Save anonymous/a95bad3aaf6b7f344460 to your computer and use it in GitHub Desktop.
An ant script saved from https://github.com/jywarren/antfarm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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