-
Notifications
You must be signed in to change notification settings - Fork 0
/
canvas.html
153 lines (108 loc) · 3.61 KB
/
canvas.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<!DOCTYPE html>
<html>
<body onload="draw()">
<!--
<canvas id="myCanvas" width="200" height="100"
style="border:5px double #bb342b;">
</canvas> -->
<canvas id="element1" width="220" height="220" style="border:5px solid red ;"></canvas>
<canvas id="element2" width="220" height="220" style="border:5px solid red ;"></canvas>
<canvas id="element3" width="220" height="220" style="border:5px solid red ;"></canvas>
<canvas id="element4" width="220" height="220" style="border:5px solid red ;"></canvas>
<script>
function draw(){
let canvas1 = document.getElementById('element1')
if(canvas1.getContext){
const ctx = canvas1.getContext('2d')
// first square
ctx.fillStyle = 'rgb(0, 0, 0)';
ctx.fillRect(30, 30, 100, 100);
ctx.clearRect(30, 30, 100, 100);
ctx.strokeRect(30,30,110,110);
// second square
ctx.fillStyle = 'rgb(0, 0, 0)';
ctx.fillRect(70, 70, 100, 100);
ctx.clearRect(70, 70, 100, 100);
ctx.strokeRect(70,70,110,110);
// first line
ctx.moveTo(30,30);
ctx.lineTo(70,70);
ctx.stroke();
ctx.fill()
// second line
ctx.moveTo(30,140);
ctx.lineTo(70,180);
ctx.stroke();
ctx.fill();
// third line
ctx.moveTo(140,30);
ctx.lineTo(180,70);
ctx.stroke();
ctx.fill();
// fourth line
ctx.moveTo(140,70);
ctx.lineTo(140,140);
ctx.stroke();
ctx.fill();
// fifth line
ctx.moveTo(70,140);
ctx.lineTo(140,140)
ctx.stroke();
ctx.fill()
// sixth line
ctx.moveTo(140,140);
ctx.lineTo(180,180)
ctx.stroke();
ctx.fill()
}
}
let canvas2 = document.getElementById('element2')
if(canvas2.getContext){
const ctx = canvas2.getContext('2d');
ctx.beginPath();
ctx.arc(110, 110, 90,0, Math.PI*2);
ctx.shadowBlur = 2;
ctx.shadowColor = "red";
ctx.stroke()
// ctx.fill();
ctx.moveTo(80, 90);
ctx.arc(70,90,10,0,Math.PI*2);
ctx.fillStyle = "yellow";
ctx.fill()
ctx.moveTo(150,90)
ctx.arc(140,90,10,0,Math.PI*2);
ctx.moveTo(170,110)
ctx.arc(110,110,60,0,Math.PI);
ctx.stroke();
}
let canvas3 = document.getElementById('element3')
if(canvas3.getContext){
const ctx = canvas3.getContext('2d');
ctx.font = '30px arial'
ctx.strokeText("HELLO WORLD",0,110);
ctx.fillStyle = "red"
ctx.fill();
}
let canvas4 = document.getElementById('element4')
if(canvas4.getContext){
const ctx = canvas4.getContext('2d');
ctx.moveTo(30,30)
ctx.lineTo(160,30)
ctx.moveTo(160,30)
ctx.lineTo(30,160)
ctx.moveTo(30,160)
ctx.lineTo(30,30)
ctx.stroke()
ctx.fill()
ctx.moveTo(160,35)
ctx.lineTo(35,160)
ctx.moveTo(35,160)
ctx.lineTo(160,160)
ctx.moveTo(160,160)
ctx.lineTo(160,35)
ctx.stroke()
ctx.fill()
}
</script>
</body>
</html>