-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
138 lines (102 loc) · 3.38 KB
/
main.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
function yumetobiEffects() {
var cs = document.getElementById('main');
var ctx = cs.getContext('2d');
var w = cs.width;
var h = cs.height;
var circles = [];
var fillColors = ["#ffb391","#ff88d8","#f79998","#f0be52"];
var Circle = function(deg,fillColor){
this.initialize(deg,fillColor);
}
Circle.prototype = {
initialize: function(deg,fillColor){
this.x = 0;
this.y = 0;
//角度
this.deg = deg || 0;
//ラジアン
this.rad = 0;
//回転半径
this.radius = w/2;
this.size = w/10;
this.fillColor = fillColor;
},
updatePos: function(){
// 角度を増やす
this.deg += w/100;
//回転半径を減らす
this.radius -= 3;
//円のサイズを小さくする
this.size -= w/1000;
// 角度をラジアンに変換
this.rad = this.deg * Math.PI / 180;
// x座標 = 円の中心x座標 + 半径 * Cos
this.x = (w/2) + this.radius * Math.cos(this.rad);
// Y座標 = 円の中心y座標 + 半径 * Sin
this.y = (h/2) - this.radius * Math.sin(this.rad);
//console.log("x="+this.x+":y="+this.y);
//
},
drawing: function(){
if(this.size < 0){
delete this;
return false;
}
//描画を始める
ctx.beginPath();
ctx.arc(this.x,this.y,this.size,0,Math.PI*2,false);
ctx.fillStyle = this.fillColor;
ctx.globalAlpha = 0.7;
ctx.fill();
},
render: function(){
if(this.radius <= 0)return false;
this.updatePos();
this.drawing();
}
};
cs.addEventListener("click",function(event){
console.log("click!");
var initPos = Math.floor(Math.random() * 360) + 1;
var color = fillColors[Math.floor(Math.random()*fillColors.length)+1];
circle = new Circle(initPos,color);
circles.push(circle);
//console.log(circles);
},false);
(function render() {
ctx.clearRect(0, 0, w, h);
//if(circles.length <= 0)return false;
circles.forEach(function(circle){
circle.render();
});
//アニメーションする
requestAnimationFrame(render);
})();
}
function drawBackGround(){
var cs = document.getElementById('background');
var ctx = cs.getContext('2d');
var w = cs.width;
var h = cs.height;
ctx.beginPath();
/* グラデーション領域をセット */
var grad = ctx.createRadialGradient(w/2,h/2,50,w/2,h/2,w/2);
/* グラデーション終点のオフセットと色をセット */
grad.addColorStop(0,'#f7b34c');
grad.addColorStop(1,'#feeeea');
grad.addColorStop(1,'#c383a2');
/* グラデーションをfillStyleプロパティにセット */
ctx.fillStyle = grad;
/* 矩形を描画 */
ctx.rect(0,0, w,h);
ctx.fill();
var img = new Image();
var imgWidth = 120;
var imgHeight = 120;
img.src = "./src/muse.png";
img.onload = function(){
ctx.drawImage(img,w/2 - imgWidth/2,h/2 - imgHeight/2,imgWidth,imgHeight);
}
}
drawBackGround();
yumetobiEffects();