xxxxxxxxxx
49
function setup() {
createCanvas(400, 400);
w = new walker();
w.x = 0;
w.y = 0;
background(220);
}
function draw() {
w.step;
w.display;
}
walker = function() {
/*
var setup = function(x,y) {
this.x = x;
this.y = y;
}
*/
var step = function() {
var choice = randInt(0,3);
if (choice == 0) {
this.x++;
}
else if (choice == 1) {
this.x--;
}
else if (choice == 2) {
this.y++;
}
else {
this.y--;
}
print('choice=' + choice);
}
var display = function() {
ellipse(this.x,this.y,2,2);
}
}
//note it didn't ever equal max, so we add +1 later on
function randInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max + 1);
return Math.floor(Math.random() * (max - min)) + min;
}