xxxxxxxxxx
63
/*********************************************************************************
NAME: Zenek Chapman
DATE: Oct 21
COURSE: Computer Science 30
PROGRAM DESCRIPTION: Square following the edges of the canvas
******************************************************************************/
var x = 0; // x location of square
var y = 0; // y location of square
var speed = 5; // speed of square
var state = 0; //state of sqaure
function setup() {
createCanvas(random(100,1000), random(100, 1000));
}
function draw() {
background(125,50,50)
// Display the square
stroke(0);
fill(230,255,204);
if (state == 0) { // once state is 0 start moving rect right
fill(255, 30, 40)
x += speed
rect(x, y, 20, 20)
if (x > width - 20){
state = 1
}
}
else if (state == 1) { // once state is 1 start moving rect down
fill(10, 200, 100)
y += speed
rect(x, y, 20, 20)
if (y > height - 20){
state = 2
}
}
else if (state == 2) { // once state is 2 start moving rect left
fill(100, 20, 225)
x -= speed
rect(x, y, 20, 20)
if (x < 1){
state = 3
}
}
else if (state == 3) { // once state is 3 start moving rect up
fill(100, 10, 150)
y -= speed
rect(x, y, 20, 20)
if (y < 1){
state = 0
}
}
}