|
1 | 1 | (function(){ |
2 | 2 | 'use strict'; |
3 | 3 |
|
| 4 | + var PIXEL_RATIO = window.devicePixelRatio || 1; |
| 5 | + var canvasPlaceholder = document.querySelector('.canvas-placeholder'); |
4 | 6 | var canvas = document.querySelector('.canvas'); |
5 | 7 | var script = document.querySelector('.script'); |
6 | 8 | var ctx = canvas.getContext('2d'); |
|
9 | 11 | var WIDTH, HEIGHT, position, direction, visible, pen, color; |
10 | 12 |
|
11 | 13 | function onResize(evt){ |
12 | | - canvas.setAttribute('width', canvas.scrollWidth); |
13 | | - canvas.setAttribute('height', canvas.scrollHeight); |
14 | | - WIDTH = canvas.scrollWidth; |
15 | | - HEIGHT = canvas.scrollHeight; |
| 14 | + WIDTH = canvasPlaceholder.getBoundingClientRect().width * PIXEL_RATIO; |
| 15 | + HEIGHT = canvasPlaceholder.getBoundingClientRect().height * PIXEL_RATIO; |
| 16 | + canvas.setAttribute('width', WIDTH); |
| 17 | + canvas.setAttribute('height', HEIGHT); |
| 18 | + canvas.style.top = canvasPlaceholder.getBoundingClientRect().top + "px"; |
| 19 | + canvas.style.left = canvasPlaceholder.getBoundingClientRect().left + "px"; |
| 20 | + canvas.style.width = (WIDTH / PIXEL_RATIO) + "px" |
| 21 | + canvas.style.height = (HEIGHT / PIXEL_RATIO) + "px" |
16 | 22 | if (evt){ |
17 | 23 | Menu.runSoon(); |
18 | 24 | } |
|
46 | 52 | function _moveForward(distance){ |
47 | 53 | var start = position; |
48 | 54 | position = { |
49 | | - x: cos(direction) * distance + start.x, |
50 | | - y: -sin(direction) * distance + start.y |
| 55 | + x: cos(direction) * distance * PIXEL_RATIO + start.x, |
| 56 | + y: -sin(direction) * distance * PIXEL_RATIO + start.y |
51 | 57 | }; |
52 | 58 | if (pen){ |
53 | 59 | ctx.lineStyle = color; |
|
0 commit comments