-
Notifications
You must be signed in to change notification settings - Fork 1
/
css_script.js
37 lines (29 loc) · 1.16 KB
/
css_script.js
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
document.getElementById('startButton').addEventListener('click', drawCircles);
function drawCircles() {
const radius = document.getElementById('radiusSlider').value;
const canvas = document.getElementById('circleCanvas');
const ctx = canvas.getContext('2d');
const smallerRadius = radius / 2;
canvas.width = radius * 2 + 20; // Add some margin
canvas.height = radius * 2 + 20;
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw outer circle
ctx.beginPath();
ctx.arc(canvas.width / 2, canvas.height / 2, radius, 0, Math.PI * 2);
ctx.stroke();
// Calculate positions for smaller circles
const innerCircleX = canvas.width / 2;
const innerCircleY = canvas.height / 2;
const positions = [
{ x: innerCircleX - smallerRadius, y: innerCircleY },
{ x: innerCircleX + smallerRadius, y: innerCircleY },
{ x: innerCircleX, y: innerCircleY - smallerRadius },
{ x: innerCircleX, y: innerCircleY + smallerRadius }
];
// Draw smaller circles
positions.forEach(pos => {
ctx.beginPath();
ctx.arc(pos.x, pos.y, smallerRadius, 0, Math.PI * 2);
ctx.stroke();
});
}