-
Notifications
You must be signed in to change notification settings - Fork 1
/
chasing_square.html
54 lines (49 loc) · 1.45 KB
/
chasing_square.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Canvas Pattern</title>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #fff;
}
canvas {
border: 1px solid black;
}
</style>
</head>
<body>
<canvas id="patternCanvas" width="500" height="500"></canvas>
<script>
const canvas = document.getElementById('patternCanvas');
const ctx = canvas.getContext('2d');
function drawPattern() {
const radius = 100;
const spacing = 10;
const rows = 5;
const cols = 5;
for (let row = 0; row < rows; row++) {
for (let col = 0; col < cols; col++) {
const x = col * 2 * radius * 0.5 + radius;
const y = row * 2 * radius * 0.5 + radius;
drawArcSet(x, y, radius, spacing);
}
}
}
function drawArcSet(x, y, radius, spacing) {
for (let i = 0; i < radius / spacing; i++) {
ctx.beginPath();
ctx.arc(x, y, radius - i * spacing, 0, Math.PI, false);
ctx.stroke();
}
}
drawPattern();
</script>
</body>
</html>