blob: b44c7d655f2dce86840394a4685fad45c8700633 (
plain)
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
|
<!DOCTYPE html>
<html>
<head>
<title>canvas path example</title>
</head>
<body>
<canvas width=300 height=300></canvas>
<script>
function drawHouse() {
var ctx = document.querySelector("canvas").getContext("2d");
ctx.fillStyle = 'black';
ctx.fillRect(0, 0, 300, 300);
ctx.fillStyle = 'white';
ctx.strokeStyle = 'red';
// Set line width
ctx.lineWidth = 10;
// Wall
ctx.strokeRect(75, 140, 150, 110);
// Door
ctx.fillRect(130, 190, 40, 60);
// Roof
ctx.beginPath();
ctx.moveTo(50, 140);
ctx.lineTo(150, 60);
ctx.lineTo(250, 140);
ctx.closePath();
ctx.stroke();
}
drawHouse();
</script>
</body>
</html>
|