xxxxxxxxxx
44
var x, y;
var move = 2;
var s = 20;
function setup() {
createCanvas(400, 400);
rectMode(CENTER);
background(0);
noStroke();
fill(255);
x = width/2;
y = height/2;
}
function draw() {
background(0);
if (keyCode == UP_ARROW) {
y -= move;
} else if (keyCode == DOWN_ARROW) {
y += move;
} else if (keyCode == LEFT_ARROW) {
x -= move;
} else if (keyCode == RIGHT_ARROW) {
x += move;
}
if (x > width + s) x = -s;
if (x < -s) x = width + s;
if (y > height + s) y = -s;
if (y < -s) y = height + s;
rect(x, y, s, s);
}