diff options
| author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2018-09-19 01:53:20 +0200 |
|---|---|---|
| committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2018-09-19 01:53:20 +0200 |
| commit | a217ba8ae93591c5f1881425e9a3f2d6842e92de (patch) | |
| tree | bb29512626fc47ce492d14987099404766eae6f5 /tools | |
| parent | 6a38bb139ba43e261f54808f9f72f5e44b4fce92 (diff) | |
| download | mitjafelicijan.com-a217ba8ae93591c5f1881425e9a3f2d6842e92de.tar.gz | |
content update
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/draw/app.css | 58 | ||||
| -rw-r--r-- | tools/draw/app.js | 66 | ||||
| -rw-r--r-- | tools/draw/index.html | 38 |
3 files changed, 162 insertions, 0 deletions
diff --git a/tools/draw/app.css b/tools/draw/app.css new file mode 100644 index 0000000..40e4838 --- /dev/null +++ b/tools/draw/app.css | |||
| @@ -0,0 +1,58 @@ | |||
| 1 | @charset "utf-8"; | ||
| 2 | |||
| 3 | * { | ||
| 4 | box-sizing: border-box; | ||
| 5 | background-color: transparent; | ||
| 6 | margin: 0; | ||
| 7 | padding: 0; | ||
| 8 | border: 0; | ||
| 9 | list-style-type: none; | ||
| 10 | outline: none; | ||
| 11 | text-decoration: none; | ||
| 12 | position: relative; | ||
| 13 | box-shadow: none; | ||
| 14 | -moz-osx-font-smoothing: grayscale !important; | ||
| 15 | text-rendering: optimizeLegibility !important; | ||
| 16 | -webkit-font-smoothing: antialiased !important; | ||
| 17 | font-family: Arial, Helvetica, sans-serif; | ||
| 18 | } | ||
| 19 | |||
| 20 | body { | ||
| 21 | margin: 0; | ||
| 22 | padding: 0; | ||
| 23 | font-size: 13px; | ||
| 24 | } | ||
| 25 | |||
| 26 | section { | ||
| 27 | position: fixed; | ||
| 28 | left: 0; | ||
| 29 | top: 0; | ||
| 30 | right: 0; | ||
| 31 | bottom: 0; | ||
| 32 | background-image: linear-gradient(0deg, transparent 24%, rgba(0, 0, 0, .08) 25%, rgba(0, 0, 0, .08) 26%, transparent 27%, transparent 74%, rgba(0, 0, 0, .08) 75%, rgba(0, 0, 0, .08) 76%, transparent 77%, transparent), linear-gradient(90deg, transparent 24%, rgba(0, 0, 0, .08) 25%, rgba(0, 0, 0, .08) 26%, transparent 27%, transparent 74%, rgba(0, 0, 0, .08) 75%, rgba(0, 0, 0, .08) 76%, transparent 77%, transparent); | ||
| 33 | background-size: 50px 50px; | ||
| 34 | } | ||
| 35 | |||
| 36 | canvas { | ||
| 37 | width: 100%; | ||
| 38 | height: 100%; | ||
| 39 | } | ||
| 40 | |||
| 41 | nav { | ||
| 42 | position: fixed; | ||
| 43 | left: 10px; | ||
| 44 | top: 10px; | ||
| 45 | width: 100px; | ||
| 46 | } | ||
| 47 | |||
| 48 | nav button { | ||
| 49 | border: 2px dashed #bbb; | ||
| 50 | background: #fff; | ||
| 51 | border-radius: 5px; | ||
| 52 | display: block; | ||
| 53 | width: 100%; | ||
| 54 | margin-bottom: 10px; | ||
| 55 | padding: 10px 5px; | ||
| 56 | font-weight: bold; | ||
| 57 | cursor: pointer; | ||
| 58 | } | ||
diff --git a/tools/draw/app.js b/tools/draw/app.js new file mode 100644 index 0000000..d8b6ebf --- /dev/null +++ b/tools/draw/app.js | |||
| @@ -0,0 +1,66 @@ | |||
| 1 | let paintStyle = getComputedStyle(document.querySelector('section')); | ||
| 2 | let canvas = document.querySelector('canvas'); | ||
| 3 | let ctx = canvas.getContext('2d'); | ||
| 4 | |||
| 5 | canvas.width = parseInt(paintStyle.getPropertyValue('width')); | ||
| 6 | canvas.height = parseInt(paintStyle.getPropertyValue('height')); | ||
| 7 | |||
| 8 | var mouse = { | ||
| 9 | x: 0, | ||
| 10 | y: 0 | ||
| 11 | }; | ||
| 12 | |||
| 13 | ctx.lineWidth = 3; | ||
| 14 | ctx.lineJoin = 'round'; | ||
| 15 | ctx.lineCap = 'round'; | ||
| 16 | ctx.strokeStyle = 'limegreen'; | ||
| 17 | |||
| 18 | canvas.addEventListener('mousemove', function(e) { | ||
| 19 | mouse.x = e.pageX - this.offsetLeft; | ||
| 20 | mouse.y = e.pageY - this.offsetTop; | ||
| 21 | }, false); | ||
| 22 | |||
| 23 | canvas.addEventListener('mousedown', function(e) { | ||
| 24 | ctx.beginPath(); | ||
| 25 | ctx.moveTo(mouse.x, mouse.y); | ||
| 26 | canvas.addEventListener('mousemove', onPaint, false); | ||
| 27 | }, false); | ||
| 28 | |||
| 29 | canvas.addEventListener('mouseup', function() { | ||
| 30 | canvas.removeEventListener('mousemove', onPaint, false); | ||
| 31 | }, false); | ||
| 32 | |||
| 33 | var onPaint = function() { | ||
| 34 | ctx.lineCap = 'round'; | ||
| 35 | ctx.lineTo(mouse.x, mouse.y); | ||
| 36 | ctx.stroke(); | ||
| 37 | }; | ||
| 38 | |||
| 39 | |||
| 40 | document.querySelectorAll('nav button').forEach(function(button, idx) { | ||
| 41 | button.addEventListener('click', function(evt) { | ||
| 42 | console.log(button.dataset.method); | ||
| 43 | |||
| 44 | switch (button.dataset.method) { | ||
| 45 | case 'color': | ||
| 46 | { | ||
| 47 | ctx.strokeStyle = button.dataset.value; | ||
| 48 | break; | ||
| 49 | } | ||
| 50 | case 'size': | ||
| 51 | { | ||
| 52 | ctx.lineWidth = parseInt(button.dataset.value); | ||
| 53 | break; | ||
| 54 | } | ||
| 55 | case 'clear': | ||
| 56 | { | ||
| 57 | let clear = confirm('Do you really want to clear canvas?'); | ||
| 58 | if (clear) { | ||
| 59 | ctx.clearRect(0, 0, canvas.width, canvas.height); | ||
| 60 | } | ||
| 61 | break; | ||
| 62 | } | ||
| 63 | } | ||
| 64 | }); | ||
| 65 | |||
| 66 | }); | ||
diff --git a/tools/draw/index.html b/tools/draw/index.html new file mode 100644 index 0000000..12bead7 --- /dev/null +++ b/tools/draw/index.html | |||
| @@ -0,0 +1,38 @@ | |||
| 1 | <!DOCTYPE html> | ||
| 2 | <html lang="en"> | ||
| 3 | |||
| 4 | <head> | ||
| 5 | <meta charset="UTF-8"> | ||
| 6 | <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| 7 | <meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
| 8 | <title>Draw</title> | ||
| 9 | <link rel="stylesheet" href="app.css"> | ||
| 10 | </head> | ||
| 11 | |||
| 12 | <body> | ||
| 13 | |||
| 14 | <section> | ||
| 15 | <canvas></canvas> | ||
| 16 | </section> | ||
| 17 | |||
| 18 | <nav> | ||
| 19 | <button data-method="color" data-value="limegreen">limegreen</button> | ||
| 20 | <button data-method="color" data-value="crimson">crimson</button> | ||
| 21 | <button data-method="color" data-value="purple">purple</button> | ||
| 22 | <button data-method="color" data-value="fuchsia">fuchsia</button> | ||
| 23 | <button data-method="color" data-value="blueviolet">blueviolet</button> | ||
| 24 | <button data-method="color" data-value="goldenrod">goldenrod</button> | ||
| 25 | <button data-method="color" data-value="royalblue">royalblue</button> | ||
| 26 | <br> | ||
| 27 | <button data-method="size" data-value="2">small</button> | ||
| 28 | <button data-method="size" data-value="4">normal</button> | ||
| 29 | <button data-method="size" data-value="10">big</button> | ||
| 30 | <br> | ||
| 31 | <button data-method="clear" data-value="">clear</button> | ||
| 32 | </nav> | ||
| 33 | |||
| 34 | <script src="app.js" defer></script> | ||
| 35 | |||
| 36 | </body> | ||
| 37 | |||
| 38 | </html> | ||
