diff options
| author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2019-02-17 21:53:36 +0100 |
|---|---|---|
| committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2019-02-17 21:53:36 +0100 |
| commit | 8e9ef5ba62b8bee028428384ad5666e245eb854c (patch) | |
| tree | b382c5b40f122b2a152da2226006abab34abe105 /tools/draw/app.js | |
| parent | ad974810d43e1d5f70bca269665c25230e6a3221 (diff) | |
| download | mitjafelicijan.com-8e9ef5ba62b8bee028428384ad5666e245eb854c.tar.gz | |
content update
Diffstat (limited to 'tools/draw/app.js')
| -rw-r--r-- | tools/draw/app.js | 72 |
1 files changed, 0 insertions, 72 deletions
diff --git a/tools/draw/app.js b/tools/draw/app.js deleted file mode 100644 index 4c73d75..0000000 --- a/tools/draw/app.js +++ /dev/null | |||
| @@ -1,72 +0,0 @@ | |||
| 1 | window.addEventListener('load', function(evt) { | ||
| 2 | |||
| 3 | let paintStyle = getComputedStyle(document.querySelector('section')); | ||
| 4 | let canvas = document.querySelector('canvas'); | ||
| 5 | let ctx = canvas.getContext('2d'); | ||
| 6 | |||
| 7 | canvas.width = parseInt(paintStyle.getPropertyValue('width')); | ||
| 8 | canvas.height = parseInt(paintStyle.getPropertyValue('height')); | ||
| 9 | |||
| 10 | var mouse = { | ||
| 11 | x: 0, | ||
| 12 | y: 0 | ||
| 13 | }; | ||
| 14 | |||
| 15 | ctx.lineWidth = 3; | ||
| 16 | ctx.lineJoin = 'round'; | ||
| 17 | ctx.lineCap = 'round'; | ||
| 18 | ctx.strokeStyle = 'limegreen'; | ||
| 19 | |||
| 20 | canvas.addEventListener('mousemove', function(e) { | ||
| 21 | mouse.x = e.pageX - this.offsetLeft; | ||
| 22 | mouse.y = e.pageY - this.offsetTop; | ||
| 23 | }, false); | ||
| 24 | |||
| 25 | canvas.addEventListener('mousedown', function(e) { | ||
| 26 | ctx.beginPath(); | ||
| 27 | ctx.moveTo(mouse.x, mouse.y); | ||
| 28 | canvas.addEventListener('mousemove', onPaint, false); | ||
| 29 | }, false); | ||
| 30 | |||
| 31 | canvas.addEventListener('mouseup', function() { | ||
| 32 | canvas.removeEventListener('mousemove', onPaint, false); | ||
| 33 | }, false); | ||
| 34 | |||
| 35 | var onPaint = function() { | ||
| 36 | ctx.lineCap = 'round'; | ||
| 37 | ctx.lineTo(mouse.x, mouse.y); | ||
| 38 | ctx.stroke(); | ||
| 39 | }; | ||
| 40 | |||
| 41 | |||
| 42 | document.querySelectorAll('nav button').forEach(function(button, idx) { | ||
| 43 | |||
| 44 | if (button.dataset.method == 'color') { | ||
| 45 | button.style.background = button.dataset.value; | ||
| 46 | } | ||
| 47 | |||
| 48 | button.addEventListener('click', function(evt) { | ||
| 49 | switch (button.dataset.method) { | ||
| 50 | case 'color': | ||
| 51 | { | ||
| 52 | ctx.strokeStyle = button.dataset.value; | ||
| 53 | break; | ||
| 54 | } | ||
| 55 | case 'size': | ||
| 56 | { | ||
| 57 | ctx.lineWidth = parseInt(button.dataset.value); | ||
| 58 | break; | ||
| 59 | } | ||
| 60 | } | ||
| 61 | }); | ||
| 62 | |||
| 63 | }); | ||
| 64 | |||
| 65 | document.addEventListener('keydown', function(evt) { | ||
| 66 | if (evt.keyCode == 8) { | ||
| 67 | ctx.clearRect(0, 0, canvas.width, canvas.height); | ||
| 68 | } | ||
| 69 | console.log(evt.keyCode); | ||
| 70 | }, false); | ||
| 71 | |||
| 72 | }); | ||
