Walker Render point()
in
Programming Questions
•
2 years ago
What is wrong with this simple program?
It used to work 3 years ago.
Is there a problem with the point(x,y) function?
- // Daniel Shiffman
// The Nature of Code
// ITP, Spring 2006
// http://www.shiffman.net/ - Walker w;
- void setup() {
size(200,200);
background(0); - // Create a walker object
w = new Walker();
} - void draw() {
// Run the walker object
w.walk();
w.render();
} - class Walker {
int x,y; - Walker() {
x = width/2;
y = height/2;
} - void render() {
stroke(255,100);
point(x,y);
} - // Randomly move up, down, left, right, or stay in one place
void walk() {
int vx = int(random(5))-1;
int vy = int(random(5))-1;
x += vx;
y += vy;
x = constrain(x,0,width-1);
y = constrain(y,0,height-1);
}
}
1