-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2.01 - Desenho 2.html
54 lines (46 loc) · 1.49 KB
/
2.01 - Desenho 2.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
<canvas width="500" height="500"></canvas>
<script>
// Seletor de tela
var tela=document.querySelector('canvas');
var desenho=tela.getContext('2d');
var W=tela.width; H=tela.height;
// Ferramentas de desenho
{
function inicio() { desenho.beginPath() }
function ponto(x,y) { desenho.moveTo(x,y) }
function linha(x,y) { desenho.lineTo(x,y) }
function pintarRet(xr,yr, w,h) { desenho.fillRect(xr,yr, w,h) }
function contornoRet(xr,yr, w,h) { desenho.strokeRect(xr,yr, w,h) }
function circular (xc,yc,r, ti, tf) { desenho.arc(xc,yc,r, ti, tf) }
function arco (xc,yc,r, ti, tf,texto) { desenho.arc(xc,yc,r, ti, tf,texto) }
function pintar() { desenho.fill() }
function contorno() { desenho.stroke() }
function cor(x) { desenho.fillStyle=x }
function corLinha(x) { desenho.strokeStyle=x }
}
corLinha('black'); contornoRet(0,0,W,H)
function Quadrado(xr,yr,w,h,fundo,linha)
{
var tela = document.querySelector('canvas');
var desenho = tela.getContext('2d');
cor(fundo);
pintarRet(xr,yr,w,h);
corLinha(linha);
contornoRet(xr,yr,w,h);
}
var x, y;
var cor1 = 'green'; cor2 = 'yellow';
// Xadrez
for(y = 0; y <= H; y = y+100)
{
for(x = 0; x < W; x = x+100) {
Quadrado(x, y, 50, 50, cor1, 'black')
Quadrado(x+50, y+50, 50, 50, cor1, 'black')
}
for(x = 50; x <= W; x = x+100) {
Quadrado(x+50, y+50, 50, 50, cor2, 'black')
Quadrado(x, y, 50, 50, cor2, 'black')
Quadrado(0, y+50, 50, 50, cor2, 'black')
}
}
</script>