|
@@ -14,6 +14,7 @@
|
14
|
14
|
|
15
|
15
|
|
16
|
16
|
const S = {
|
|
17
|
+
|
17
|
18
|
init: function (conf) {
|
18
|
19
|
S.Drawing.init(conf);
|
19
|
20
|
S.ShapeBuilder.init(conf);
|
|
@@ -23,18 +24,64 @@ const S = {
|
23
|
24
|
});
|
24
|
25
|
},
|
25
|
26
|
performAction: function (value) {
|
|
27
|
+ console.log("🚀 ~ file: shape-shifter.js ~ line 27 ~ value", value)
|
|
28
|
+ const a = new Date()
|
|
29
|
+ console.log(a);
|
26
|
30
|
const fast = true;
|
27
|
31
|
S.Shape.switchShape(S.ShapeBuilder.letter(value), fast);
|
|
32
|
+ // let currentAction
|
|
33
|
+ // let interval
|
|
34
|
+
|
|
35
|
+ // function timedAction(fn, delay, max, reverse) {
|
|
36
|
+ // clearInterval(interval);
|
|
37
|
+ // currentAction = max;
|
|
38
|
+ // fn(currentAction);
|
|
39
|
+
|
|
40
|
+ // interval = setInterval(function () {
|
|
41
|
+ // currentAction = currentAction - 1;
|
|
42
|
+ // fn(currentAction);
|
|
43
|
+
|
|
44
|
+ // if ((!reverse && max && currentAction === max) || (reverse && currentAction === 0)) {
|
|
45
|
+ // clearInterval(interval);
|
|
46
|
+ // }
|
|
47
|
+ // }, delay);
|
|
48
|
+ // }
|
|
49
|
+ // switch ('countdown') {
|
|
50
|
+ // case 'countdown':
|
|
51
|
+ // value = parseInt(value) || 10;
|
|
52
|
+ // value = value > 0 ? value : 10;
|
|
53
|
+
|
|
54
|
+ // timedAction(function (index) {
|
|
55
|
+ // if (index === 0) {
|
|
56
|
+ // if (sequence.length === 0) {
|
|
57
|
+ // S.Shape.switchShape(S.ShapeBuilder.letter(''));
|
|
58
|
+ // } else {
|
|
59
|
+ // performAction(sequence);
|
|
60
|
+ // }
|
|
61
|
+ // } else {
|
|
62
|
+ // S.Shape.switchShape(S.ShapeBuilder.letter(index), true);
|
|
63
|
+ // }
|
|
64
|
+ // }, 1000, value, true);
|
|
65
|
+ // break;
|
|
66
|
+
|
|
67
|
+ // default:
|
|
68
|
+ // }
|
28
|
69
|
}
|
|
70
|
+
|
|
71
|
+
|
29
|
72
|
};
|
30
|
73
|
|
31
|
74
|
S.Drawing = (function () {
|
32
|
75
|
let canvas,
|
33
|
|
- context,
|
34
|
|
- renderFn,
|
35
|
|
- requestFrame = function(callback) {
|
36
|
|
- setTimeout(callback, 1000 / 60);
|
37
|
|
- };
|
|
76
|
+ context,
|
|
77
|
+ renderFn,
|
|
78
|
+ requestFrame = function (callback) {
|
|
79
|
+ setTimeout(callback, 1000 / 100); //气泡分散集合 用到的时间
|
|
80
|
+ };
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
38
|
85
|
|
39
|
86
|
return {
|
40
|
87
|
init: function (conf) {
|
|
@@ -70,9 +117,29 @@ S.Drawing = (function () {
|
70
|
117
|
context.closePath();
|
71
|
118
|
context.fill();
|
72
|
119
|
}
|
|
120
|
+
|
|
121
|
+
|
73
|
122
|
}
|
74
|
123
|
}());
|
75
|
124
|
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
|
76
|
143
|
S.Point = function (args) {
|
77
|
144
|
this.x = args.x;
|
78
|
145
|
this.y = args.y;
|
|
@@ -91,7 +158,7 @@ S.Color = function (r, g, b, a) {
|
91
|
158
|
|
92
|
159
|
S.Color.prototype = {
|
93
|
160
|
render: function () {
|
94
|
|
- return 'rgba(' + this.r + ',' + + this.g + ',' + this.b + ',' + this.a + ')';
|
|
161
|
+ return 'rgba(' + this.r + ',' + + this.g + ',' + this.b + ',' + this.a + ')';
|
95
|
162
|
}
|
96
|
163
|
};
|
97
|
164
|
|
|
@@ -132,10 +199,10 @@ S.Dot.prototype = {
|
132
|
199
|
|
133
|
200
|
_moveTowards: function (n) {
|
134
|
201
|
let details = this.distanceTo(n, true),
|
135
|
|
- dx = details[0],
|
136
|
|
- dy = details[1],
|
137
|
|
- d = details[2],
|
138
|
|
- e = this.e * d;
|
|
202
|
+ dx = details[0],
|
|
203
|
+ dy = details[1],
|
|
204
|
+ d = details[2],
|
|
205
|
+ e = this.e * d;
|
139
|
206
|
|
140
|
207
|
if (this.p.h === -1) {
|
141
|
208
|
this.p.x = n.x;
|
|
@@ -186,10 +253,12 @@ S.Dot.prototype = {
|
186
|
253
|
this.p.z = Math.max(1, this.p.z - (d * 0.05));
|
187
|
254
|
},
|
188
|
255
|
|
|
256
|
+
|
|
257
|
+
|
189
|
258
|
distanceTo: function (n, details) {
|
190
|
259
|
let dx = this.p.x - n.x,
|
191
|
|
- dy = this.p.y - n.y,
|
192
|
|
- d = Math.sqrt(dx * dx + dy * dy);
|
|
260
|
+ dy = this.p.y - n.y,
|
|
261
|
+ d = Math.sqrt(dx * dx + dy * dy);
|
193
|
262
|
|
194
|
263
|
return details ? [dx, dy, d] : d;
|
195
|
264
|
},
|
|
@@ -209,10 +278,10 @@ S.Dot.prototype = {
|
209
|
278
|
|
210
|
279
|
S.ShapeBuilder = (function () {
|
211
|
280
|
let gap = 13,
|
212
|
|
- shapeCanvas,
|
213
|
|
- shapeContext,
|
214
|
|
- fontSize = 500,
|
215
|
|
- fontFamily = 'Avenir, Helvetica Neue, Helvetica, Arial, sans-serif';
|
|
281
|
+ shapeCanvas,
|
|
282
|
+ shapeContext,
|
|
283
|
+ fontSize = 500,
|
|
284
|
+ fontFamily = 'Avenir, Helvetica Neue, Helvetica, Arial, sans-serif';
|
216
|
285
|
|
217
|
286
|
function fit({ width, height }) {
|
218
|
287
|
shapeCanvas.width = Math.floor(width / gap) * gap;
|
|
@@ -224,13 +293,13 @@ S.ShapeBuilder = (function () {
|
224
|
293
|
|
225
|
294
|
function processCanvas() {
|
226
|
295
|
let pixels = shapeContext.getImageData(0, 0, shapeCanvas.width, shapeCanvas.height).data,
|
227
|
|
- dots = [],
|
228
|
|
- x = 0,
|
229
|
|
- y = 0,
|
230
|
|
- fx = shapeCanvas.width,
|
231
|
|
- fy = shapeCanvas.height,
|
232
|
|
- w = 0,
|
233
|
|
- h = 0;
|
|
296
|
+ dots = [],
|
|
297
|
+ x = 0,
|
|
298
|
+ y = 0,
|
|
299
|
+ fx = shapeCanvas.width,
|
|
300
|
+ fy = shapeCanvas.height,
|
|
301
|
+ w = 0,
|
|
302
|
+ h = 0;
|
234
|
303
|
|
235
|
304
|
for (let p = 0; p < pixels.length; p += (4 * gap)) {
|
236
|
305
|
if (pixels[p + 3] > 0) {
|
|
@@ -250,7 +319,7 @@ S.ShapeBuilder = (function () {
|
250
|
319
|
if (x >= shapeCanvas.width) {
|
251
|
320
|
x = 0;
|
252
|
321
|
y += gap;
|
253
|
|
- p += gap * 4 * shapeCanvas.width;
|
|
322
|
+ p += gap * 4 * shapeCanvas.width; //数字分散程度
|
254
|
323
|
}
|
255
|
324
|
}
|
256
|
325
|
|
|
@@ -276,12 +345,12 @@ S.ShapeBuilder = (function () {
|
276
|
345
|
return {
|
277
|
346
|
init,
|
278
|
347
|
letter: function (l) {
|
279
|
|
- let s = 0;
|
|
348
|
+ let s = 0.;
|
280
|
349
|
|
281
|
350
|
setFontSize(fontSize);
|
282
|
351
|
s = Math.min(fontSize,
|
283
|
|
- (shapeCanvas.width / shapeContext.measureText(l).width) * 0.8 * fontSize,
|
284
|
|
- (shapeCanvas.height / fontSize) * (isNumber(l) ? 1 : 0.45) * fontSize);
|
|
352
|
+ (shapeCanvas.width / shapeContext.measureText(l).width) * 0.8 * fontSize,
|
|
353
|
+ (shapeCanvas.height / fontSize) * (isNumber(l) ? 1 : 0.45) * fontSize);
|
285
|
354
|
setFontSize(s);
|
286
|
355
|
|
287
|
356
|
shapeContext.clearRect(0, 0, shapeCanvas.width, shapeCanvas.height);
|
|
@@ -295,10 +364,10 @@ S.ShapeBuilder = (function () {
|
295
|
364
|
|
296
|
365
|
S.Shape = (function () {
|
297
|
366
|
let dots = [],
|
298
|
|
- width = 0,
|
299
|
|
- height = 0,
|
300
|
|
- cx = 0,
|
301
|
|
- cy = 0;
|
|
367
|
+ width = 0,
|
|
368
|
+ height = 0,
|
|
369
|
+ cx = 0,
|
|
370
|
+ cy = 0;
|
302
|
371
|
|
303
|
372
|
function compensate() {
|
304
|
373
|
let a = S.Drawing.getArea();
|
|
@@ -323,7 +392,7 @@ S.Shape = (function () {
|
323
|
392
|
|
324
|
393
|
switchShape: function (n, fast) {
|
325
|
394
|
let size,
|
326
|
|
- a = S.Drawing.getArea();
|
|
395
|
+ a = S.Drawing.getArea();
|
327
|
396
|
|
328
|
397
|
width = n.w;
|
329
|
398
|
height = n.h;
|
|
@@ -338,7 +407,7 @@ S.Shape = (function () {
|
338
|
407
|
}
|
339
|
408
|
|
340
|
409
|
let d = 0,
|
341
|
|
- i = 0;
|
|
410
|
+ i = 0;
|
342
|
411
|
|
343
|
412
|
while (n.dots.length > 0) {
|
344
|
413
|
i = Math.floor(Math.random() * n.dots.length);
|
|
@@ -380,7 +449,7 @@ S.Shape = (function () {
|
380
|
449
|
|
381
|
450
|
dots[i].s = false;
|
382
|
451
|
dots[i].e = 0.04;
|
383
|
|
- dots[i].move(new S.Point({
|
|
452
|
+ dots[i].move(new S.Point({
|
384
|
453
|
x: Math.random() * a.w,
|
385
|
454
|
y: Math.random() * a.h,
|
386
|
455
|
a: 0.3, //.4
|
|
@@ -400,3 +469,8 @@ S.Shape = (function () {
|
400
|
469
|
}());
|
401
|
470
|
|
402
|
471
|
export default S;
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
|