-
Notifications
You must be signed in to change notification settings - Fork 0
/
canvas.html.html
60 lines (58 loc) · 1.32 KB
/
canvas.html.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
<!DOCTYPE html>
<html>
<head><title>animation</title>
</head>
<body>
<canvas></canvas>
<script>
var canvas=document.querySelector("canvas");
var c=canvas.getContext("2d");
canvas.width=window.innerWidth;
canvas.height=window.innerHeight;
var circle =new Circle();
var color=360*Math.random();
function Circle(x,y,x1,y1,radius){
this.x=x;
this.y=y;
this.x1=x1;
this.y1=y1;
this.radius=radius;
this.draw=function(){
c.beginPath();
c.arc(this.x,this.y,this.radius ,0,Math.PI*2,false);
c.fill();
}
this.update=function(){
if(this.x+this.radius>innerWidth||this.x-this.radius<0){
this.x1=-this.x1;
}
if(this.y+this.radius>innerHeight||this.y-this.radius<0){
this.y1=-this.y1;
}
this.x+=this.x1;
this.y+=this.y1;
this.draw();
}
}
var circleArray=[];
for(var i=0;i<500;i++){
var x=Math.random()*(innerWidth-radius*2)+radius;
var y=Math.random()*(innerHeight-radius*2)+radius;;
var x1=(Math.random()-0.5);
var y1=(Math.random()-0.5);
var radius =0.1;
circleArray.push(new Circle(x,y,x1,y1,radius));
}
function animate()
{
requestAnimationFrame(animate);
for(var i=0;i<circleArray.length;i++){
circleArray[i].update();
}
circle.update();
c.fillStyle ="hsl("+color++ +",200%,50%)";
}
animate();
</script>
</body>
</html>