-
Notifications
You must be signed in to change notification settings - Fork 49
/
23-undefined.js
145 lines (106 loc) · 3.21 KB
/
23-undefined.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// --------------------------
var width, height, prevTime;
var canvas = document.getElementById('c');
var ctx = canvas.getContext('2d');
width = window.innerWidth;
height = window.innerHeight;
canvas.width = width;
canvas.height = height;
// ================
var Shape = function( ctx, x, y){
this.ctx = ctx;
this.x = x;
this.y = y;
this.circlrRawArr = [];
var minRad = 30;
var maxRad = Math.min(width, height) / 2 * .9;
for(var i = 0; i < this.circlrRawNum; i++){
var theta = 2 * Math.PI * i / this.circlrRawNum;
var circleRaw = new CircleRaw( ctx, minRad, maxRad, theta);
this.circlrRawArr.push(circleRaw);
}
};
Shape.prototype = {
circlrRawArr : null,
circlrRawNum : 60,
update : function(){
this.ctx.save();
this.ctx.translate(this.x, this.y);
for(var i = 0; i < this.circlrRawNum; i++){
var circleRaw = this.circlrRawArr[i];
circleRaw.update();
}
this.ctx.restore();
}
};
var CircleRaw = function( ctx, minRad, maxRad, theta){
var difRad;
this.ctx = ctx;
this.rad = {min : minRad, max: maxRad};
difRad = (maxRad - minRad);
this.theta = theta;
this.circleArr = [];
for(var i = 0; i < this.rawNum; i++){
var rate = i / this.rawNum;
var curRad = difRad * rate + minRad;
var circle = new Circle( this.ctx, this.theta, curRad, maxRad);
this.circleArr.push(circle);
}
this.count = theta;
}
CircleRaw.prototype = {
rate : 0,
rawNum : 20,
count : 0,
update : function(){
this.count += 0.04;
for( var i = 0; i < this.rawNum; i++){
var circle = this.circleArr[i];
circle.update(this.count);
}
}
}
var Circle = function( ctx, theta, minRad, maxRad ){
this.ctx = ctx;
this.theta = theta;
this.curRad = minRad;
this.minRad = minRad;
this.maxRad = maxRad;
this.difRad = (this.maxRad - this.minRad);
};
Circle.prototype = {
col : '#fff',
rad : 2,
update : function(count){
var rate = ( 1 + Math.sin(count))/2 * .8;
// var otherRate = (1 + Math.cos(count * 2))/2;
// var otherRate2 = (1 + Math.sin(count * 4))/2;
var rad = this.difRad * rate + this.minRad;
var xPos = rad * Math.cos(this.theta);
var yPos = rad * Math.sin(this.theta);
var col = parseInt(100 + 155 * rate);
this.ctx.beginPath();
this.ctx.fillStyle = 'rgb( ' + col + ', ' + col + ', ' + col + ')';
this.ctx.arc( xPos, yPos, this.rad, 0, 2 * Math.PI, false);
this.ctx.fill();
this.ctx.closePath();
}
};
// ================
var shape;
init();
loop();
function init(){
shape = new Shape( ctx, width/2, height/2);
prevTime = +new Date;
}
function loop(){
var curTime = +new Date;
var duration = (curTime - prevTime)/1000;
prevTime = curTime;
ctx.fillStyle = '#333';
ctx.fillRect(0, 0, width, height);
shape.update();
requestAnimationFrame(loop);
}
window.requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;