-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathteste.html
More file actions
43 lines (30 loc) · 1.04 KB
/
teste.html
File metadata and controls
43 lines (30 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<canvas width="600" height="400"></canvas>
<script>
var tela = document.querySelector('canvas');
var pincel = tela.getContext('2d');
pincel.fillStyle = 'grey';
pincel.fillRect(0, 0, 600, 400);
var desenha = false;
function desenhaCirculo(evento) {
if(desenha) {
var x = evento.pageX - tela.offsetLeft;
var y = evento.pageY - tela.offsetTop;
pincel.fillStyle = 'blue';
pincel.beginPath();
pincel.arc(x, y, 10, 0, 2 * 3.14);
pincel.fill();
}
console.log(x + ',' + y);
}
tela.onmousemove = desenhaCirculo;
// função não tem mais nome, se não tem nome é anônima
function() {
desenha = true;
}
// função não tem mais nome, se não tem nome é anônima
function() {
desenha = false;
}
tela.onmousedown = habilitaDesenhar; // habilitaDesenhar é um nome que não existe mais
tela.onmouseup = desabilitaDesenhar; // desabilitaDesenhar é um nome que não existe mais
</script>