Skip to content

Instantly share code, notes, and snippets.

Created May 7, 2012 03:30
Show Gist options
  • Save anonymous/2625738 to your computer and use it in GitHub Desktop.
Save anonymous/2625738 to your computer and use it in GitHub Desktop.
a guest on May 6th, 2012 - pastebin.com/tmEAaKsk
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
//$(document).ready(function(){
var context;
var dx= 4;
var dy=4;
var y=150;
var x=10;
var rightDown = false;
var leftDown = false;
function draw(){
context= myCanvas.getContext('2d');
context.clearRect(0,0,300,300);
context.beginPath();
context.fillStyle="#0000ff";
context.arc(x,y,20,0,Math.PI*2,true);
context.closePath();
context.fill();
if(leftDown == true/* x<0 || x>300*/){
// dx=-dx;
x+=y;
}
/* if(rightDown == true/*y<0 || y>300)*/
/*` dy=-dy;
x+=dx;
y+=dy;
*/ }
/*$(canvas).onKeydown(function (evt){
if(evt.keyCode == 39) rightDown = true;
else if(evt.keyCode == 37) leftDown = true;
})*/
$(context).keydown(function(event) {
if (event.keyCode == 39)
rightDown == true;
leftDown == true;
})/*
var rightDown = false;
var leftDown = false;*/
setInterval(draw,10);
</script>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div>
<canvas id="myCanvas" width="300" height="300"></canvas>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment