Processing3 1.随机行走

时间:2022-01-07 17:18:56
class Walker {
int x;
int y;
Walker() {
x = width/2;
y = height/2;
}
void display() {
stroke(0);
point(x,y);
} void step() {
int choice = int(random(4)); //0,1,2,or 3
if(choice == 0) {
x++;
} else if(choice == 1) {
x--;
} else if(choice == 2) {
y++;
} else {
y--;
}
}
} Walker walker;
void setup() {
size(640,360);
walker = new Walker();
background(255);
}
void draw() {
walker.setup();
walker.display();
}