Created
October 23, 2013 18:57
-
-
Save mmcdaris/7124521 to your computer and use it in GitHub Desktop.
random grey walker in processing
This file contains 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
class Walker { | |
int x, y, range; | |
String tag; | |
Walker(int x1, int y1, int rng) { | |
x = x1; | |
y = y1; | |
range = rng; | |
// start at center | |
} | |
int rndclr () { | |
return int(random(255)); | |
} | |
void display() { | |
stroke(rndclr()); | |
strokeWeight(int(random(range))); | |
point(x, y); | |
} | |
void step() { | |
int choice = int(random(4)); // this picks from [0,4) | |
if ( choice == 0 ) { | |
x++; | |
} | |
else if ( choice == 1 ) { | |
x--; | |
} | |
else if ( choice == 2 ) { | |
y++; | |
} | |
else { | |
y--; | |
} | |
} | |
void jump () { | |
if (x > range || y > range) { | |
x = x - int(random(5)); | |
y = y - int(random(5)); | |
} | |
if (x < -range || y < -range) { | |
x = x + int(random(5)); | |
y = y + int(random(5)); | |
} | |
} | |
} | |
Walker w, x, y, z; | |
void setup () { | |
size(800, 800); | |
w = new Walker(400, 400, 30); | |
x = new Walker(200, 200, 240); | |
y = new Walker(600, 500, 360); | |
z = new Walker(300, 100, 50); | |
background(#FA6400); | |
} | |
void draw () { | |
w.step(); | |
//w.jump(); | |
w.display(); | |
x.step(); | |
//x.jump(); | |
x.display(); | |
y.step(); | |
//y.jump(); | |
y.display(); | |
z.step(); | |
//z.jump(); | |
z.display(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
make walkers draggable :)