javascript:labirintas
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| javascript:labirintas [2016/12/05 16:06] – aistis | javascript:labirintas [2016/12/06 00:10] (current) – aistis | ||
|---|---|---|---|
| Line 2: | Line 2: | ||
| <code html> | <code html> | ||
| - | <canvas id=" | + | <canvas id=" |
| Your browser does not support the HTML5 canvas tag.</ | Your browser does not support the HTML5 canvas tag.</ | ||
| </ | </ | ||
| Line 9: | Line 9: | ||
| var c = document.getElementById(" | var c = document.getElementById(" | ||
| var ctx = c.getContext(" | var ctx = c.getContext(" | ||
| - | // | ||
| - | // | ||
| - | // | ||
| - | var x = 50; | + | var x = 50, y = 50, step = 5; |
| - | var y = 50; | + | |
| - | var step = 5; | + | |
| var img = new Image; | var img = new Image; | ||
| - | img.src = " | + | img.src = " |
| - | ctx.drawImage(img, | + | media=javascript: |
| + | ctx.drawImage(img, | ||
| document.onkeydown = checkKey; | document.onkeydown = checkKey; | ||
| + | |||
| + | function refresh(){ | ||
| + | ctx.clearRect(0, | ||
| + | ctx.drawImage(img, | ||
| + | ctx.beginPath(); | ||
| + | ctx.arc(x, | ||
| + | ctx.stroke(); | ||
| + | } | ||
| function checkKey(e) { | function checkKey(e) { | ||
| - | | + | e = e || window.event; |
| - | | + | if (e.keyCode == ' |
| - | ctx.clearRect(0, | + | else if (e.keyCode == ' |
| - | ctx.drawImage(img, | + | else if (e.keyCode == ' |
| - | y = y - step; | + | else if (e.keyCode == ' |
| - | | + | |
| - | ctx.arc(x, | + | |
| - | ctx.stroke(); | + | |
| - | } | + | |
| - | | + | |
| - | ctx.clearRect(0, | + | |
| - | ctx.drawImage(img, | + | |
| - | y = y + step; | + | |
| - | | + | |
| - | ctx.arc(x, | + | |
| - | ctx.stroke(); | + | |
| - | } | + | |
| - | | + | |
| - | ctx.clearRect(0, | + | |
| - | ctx.drawImage(img, | + | |
| - | x = x - step; | + | |
| - | | + | |
| - | ctx.arc(x, | + | |
| - | ctx.stroke(); | + | |
| - | } | + | |
| - | | + | |
| - | ctx.clearRect(0, | + | |
| - | ctx.drawImage(img, | + | |
| - | x = x + step; | + | |
| - | ctx.beginPath(); | + | |
| - | ctx.arc(x, | + | |
| - | ctx.stroke(); | + | |
| - | } | + | |
| - | } | + | if (x < 0) x = 0; |
| + | if (y < 0) y = 0; | ||
| + | if (x > 600) x = 600; | ||
| + | if (y > 600) y = 600; | ||
| + | refresh(); | ||
| + | }</ | ||
| - | </ | + | |
| + | Labirintas: | ||
| + | |||
| + | {{: | ||
javascript/labirintas.1480946796.txt.gz · Last modified: by aistis
