({ key })
| 26 | let color = 0; |
| 27 | //write a draw function |
| 28 | function draw({ key }) { |
| 29 | console.log(key); |
| 30 | //begin path |
| 31 | ctx.beginPath(); |
| 32 | ctx.moveTo(w, h); |
| 33 | //move the value depending on what user did |
| 34 | switch (key) { |
| 35 | case "ArrowUp": |
| 36 | h = h - MOVE_AMOUNT; |
| 37 | break; |
| 38 | case "ArrowDown": |
| 39 | h = h + MOVE_AMOUNT; |
| 40 | break; |
| 41 | case "ArrowLeft": |
| 42 | w = w - MOVE_AMOUNT; |
| 43 | break; |
| 44 | case "ArrowRight": |
| 45 | w = w + MOVE_AMOUNT; |
| 46 | break; |
| 47 | } |
| 48 | |
| 49 | ctx.lineTo(w, h); |
| 50 | color = color + Math.random() * 10; |
| 51 | ctx.strokeStyle = `hsl(${color},100%,50%)`; |
| 52 | ctx.stroke(); |
| 53 | } |
| 54 | //handler for keys |
| 55 | function handleKeys(e) { |
| 56 | if (e.key.includes("Arrow")) { |