/
circle.html
61 lines (56 loc) · 1.43 KB
/
circle.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script type="application/javascript"></script>
</head>
<script src="../dist/leon.js"></script>
<script>
let init = false;
function draw() {
if (!init) {
document.querySelector("body").addEventListener("click", () => {
draw();
});
init = true;
}
const canvas = document.querySelector("#canvas");
const context = canvas.getContext("2d");
context.clearRect(0, 0, 300, 300);
const commands = [
(radius) => {
console.log((Math.PI / 180) * radius))
context.beginPath();
context.arc(50, 50, 50, 0, (Math.PI / 180) * radius);
},
];
let curr = 0;
function runCommand(curr) {
console.log(curr);
if (curr >= commands.length) return;
const command = commands[curr];
if (curr == 1) {
command();
runCommand(curr + 1);
} else {
function call(i) {
requestAnimationFrame(() => {
if (i > 360) {
runCommand(curr + 1);
return;
}
command(i);
context.stroke();
call(i + 6);
});
}
call(0);
}
}
runCommand(0);
}
</script>
<body onload="draw();">
<canvas id="canvas" width="300" height="300"></canvas>
</body>
</html>