-
Notifications
You must be signed in to change notification settings - Fork 0
/
programa3.html
112 lines (89 loc) · 3.21 KB
/
programa3.html
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta content="dark" name="color-scheme">
<title>Programa 3</title>
<link rel="stylesheet" href="./css/reset.css">
</head>
<body>
<canvas width="600" height="400"></canvas>
<p><span>Selecione a cor: </span><input type="color" name="paleta" id="paleta"></p>
<script>
function numeroAleatorio(limiteNumeroAleatorio) {
return Math.round(Math.random() * limiteNumeroAleatorio);
}
function corAleatoria() {
var listaCor = ['blue', 'green', 'red', 'yellow', 'orange', 'black', 'white', 'pink']
return listaCor[numeroAleatorio(listaCor.length)]
}
function backgroundCanvas(cor) {
pincel.fillStyle = cor;
pincel.fillRect(0, 0, 600, 400);
}
function desenhaBolinha(posicaoX, posicaoY, raio) {
pincel.fillStyle = paleta.value //cores[indiceCorAtual]; //'blue'; //corAleatoria();
pincel.beginPath();
pincel.arc(posicaoX, posicaoY, raio, 0, 2 * Math.PI);
pincel.fill();
}
var paleta = document.querySelector("input");
var tela = document.querySelector('canvas');
var pincel = tela.getContext('2d');
backgroundCanvas('grey');
var cores = ['blue', 'red', 'green'];
var indiceCorAtual = 0;
function mudaCor() {
indiceCorAtual++;
if (indiceCorAtual >= cores.length) {
indiceCorAtual = 0; // volta para a primeira cor, azul
}
return false;
}
tela.oncontextmenu = mudaCor;
var raio = 10;
var desenha = false;
// function desenhaCirculo(evento) {
// if (desenha) {
// var x = evento.pageX - tela.offsetLeft;
// var y = evento.pageY - tela.offsetTop;
// //var raio = 10;
// if (evento.shiftKey && raio < 40) {
// //desenhaBolinha(x, y, raio + 20);
// raio += 10;
// }
// if (evento.ctrlKey && raio > 10) {
// raio -= 5;
// }
// desenhaBolinha(x, y, raio);
// }
// console.log(x + ', ' + y);
// }
// tela.onclick = desenhaCirculo;
tela.onmousemove = (evento) => {
if (desenha) {
var x = evento.pageX - tela.offsetLeft;
var y = evento.pageY - tela.offsetTop;
//var raio = 10;
if (evento.shiftKey && raio < 40) {
//desenhaBolinha(x, y, raio + 20);
raio += 10;
}
if (evento.ctrlKey && raio > 10) {
raio -= 5;
}
desenhaBolinha(x, y, raio);
}
//console.log(x + ', ' + y);
}
tela.onmousedown = () => {
desenha = true;
}
tela.onmouseup = () => {
desenha = false;
}
</script>
</body>
</html>