-
Notifications
You must be signed in to change notification settings - Fork 0
/
rect.html
97 lines (91 loc) · 2.55 KB
/
rect.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script type="application/javascript"></script>
</head>
<script src="../dist/leon.js"></script>
<script>
function draw() {
document.querySelector("body").addEventListener("click", () => {
draw();
});
const canvas = document.querySelector("#canvas");
const context = canvas.getContext("2d");
const commands = [
() => context.beginPath(),
() => context.moveTo(50, 50),
(w) => {
context.lineTo(50, 50 + w);
},
(w) => {
context.lineTo(50 + w, 100);
},
(w) => {
context.lineTo(100, 100 + w);
},
(w) => {
context.lineTo(100 + w, 50);
},
];
context.clearRect(0, 0, 300, 300);
let curr = 0;
function runCommand(curr) {
if (curr >= commands.length) return;
const command = commands[curr];
if (curr == 0 || curr == 1 || curr == 6) {
command();
runCommand(curr + 1);
} else {
function call(i) {
if (curr == 4 || curr == 5) {
if (i < -50) {
runCommand(curr + 1);
return;
}
setTimeout(() => {
command(i);
context.stroke();
call(i - 1);
}, 1);
} else {
if (i > 50) {
runCommand(curr + 1);
return;
}
setTimeout(() => {
command(i);
context.stroke();
call(i + 1);
}, 1);
}
}
call(0);
}
}
runCommand(0);
}
window._draw = draw;
</script>
<script>
// quadraticCurveTo(cp1x, cp1y, x, y)
// 현재 위치 에서 x,y 까지 cp1x, cp1y기준으로 그린다.
// function draw() {
// const canvas = document.querySelector("#canvas");
// const context = canvas.getContext("2d");
// context.beginPath();
// context.moveTo(75, 25);
// context.quadraticCurveTo(25, 25, 25, 62.5);
// context.quadraticCurveTo(25, 100, 50, 100);
// context.quadraticCurveTo(50, 120, 30, 125);
// context.quadraticCurveTo(60, 120, 65, 100);
// context.quadraticCurveTo(125, 100, 125, 62.5);
// context.quadraticCurveTo(125, 25, 75, 25);
// context.stroke();
// }
</script>
<script></script>
<body onload="draw();">
<canvas id="canvas" width="300" height="300"></canvas>
</body>
</html>