-
Notifications
You must be signed in to change notification settings - Fork 1
/
rotate.js
50 lines (36 loc) · 1.31 KB
/
rotate.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
function spiral() {
var c = document.getElementById('c');
var context = c.getContext("2d");
var centerx = context.canvas.width/2;
var centery = context.canvas.height/2;
context.clearRect(0, 0, 400, 400);
var gradient = context.createRadialGradient(centerx,centery,10,centerx,centery,150);
gradient.addColorStop(0,'#FF0000'); //red
gradient.addColorStop(0.4,'#600'); //brown
gradient.addColorStop(0.7,'#FF9900'); //yellow
gradient.addColorStop(1,'#000'); //black
context.fillStyle=gradient;
context.moveTo(centerx, centery);
context.beginPath();
var total = 600; //total count of seeds/dots, constant
var c = 2; //size constant
var c2 = c*3; //spacing constant
var increase = Math.PI * 2 / total;
var angle = 0; //changable angle for rotation animation
function rotate() {
context.clearRect(0, 0, 400, 400);
context.beginPath();
for( var i = 0; i < total; i++ ) {
r = Math.sqrt(i);
t = 137.5*Math.PI/180*i;
angle+=increase;
x = centerx + r * c2 * Math.cos(t) * Math.cos( angle );
y = centery + r * c2 * Math.sin(t) * Math.cos( angle );
context.arc(x, y,c,0,2*Math.PI,false);
}
context.fill();
angle -= 0.06;
}
var interval = window.setInterval(rotate, 30); //Looping through the function for the animation
}
window.onload = spiral;