-
Notifications
You must be signed in to change notification settings - Fork 0
/
2015-09-17.html
172 lines (166 loc) · 5.51 KB
/
2015-09-17.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
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<!doctype html>
<html>
<head>
<title>2015/09/17</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1">
<style>
html, body {
height: 100%;
padding: 0;
margin: 0;
font-family: "ff-tisa-web-pro-1","ff-tisa-web-pro-2","Lucida Grande","Hiragino Sans GB","Hiragino Sans GB W3";
}
#canvas {
display: block;
/*cursor: none;*/
height: 100%;
width: 100%;
}
.sign {
position: absolute;
bottom: 20px;
right: 20px;
font-size: 14px;
color: #666;
font-style: italic;
}
#doujia {
position: absolute;
top: 50%;
left: 50%;
font-size: 18px;
-webkit-transform: translate3d(-50%, -50%, 0);
transform: translate3d(-50%, -50%, 0);
color: royalblue;
z-index: -1;
}
.help {
position: absolute;
bottom: 20px;
left: 20px;
color: #666;
font-size: 12px;
text-decoration: underline;
}
.description {
position: absolute;
bottom: 40px;
left: 20px;
color: #666;
font-size: 12px;
}
</style>
</head>
<body>
<canvas id="canvas"></canvas>
<div class="sign">Beyond</div>
<div id="doujia">
<!--Lovely Doujia, <br/>Do you like the stars~-->
</div>
<div class="help">
Use pc to see the effect~
</div>
<div id="position">
</div>
<script type="text/javascript" src="https://code.createjs.com/easeljs-0.8.1.min.js"></script>
<script>
+function() {
var stage = new createjs.Stage("canvas");
var width = document.body.clientWidth;
var height = document.body.clientHeight;
var count = 0;
var center = {};
function Particle(radius, color, x, y, finalX, finalY) {
this.finalX = finalX;
this.finalY = finalY;
this.particle = new createjs.Shape();
this.particle.graphics.beginFill(color).drawPolyStar(0, 0, radius, 6, 6, 0);//drawCircle(0, 0, radius);
this.particle.x = x;
this.particle.y = y;
stage.addChild(this.particle);
return this;
}
Particle.prototype.update = function() {
// this.particle.angle = this.particle.angle + 1 / Math.PI;
// console.log(this.particle.angle);
var disX = this.finalX - this.particle.x;
var disY = this.finalY - this.particle.y;
var dis = Math.sqrt(disX * disX + disY * disY);
if (dis > 2) {
this.particle.x += 2 * disX / dis;
this.particle.y += 2 * disY / dis;
}
else if (dis > 0.5){
this.particle.x += disX / dis;
this.particle.y += disY / dis;
}
};
function getImage(canvas) {
var ctx = canvas.getContext('2d');
var matrix = ctx.getImageData(width / 2 - 20, height / 2 - 15, 70, 21)
return matrix;
}
function init() {
var canvas = document.getElementById('canvas');
var colors = ["#00BFFF", "#FF69B4", "#3CB371", "#FFD700", "#CD5C5C", "#FF4500"];
var particles = [];
canvas.setAttribute('width', width);
canvas.setAttribute('height', height);
var text = new createjs.Text("Jessica", "20px Arial", "#00BFFF");
text.x = width / 2 - 20;
text.y = height / 2;
text.textBaseline = "alphabetic";
stage.addChild(text);
var text = new createjs.Text("Jessica", "20px Arial", "#FFFFFF");
text.x = width / 2 - 20;
text.y = height / 2;
text.textBaseline = "alphabetic";
stage.addChild(text);
stage.update();
var matrix = getImage(canvas);
var columns = matrix.width;
var rows = matrix.height;
var pmatrix = [];
var data = matrix.data;
var index = 0;
for (var i = 0; i < rows; i++) {
var row = [];
for (var j = 0; j < columns; j++) {
var r = data[index++];
var g = data[index++];
var b = data[index++];
if (r || g || b) {
row.push(1);
}
else {
row.push(0);
}
index++;
}
pmatrix.push(row);
}
stage.clear();
createjs.Ticker.setFPS(60);
var offsetX = (width - 15 * (columns - 1)) / 2;
var offsetY = (height - 15 * (rows - 1)) / 2;
for (i = 0; i < rows; i++) {
for (j = 0; j < columns; j++) {
if (pmatrix[i][j]) {
particles.push(new Particle(2, "#FF7F50", width / 2, height / 2, j * 15 + offsetX, i * 15 +
offsetY));
}
}
}
// stage.update();
createjs.Ticker.addEventListener("tick", function() {
particles.forEach(function(e) {
e.update();
})
stage.update();
});
}
window.onload = init;
}();
</script>
</body>
</html>