-
Notifications
You must be signed in to change notification settings - Fork 1
/
chasing_square1.html
58 lines (52 loc) · 1.52 KB
/
chasing_square1.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
<!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');
const width = canvas.width;
const height = canvas.height;
const radius = 100;
const lineWidth = 2;
ctx.lineWidth = lineWidth;
ctx.strokeStyle = '#000';
function drawPattern() {
const offsetX = radius;
const offsetY = radius;
const spacing = 10;
for (let i = 0; i <= width / radius; i++) {
for (let j = 0; j <= height / radius; j++) {
drawArcs(i * offsetX, j * offsetY, radius, spacing);
}
}
}
function drawArcs(x, y, radius, spacing) {
for (let r = radius; r > 0; r -= spacing) {
ctx.beginPath();
ctx.arc(x, y, r, 0, Math.PI * 2, false);
ctx.stroke();
}
}
drawPattern();
</script>
</body>
</html>