@@ -11,10 +11,18 @@
1111
1212 if (Modernizr.canvas && Modernizr.canvastext) {
1313
14- var canvas = document.createElement('canvas');
14+ var canvas = document.createElement('canvas'),
15+ canvasWidth = $(window).width() - 38,
16+ canvasHeight = $(window).height(),
17+ startX = Math.ceil(canvasWidth / 2),
18+ startY = canvasHeight - 20,
19+ currentX = startX,
20+ currentY = startY;
21+
22+
1523 $(canvas).attr({
16- 'height': $(window).height(),
17- 'width': $(window).width()
24+ 'height': canvasHeight,
25+ 'width': canvasWidth
1826 });
1927
2028 $('#main').html(canvas);
@@ -22,7 +30,33 @@
2230 var ctx = canvas.getContext('2d');
2331 ctx.font = '38px oxy';
2432 ctx.fillStyle = '#444444';
25- ctx.fillText('TEST: hello world', 50, 58);
33+
34+ ctx.fillText('o', startX, startY);
35+
36+ $(document).keydown(function (ev) {
37+ switch(ev.which) {
38+ case 37:
39+ case 39:
40+ var keepMoving = 10;
41+ (function animate () {
42+ if (currentX <= 38 ||
43+ currentX >= (canvasWidth -38))
44+ return currentX = (currentX <= 38)? 40: canvasWidth -40;
45+
46+ ctx.fillStyle = '#ffffff';
47+ ctx.fillRect(38, 38, currentX, currentY);
48+
49+ currentX += (ev.which === 37)? -2: 2;
50+
51+ ctx.fillStyle = '#444444';
52+ ctx.fillText('o', currentX, currentY);
53+ if (--keepMoving)
54+ setTimeout(animate, 20);
55+ })();
56+ }
57+
58+ //log(ev.which);
59+ });
2660 }
2761
2862 else { // IE or old browser
@@ -39,6 +73,7 @@
3973 }
4074 });
4175
76+
4277 }) (window);