Created
February 11, 2018 17:33
-
-
Save sabha/b581cad76bea182dfde361a9f23b13ee to your computer and use it in GitHub Desktop.
Jitter
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
<!DOCTYPE html> | |
<html> | |
<body> | |
<canvas id="myCanvas" width="200" height="100" style="border:1px solid #d3d3d3;"> | |
Your browser does not support the HTML5 canvas tag.</canvas> | |
<script> | |
var c = document.getElementById("myCanvas"); | |
var ctx = c.getContext("2d"); | |
var x = 95; | |
var y = 50; | |
var f = false; | |
function gameLoop(){ | |
var rand = Math.random(); | |
f = !f; | |
x = (f) ? x+rand : x-rand; | |
y = (f) ? y+rand : y-rand; | |
ctx.clearRect(0,0,200,100); | |
ctx.rect(0,0,200,100); | |
ctx.fillStyle = "black"; | |
ctx.fill(); | |
ctx.beginPath(); | |
ctx.fillStyle = "red"; | |
ctx.arc(x,y,10,0,2*Math.PI); | |
ctx.fill(); | |
} | |
setInterval(gameLoop, 100); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment