Created
February 5, 2014 16:37
-
-
Save cranic/8827720 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!doctype html> | |
| <html> | |
| <head> | |
| <title>Desenhar</title> | |
| <meta charset="utf-8" /> | |
| <style type="text/css"> | |
| #canvas { | |
| background-color: #fff; | |
| border: 5px solid black; | |
| } | |
| #linhas, #linha{ | |
| clear: both; | |
| } | |
| </style> | |
| <script type="text/javascript"> | |
| var mouseDown = false; | |
| document.addEventListener('mousedown', function(e) { | |
| mouseDown = true; | |
| if(e.srcElement.id === 'canvas') | |
| getPosition(e); | |
| }); | |
| document.addEventListener('mouseup', function() { | |
| mouseDown = false; | |
| }); | |
| document.addEventListener('DOMContentLoaded', function(){ | |
| var canvas = document.getElementById('canvas'); | |
| canvas.addEventListener('mousemove', getPosition, false); | |
| }); | |
| function getPosition(event){ | |
| if(!mouseDown) | |
| return; | |
| var x = new Number(); | |
| var y = new Number(); | |
| var canvas = document.getElementById('canvas'); | |
| if (event.x != undefined && event.y != undefined){ | |
| x = event.offsetX; | |
| y = event.offsetY; | |
| } | |
| x -= canvas.offsetLeft; | |
| y -= canvas.offsetTop; | |
| drawn(x, y); | |
| } | |
| function drawn(x, y){ | |
| var ctx = document.getElementById('canvas').getContext('2d'); | |
| ctx.lineWidth = 3; | |
| ctx.beginPath(); | |
| ctx.beginPath(); | |
| ctx.arc(x, y, document.getElementById('size').value, 0, 2 * Math.PI, false); | |
| ctx.fillStyle = document.getElementById('color').value; | |
| ctx.fill(); | |
| } | |
| function clear(){ | |
| var canvas = document.getElementById('canvas'); | |
| var ctx = canvas.getContext('2d'); | |
| ctx.clearRect( 0, 0, canvas.width, canvas.height) | |
| } | |
| </script> | |
| </head> | |
| <body> | |
| <canvas id="canvas" width="640" height="360"></canvas><br /><br /> | |
| <label>Tamanho da linha:</label> <input type="text" id="size" value="5"><br/> | |
| <label>Cor:</label> <input type="text" id="color" value="black"><br/> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment