Skip to content

Instantly share code, notes, and snippets.

@sabha
Created February 11, 2018 17:33
Show Gist options
  • Save sabha/b581cad76bea182dfde361a9f23b13ee to your computer and use it in GitHub Desktop.
Save sabha/b581cad76bea182dfde361a9f23b13ee to your computer and use it in GitHub Desktop.
Jitter
<!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