Last active
October 14, 2018 21:05
-
-
Save domenicrosati/2af46406b7a73585e641f76d180924e9 to your computer and use it in GitHub Desktop.
This file contains 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 canvas = document.getElementById("myCanvas"); | |
var ctx = canvas.getContext("2d"); | |
function drawRect(x, y) { | |
ctx.fillStyle = "green"; | |
ctx.fillRect(x, y, 50, 50); | |
} | |
// box co-ordinates | |
var x = 0; | |
var y = 0; | |
// destroy? | |
var destroy = false; | |
function draw() { | |
ctx.clearRect(0, 0, 500, 500); // clear canvas | |
drawRect(x, y); | |
if(destroy != true) { | |
if (x <= 450) { | |
x = x + 5; | |
} | |
} | |
if (destroy == true) { | |
x = x - 5; | |
} | |
if (x == 450) { | |
destroy = true; | |
} | |
if (x == 0) { | |
destroy = false; | |
} | |
window.requestAnimationFrame(draw); | |
} | |
window.requestAnimationFrame(draw); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment