forked from lingonsaft/hacktoberfest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandom_circles.html
52 lines (49 loc) · 1.17 KB
/
random_circles.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Circles</title>
<style>
html {
width: 100%;
height: inherit;
}
canvas {
display: block;
}
body {
margin: 0;
}
button {
position: absolute;
top: 10px;
left: 10px;
}
</style>
</head>
<body>
<button>Redraw</button>
<canvas></canvas>
<script>
const btn = document.querySelector('button');
const canvas = document.querySelector('canvas');
const ctx = canvas.getContext('2d');
let WIDTH = document.documentElement.clientWidth;
let HEIGHT = document.documentElement.clientHeight;
canvas.width = WIDTH;
canvas.height = HEIGHT;
function random(number) {
return Math.floor(Math.random()*number);
}
function draw() {
ctx.clearRect(0,0,WIDTH,HEIGHT);
for(let i = 0; i < 100; i++) {
ctx.beginPath();
ctx.fillStyle = 'rgba(255,200,30,0.5)';
ctx.arc(random(WIDTH), random(HEIGHT), random(50), 0, 2 * Math.PI);
ctx.fill();
}
}
btn.addEventListener('click',draw);
</script>
"circles.html" 55L, 1180C