Created
February 1, 2016 16:39
-
-
Save claytical/d7653fe9c0dee9056f62 to your computer and use it in GitHub Desktop.
If, Else If, Else
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var x; | |
var y; | |
var xSpeed; | |
var ySpeed; | |
function setup() { | |
createCanvas(windowWidth, windowHeight); | |
x = width/2; | |
y = height/2; | |
xSpeed = 0; | |
ySpeed = 0; | |
} | |
function draw() { | |
noStroke(); | |
fill(255,0,0); | |
ellipse(x, y, 10, 10); | |
if (mouseX < width/2 && mouseY < height/2) { | |
xSpeed = -1; | |
ySpeed = -1; | |
} | |
else if(mouseX > width/2 && mouseY < height/2) { | |
xSpeed = 1; | |
ySpeed = -1; | |
} | |
else if(mouseX > width/2 && mouseY > height/2) { | |
xSpeed = 1; | |
ySpeed = 1; | |
} | |
else { | |
xSpeed = -1; | |
ySpeed = 1; | |
} | |
x = x + xSpeed; | |
y = y + ySpeed; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment