|
@@ -1,32 +1,31 @@
|
1
|
|
-var renderer,
|
2
|
|
- stage,
|
3
|
|
- screenWidth,
|
4
|
|
- screenHeight,
|
5
|
|
- counter,
|
6
|
|
- totalScreenPixels,
|
7
|
|
- cycleDuration,
|
8
|
|
- connectionDistance,
|
9
|
|
- connectionLimit,
|
10
|
|
- pointShiftDistance,
|
11
|
|
- colorShiftAmt,
|
12
|
|
- disconnectedColorShiftAmt,
|
13
|
|
- polygon,
|
14
|
|
- startPoints,
|
15
|
|
- polygonPoints,
|
16
|
|
- tweeningFns,
|
17
|
|
- lastLoop,
|
18
|
|
- thisLoop,
|
19
|
|
- fps,
|
20
|
|
- fpsGraphic,
|
21
|
|
- scrollDelta,
|
22
|
|
- pointShiftBiasX,
|
23
|
|
- pointShiftBiasY,
|
24
|
|
-
|
25
|
|
- fpsEnabled = false;
|
|
1
|
+var renderer;
|
|
2
|
+var stage;
|
|
3
|
+var screenWidth;
|
|
4
|
+var screenHeight;
|
|
5
|
+var counter;
|
|
6
|
+var totalScreenPixels;
|
|
7
|
+var cycleDuration;
|
|
8
|
+var connectionDistance;
|
|
9
|
+var connectionLimit;
|
|
10
|
+var pointShiftDistance;
|
|
11
|
+// var colorShiftAmt;
|
|
12
|
+var disconnectedColorShiftAmt;
|
|
13
|
+var polygon;
|
|
14
|
+var startPoints;
|
|
15
|
+var polygonPoints;
|
|
16
|
+var tweeningFns;
|
|
17
|
+var lastLoop;
|
|
18
|
+var thisLoop;
|
|
19
|
+var fps;
|
|
20
|
+var fpsGraphic;
|
|
21
|
+var scrollDelta;
|
|
22
|
+var pointShiftBiasX;
|
|
23
|
+var pointShiftBiasY;
|
|
24
|
+var fpsEnabled = false;
|
26
|
25
|
|
27
|
26
|
function randomInt (min, max) {
|
28
|
|
- // inclusive of min and max
|
29
|
|
- return Math.floor(Math.random() * (max - min + 1)) + min
|
|
27
|
+ // inclusive of min and max
|
|
28
|
+ return Math.floor(Math.random() * (max - min + 1)) + min;
|
30
|
29
|
}
|
31
|
30
|
|
32
|
31
|
function linearTweening (t, b, c, d) {
|
|
@@ -34,131 +33,133 @@ function linearTweening (t, b, c, d) {
|
34
|
33
|
// b = start value
|
35
|
34
|
// c = change in value
|
36
|
35
|
// d = duration
|
37
|
|
- return ((c * t) / d) + b
|
|
36
|
+ return ((c * t) / d) + b;
|
38
|
37
|
}
|
39
|
38
|
|
|
39
|
+/* eslint-disable no-unused-vars */
|
40
|
40
|
function easeOutBounce (t, b, c, d) {
|
41
|
|
- if ((t /= d) < (1 / 2.75)) {
|
42
|
|
- return c * (7.5625 * t * t) + b
|
43
|
|
- } else if (t < (2 / 2.75)) {
|
44
|
|
- return c * (7.5625 * (t -= (1.5 / 2.75)) * t + 0.75) + b
|
45
|
|
- } else if (t < (2.5 / 2.75)) {
|
46
|
|
- return c * (7.5625 * (t -= (2.25 / 2.75)) * t + 0.9375) + b
|
47
|
|
- } else {
|
48
|
|
- return c * (7.5625 * (t -= (2.625 / 2.75)) * t + 0.984375) + b
|
49
|
|
- }
|
|
41
|
+ if ((t /= d) < (1 / 2.75)) {
|
|
42
|
+ return c * (7.5625 * t * t) + b;
|
|
43
|
+ } else if (t < (2 / 2.75)) {
|
|
44
|
+ return c * (7.5625 * (t -= (1.5 / 2.75)) * t + 0.75) + b;
|
|
45
|
+ } else if (t < (2.5 / 2.75)) {
|
|
46
|
+ return c * (7.5625 * (t -= (2.25 / 2.75)) * t + 0.9375) + b;
|
|
47
|
+ } else {
|
|
48
|
+ return c * (7.5625 * (t -= (2.625 / 2.75)) * t + 0.984375) + b;
|
|
49
|
+ }
|
50
|
50
|
}
|
51
|
51
|
|
52
|
52
|
function easeInSine (t, b, c, d) {
|
53
|
|
- return -c * Math.cos(t / d * (Math.PI / 2)) + c + b
|
|
53
|
+ return -c * Math.cos(t / d * (Math.PI / 2)) + c + b;
|
54
|
54
|
}
|
55
|
55
|
|
56
|
56
|
function easeOutSine (t, b, c, d) {
|
57
|
|
- return c * Math.sin(t / d * (Math.PI / 2)) + b
|
|
57
|
+ return c * Math.sin(t / d * (Math.PI / 2)) + b;
|
58
|
58
|
}
|
59
|
59
|
|
60
|
60
|
function easeInOutSine (t, b, c, d) {
|
61
|
|
- return -c / 2 * (Math.cos(Math.PI * t / d) - 1) + b
|
|
61
|
+ return -c / 2 * (Math.cos(Math.PI * t / d) - 1) + b;
|
62
|
62
|
}
|
63
|
63
|
|
64
|
64
|
function easeInQuad (t, b, c, d) {
|
65
|
|
- return c * (t /= d) * t + b
|
|
65
|
+ return c * (t /= d) * t + b;
|
66
|
66
|
}
|
67
|
67
|
|
68
|
68
|
function easeOutQuad (t, b, c, d) {
|
69
|
|
- return -c * (t /= d) * (t - 2) + b
|
|
69
|
+ return -c * (t /= d) * (t - 2) + b;
|
70
|
70
|
}
|
71
|
71
|
|
72
|
72
|
function easeInOutQuad (t, b, c, d) {
|
73
|
|
- if ((t /= d / 2) < 1) return c / 2 * t * t + b
|
74
|
|
- return -c / 2 * ((--t) * (t - 2) - 1) + b
|
|
73
|
+ if ((t /= d / 2) < 1) return c / 2 * t * t + b;
|
|
74
|
+ return -c / 2 * ((--t) * (t - 2) - 1) + b;
|
75
|
75
|
}
|
76
|
76
|
|
77
|
77
|
function easeInCubic (t, b, c, d) {
|
78
|
|
- return c * (t /= d) * t * t + b
|
|
78
|
+ return c * (t /= d) * t * t + b;
|
79
|
79
|
}
|
80
|
80
|
|
81
|
81
|
function easeOutCubic (t, b, c, d) {
|
82
|
|
- return c * ((t = t / d - 1) * t * t + 1) + b
|
|
82
|
+ return c * ((t = t / d - 1) * t * t + 1) + b;
|
83
|
83
|
}
|
84
|
84
|
|
85
|
85
|
function easeInOutCubic (t, b, c, d) {
|
86
|
|
- if ((t /= d / 2) < 1) return c / 2 * t * t * t + b
|
87
|
|
- return c / 2 * ((t -= 2) * t * t + 2) + b
|
|
86
|
+ if ((t /= d / 2) < 1) return c / 2 * t * t * t + b;
|
|
87
|
+ return c / 2 * ((t -= 2) * t * t + 2) + b;
|
88
|
88
|
}
|
89
|
89
|
|
90
|
90
|
function easeInExpo (t, b, c, d) {
|
91
|
|
- return (t == 0) ? b : c * Math.pow(2, 10 * (t / d - 1)) + b
|
|
91
|
+ return (t === 0) ? b : c * Math.pow(2, 10 * (t / d - 1)) + b;
|
92
|
92
|
}
|
93
|
93
|
|
94
|
94
|
function easeOutExpo (t, b, c, d) {
|
95
|
|
- return (t == d) ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b
|
|
95
|
+ return (t === d) ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b;
|
96
|
96
|
}
|
97
|
97
|
|
98
|
98
|
function easeInOutExpo (t, b, c, d) {
|
99
|
|
- if (t == 0) return b
|
100
|
|
- if (t == d) return b + c
|
101
|
|
- if ((t /= d / 2) < 1) return c / 2 * Math.pow(2, 10 * (t - 1)) + b
|
102
|
|
- return c / 2 * (-Math.pow(2, -10 * --t) + 2) + b
|
|
99
|
+ if (t === 0) return b;
|
|
100
|
+ if (t === d) return b + c;
|
|
101
|
+ if ((t /= d / 2) < 1) return c / 2 * Math.pow(2, 10 * (t - 1)) + b;
|
|
102
|
+ return c / 2 * (-Math.pow(2, -10 * --t) + 2) + b;
|
103
|
103
|
}
|
104
|
104
|
|
105
|
105
|
function easeInElastic (t, b, c, d) {
|
106
|
|
- var s = 1.70158; var p = 0; var a = c
|
107
|
|
- if (t == 0) return b; if ((t /= d) == 1) return b + c; if (!p) p = d * 0.3
|
108
|
|
- if (a < Math.abs(c)) { a = c; var s = p / 4 } else var s = p / (2 * Math.PI) * Math.asin(c / a)
|
109
|
|
- return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b
|
|
106
|
+ var s = 1.70158; var p = 0; var a = c;
|
|
107
|
+ if (t === 0) return b; if ((t /= d) === 1) return b + c; if (!p) p = d * 0.3;
|
|
108
|
+ if (a < Math.abs(c)) { a = c; s = p / 4; } else s = p / (2 * Math.PI) * Math.asin(c / a);
|
|
109
|
+ return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
|
110
|
110
|
}
|
111
|
111
|
|
112
|
112
|
function easeOutElastic (t, b, c, d) {
|
113
|
|
- var s = 1.70158; var p = 0; var a = c
|
114
|
|
- if (t == 0) return b; if ((t /= d) == 1) return b + c; if (!p) p = d * 0.3
|
115
|
|
- if (a < Math.abs(c)) { a = c; var s = p / 4 } else var s = p / (2 * Math.PI) * Math.asin(c / a)
|
116
|
|
- return a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + c + b
|
|
113
|
+ var s = 1.70158; var p = 0; var a = c;
|
|
114
|
+ if (t === 0) return b; if ((t /= d) === 1) return b + c; if (!p) p = d * 0.3;
|
|
115
|
+ if (a < Math.abs(c)) { a = c; s = p / 4; } else s = p / (2 * Math.PI) * Math.asin(c / a);
|
|
116
|
+ return a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + c + b;
|
117
|
117
|
}
|
118
|
118
|
|
119
|
119
|
function easeInOutElastic (t, b, c, d) {
|
120
|
|
- var s = 1.70158; var p = 0; var a = c
|
121
|
|
- if (t == 0) return b; if ((t /= d / 2) == 2) return b + c; if (!p) p = d * (0.3 * 1.5)
|
122
|
|
- if (a < Math.abs(c)) { a = c; var s = p / 4 } else var s = p / (2 * Math.PI) * Math.asin(c / a)
|
123
|
|
- if (t < 1) return -0.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b
|
124
|
|
- return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p) * 0.5 + c + b
|
|
120
|
+ var s = 1.70158; var p = 0; var a = c;
|
|
121
|
+ if (t === 0) return b; if ((t /= d / 2) === 2) return b + c; if (!p) p = d * (0.3 * 1.5);
|
|
122
|
+ if (a < Math.abs(c)) { a = c; s = p / 4; } else s = p / (2 * Math.PI) * Math.asin(c / a);
|
|
123
|
+ if (t < 1) return -0.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
|
|
124
|
+ return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p) * 0.5 + c + b;
|
125
|
125
|
}
|
126
|
126
|
|
127
|
127
|
function easeInCirc (t, b, c, d) {
|
128
|
|
- return -c * (Math.sqrt(1 - (t /= d) * t) - 1) + b
|
|
128
|
+ return -c * (Math.sqrt(1 - (t /= d) * t) - 1) + b;
|
129
|
129
|
}
|
130
|
130
|
|
131
|
131
|
function easeOutCirc (t, b, c, d) {
|
132
|
|
- return c * Math.sqrt(1 - (t = t / d - 1) * t) + b
|
|
132
|
+ return c * Math.sqrt(1 - (t = t / d - 1) * t) + b;
|
133
|
133
|
}
|
134
|
134
|
|
135
|
135
|
function easeInOutCirc (t, b, c, d) {
|
136
|
|
- if ((t /= d / 2) < 1) return -c / 2 * (Math.sqrt(1 - t * t) - 1) + b
|
137
|
|
- return c / 2 * (Math.sqrt(1 - (t -= 2) * t) + 1) + b
|
|
136
|
+ if ((t /= d / 2) < 1) return -c / 2 * (Math.sqrt(1 - t * t) - 1) + b;
|
|
137
|
+ return c / 2 * (Math.sqrt(1 - (t -= 2) * t) + 1) + b;
|
138
|
138
|
}
|
|
139
|
+/* eslint-enable no-unused-vars */
|
139
|
140
|
|
140
|
141
|
// from: http://stackoverflow.com/a/5624139
|
141
|
142
|
// modified to return integer literal
|
142
|
143
|
function rgbToHex (color) {
|
143
|
|
- return parseInt(((1 << 24) + (color.r << 16) + (color.g << 8) + color.b).toString(16).slice(1), 16)
|
|
144
|
+ return parseInt(((1 << 24) + (color.r << 16) + (color.g << 8) + color.b).toString(16).slice(1), 16);
|
144
|
145
|
}
|
145
|
146
|
|
146
|
147
|
/* Choose a random RGB color */
|
147
|
148
|
function randomColor () {
|
148
|
|
- return {
|
149
|
|
- r: Math.floor(Math.random() * (255 + 1)),
|
150
|
|
- g: Math.floor(Math.random() * (255 + 1)),
|
151
|
|
- b: Math.floor(Math.random() * (255 + 1))
|
152
|
|
- }
|
|
149
|
+ return {
|
|
150
|
+ r: Math.floor(Math.random() * (255 + 1)),
|
|
151
|
+ g: Math.floor(Math.random() * (255 + 1)),
|
|
152
|
+ b: Math.floor(Math.random() * (255 + 1))
|
|
153
|
+ };
|
153
|
154
|
}
|
154
|
155
|
|
155
|
156
|
/* Find the average of two RGB colors and return one RGB of that color */
|
156
|
157
|
function averageColor (color1, color2) {
|
157
|
|
- return {
|
158
|
|
- r: Math.round((color1.r + color2.r) / 2),
|
159
|
|
- g: Math.round((color1.g + color2.g) / 2),
|
160
|
|
- b: Math.round((color1.b + color2.b) / 2)
|
161
|
|
- }
|
|
158
|
+ return {
|
|
159
|
+ r: Math.round((color1.r + color2.r) / 2),
|
|
160
|
+ g: Math.round((color1.g + color2.g) / 2),
|
|
161
|
+ b: Math.round((color1.b + color2.b) / 2)
|
|
162
|
+ };
|
162
|
163
|
}
|
163
|
164
|
|
164
|
165
|
/*
|
|
@@ -166,243 +167,244 @@ function averageColor (color1, color2) {
|
166
|
167
|
* weight is a decimal between 0 and 1.
|
167
|
168
|
*/
|
168
|
169
|
function weightedAverageColor (color1, color2, weight) {
|
169
|
|
- return {
|
170
|
|
- r: Math.round(((color1.r * (2 * weight)) + (color2.r * (2 * (1 - weight)))) / 2),
|
171
|
|
- g: Math.round(((color1.g * (2 * weight)) + (color2.g * (2 * (1 - weight)))) / 2),
|
172
|
|
- b: Math.round(((color1.b * (2 * weight)) + (color2.b * (2 * (1 - weight)))) / 2)
|
173
|
|
- }
|
|
170
|
+ return {
|
|
171
|
+ r: Math.round(((color1.r * (2 * weight)) + (color2.r * (2 * (1 - weight)))) / 2),
|
|
172
|
+ g: Math.round(((color1.g * (2 * weight)) + (color2.g * (2 * (1 - weight)))) / 2),
|
|
173
|
+ b: Math.round(((color1.b * (2 * weight)) + (color2.b * (2 * (1 - weight)))) / 2)
|
|
174
|
+ };
|
174
|
175
|
}
|
175
|
176
|
|
176
|
177
|
/* Darken the color by a factor of 0 to 1, where 1 is black and 0 is white */
|
177
|
178
|
function shadeColor (color, shadeFactor) {
|
178
|
|
- return {
|
179
|
|
- r: Math.round(color.r * (1 - shadeFactor)),
|
180
|
|
- g: Math.round(color.g * (1 - shadeFactor)),
|
181
|
|
- b: Math.round(color.b * (1 - shadeFactor))
|
182
|
|
- }
|
|
179
|
+ return {
|
|
180
|
+ r: Math.round(color.r * (1 - shadeFactor)),
|
|
181
|
+ g: Math.round(color.g * (1 - shadeFactor)),
|
|
182
|
+ b: Math.round(color.b * (1 - shadeFactor))
|
|
183
|
+ };
|
183
|
184
|
}
|
184
|
185
|
|
185
|
186
|
/* Given a color component (red, green, or blue int), randomly shift by configurable amount */
|
186
|
187
|
function shiftColorComponent (component, maxShiftAmt) {
|
187
|
|
- var shiftAmt = randomInt(maxShiftAmt * -1, maxShiftAmt),
|
188
|
|
- newComponent = component + shiftAmt
|
189
|
|
- if ((newComponent < 0) || (newComponent > 255)) {
|
190
|
|
- newComponent = component - shiftAmt
|
191
|
|
- }
|
192
|
|
- return newComponent
|
|
188
|
+ var shiftAmt = randomInt(maxShiftAmt * -1, maxShiftAmt);
|
|
189
|
+ var newComponent = component + shiftAmt;
|
|
190
|
+ if ((newComponent < 0) || (newComponent > 255)) {
|
|
191
|
+ newComponent = component - shiftAmt;
|
|
192
|
+ }
|
|
193
|
+ return newComponent;
|
193
|
194
|
}
|
194
|
195
|
|
195
|
196
|
/* Randomly shift a RGB color by a configurable amount and return new RGB color */
|
196
|
197
|
function shiftColor (color, maxShiftAmt) {
|
197
|
|
- return {
|
198
|
|
- r: shiftColorComponent(color.r, maxShiftAmt),
|
199
|
|
- g: shiftColorComponent(color.g, maxShiftAmt),
|
200
|
|
- b: shiftColorComponent(color.b, maxShiftAmt)
|
201
|
|
- }
|
|
198
|
+ return {
|
|
199
|
+ r: shiftColorComponent(color.r, maxShiftAmt),
|
|
200
|
+ g: shiftColorComponent(color.g, maxShiftAmt),
|
|
201
|
+ b: shiftColorComponent(color.b, maxShiftAmt)
|
|
202
|
+ };
|
202
|
203
|
}
|
203
|
204
|
|
204
|
205
|
function distance (point1, point2) {
|
205
|
|
- var a = point1[0] - point2[0]
|
206
|
|
- var b = point1[1] - point2[1]
|
207
|
|
- return Math.sqrt(a * a + b * b)
|
|
206
|
+ var a = point1[0] - point2[0];
|
|
207
|
+ var b = point1[1] - point2[1];
|
|
208
|
+ return Math.sqrt(a * a + b * b);
|
208
|
209
|
}
|
209
|
210
|
|
210
|
211
|
function getRandomPoints (numPoints, maxX, maxY, tweeningFns) {
|
211
|
|
- var points = [],
|
212
|
|
- i, x, y, cycleStart, easingFn
|
213
|
|
- for (i = 0; i < numPoints; i++) {
|
214
|
|
- x = randomInt(0, maxX - 1)
|
215
|
|
- y = randomInt(0, maxY - 1)
|
216
|
|
- cycleStart = randomInt(0, cycleDuration - 1)
|
217
|
|
- color = randomColor()
|
218
|
|
- easingFn = randomInt(0, tweeningFns.length - 1)
|
219
|
|
- points[i] = [x, y, cycleStart, color, easingFn]
|
220
|
|
- }
|
221
|
|
- return points
|
|
212
|
+ var i, x, y, color, cycleStart, easingFn;
|
|
213
|
+ var points = [];
|
|
214
|
+ for (i = 0; i < numPoints; i++) {
|
|
215
|
+ x = randomInt(0, maxX - 1);
|
|
216
|
+ y = randomInt(0, maxY - 1);
|
|
217
|
+ cycleStart = randomInt(0, cycleDuration - 1);
|
|
218
|
+ color = randomColor();
|
|
219
|
+ easingFn = randomInt(0, tweeningFns.length - 1);
|
|
220
|
+ points[i] = [x, y, cycleStart, color, easingFn];
|
|
221
|
+ }
|
|
222
|
+ return points;
|
222
|
223
|
}
|
223
|
224
|
|
|
225
|
+// eslint-disable-next-line no-unused-vars
|
224
|
226
|
function shiftPointCounter (original, maxShiftAmt) {
|
225
|
|
- var shiftAmt = randomInt(maxShiftAmt * -1, 0),
|
226
|
|
- newCounter = original + shiftAmt
|
227
|
|
- if (newCounter < 0) {
|
228
|
|
- newCounter = cycleDuration + shiftAmt
|
229
|
|
- }
|
230
|
|
- return newCounter
|
|
227
|
+ var shiftAmt = randomInt(maxShiftAmt * -1, 0);
|
|
228
|
+ var newCounter = original + shiftAmt;
|
|
229
|
+ if (newCounter < 0) {
|
|
230
|
+ newCounter = cycleDuration + shiftAmt;
|
|
231
|
+ }
|
|
232
|
+ return newCounter;
|
231
|
233
|
}
|
232
|
234
|
|
233
|
235
|
function shiftPoints (points, maxShiftAmt, counter, tweeningFns) {
|
234
|
|
- var i, shiftX, shiftY, candidateX, candidateY
|
235
|
|
- for (i = 0; i < points.original.length; i++) {
|
236
|
|
- if (points.target[i][2] >= cycleDuration) {
|
|
236
|
+ var i, shiftX, shiftY, candidateX, candidateY;
|
|
237
|
+ for (i = 0; i < points.original.length; i++) {
|
|
238
|
+ if (points.target[i][2] >= cycleDuration) {
|
237
|
239
|
// cycleDuration was reduced and now this point's cycle is out of bounds. Randomly pick a new valid one.
|
238
|
|
- points.target[i][2] = randomInt(0, cycleDuration - 1)
|
239
|
|
- }
|
240
|
|
- if (points.target[i][2] === counter) {
|
241
|
|
- points.original[i] = points.target[i].slice()
|
242
|
|
- shiftX = randomInt(maxShiftAmt * -1, maxShiftAmt)
|
243
|
|
- shiftY = randomInt(maxShiftAmt * -1, maxShiftAmt)
|
244
|
|
- if (((shiftX < 0) && (pointShiftBiasX === 1)) || ((shiftX > 0) && (pointShiftBiasX === -1))) {
|
245
|
|
- shiftX = shiftX * -1
|
246
|
|
- }
|
247
|
|
- if (((shiftY < 0) && (pointShiftBiasY === 1)) || ((shiftY > 0) && (pointShiftBiasY === -1))) {
|
248
|
|
- shiftY = shiftY * -1
|
249
|
|
- }
|
250
|
|
- candidateX = points.original[i][0] + shiftX
|
251
|
|
- candidateY = points.original[i][1] + shiftY
|
252
|
|
- if ((candidateX > screenWidth) || (candidateX < 0)) {
|
253
|
|
- candidateX = points.original[i][0] - shiftX
|
254
|
|
- }
|
255
|
|
- if ((candidateY > screenHeight) || (candidateY < 0)) {
|
256
|
|
- candidateY = points.original[i][1] - shiftY
|
257
|
|
- }
|
258
|
|
- points.target[i][0] = candidateX
|
259
|
|
- points.target[i][1] = candidateY
|
260
|
|
- points.target[i][4] = randomInt(0, tweeningFns.length - 1)
|
|
240
|
+ points.target[i][2] = randomInt(0, cycleDuration - 1);
|
|
241
|
+ }
|
|
242
|
+ if (points.target[i][2] === counter) {
|
|
243
|
+ points.original[i] = points.target[i].slice();
|
|
244
|
+ shiftX = randomInt(maxShiftAmt * -1, maxShiftAmt);
|
|
245
|
+ shiftY = randomInt(maxShiftAmt * -1, maxShiftAmt);
|
|
246
|
+ if (((shiftX < 0) && (pointShiftBiasX === 1)) || ((shiftX > 0) && (pointShiftBiasX === -1))) {
|
|
247
|
+ shiftX = shiftX * -1;
|
|
248
|
+ }
|
|
249
|
+ if (((shiftY < 0) && (pointShiftBiasY === 1)) || ((shiftY > 0) && (pointShiftBiasY === -1))) {
|
|
250
|
+ shiftY = shiftY * -1;
|
|
251
|
+ }
|
|
252
|
+ candidateX = points.original[i][0] + shiftX;
|
|
253
|
+ candidateY = points.original[i][1] + shiftY;
|
|
254
|
+ if ((candidateX > screenWidth) || (candidateX < 0)) {
|
|
255
|
+ candidateX = points.original[i][0] - shiftX;
|
|
256
|
+ }
|
|
257
|
+ if ((candidateY > screenHeight) || (candidateY < 0)) {
|
|
258
|
+ candidateY = points.original[i][1] - shiftY;
|
|
259
|
+ }
|
|
260
|
+ points.target[i][0] = candidateX;
|
|
261
|
+ points.target[i][1] = candidateY;
|
|
262
|
+ points.target[i][4] = randomInt(0, tweeningFns.length - 1);
|
261
|
263
|
// FIXME: buggy, makes points jump around too fast
|
262
|
264
|
// points.target[i][2] = shiftPointCounter(points.original[i][2], maxShiftAmt);
|
|
265
|
+ }
|
263
|
266
|
}
|
264
|
|
- }
|
265
|
267
|
// clear pointShiftBiases now that they have been "used"
|
266
|
|
- pointShiftBiasX = 0
|
267
|
|
- pointShiftBiasY = 0
|
|
268
|
+ pointShiftBiasX = 0;
|
|
269
|
+ pointShiftBiasY = 0;
|
268
|
270
|
|
269
|
|
- return points
|
|
271
|
+ return points;
|
270
|
272
|
}
|
271
|
273
|
|
272
|
274
|
function redistributeCycles (points) {
|
273
|
|
- for (i = 0; i < points.original.length; i++) {
|
274
|
|
- points.target[i][2] = randomInt(0, cycleDuration - 1)
|
275
|
|
- }
|
276
|
|
- return points
|
|
275
|
+ for (var i = 0; i < points.original.length; i++) {
|
|
276
|
+ points.target[i][2] = randomInt(0, cycleDuration - 1);
|
|
277
|
+ }
|
|
278
|
+ return points;
|
277
|
279
|
}
|
278
|
280
|
|
279
|
281
|
function relativeCounter (counter, targetStart) {
|
280
|
|
- var relCounter = counter - targetStart
|
281
|
|
- if (relCounter < 0) {
|
282
|
|
- return cycleDuration + relCounter
|
283
|
|
- }
|
284
|
|
- return relCounter
|
|
282
|
+ var relCounter = counter - targetStart;
|
|
283
|
+ if (relCounter < 0) {
|
|
284
|
+ return cycleDuration + relCounter;
|
|
285
|
+ }
|
|
286
|
+ return relCounter;
|
285
|
287
|
}
|
286
|
288
|
|
287
|
289
|
function drawPolygon (polygon, points, counter, tweeningFns) {
|
288
|
|
- var i, j, easingFn, avgColor, connectionCount, dist, proximity
|
|
290
|
+ var i, j, easingFn, avgColor, shadedColor, connectionCount, dist, connectivity;
|
289
|
291
|
// calculate vectors
|
290
|
|
- for (i = 0; i < points.original.length; i++) {
|
291
|
|
- easingFn = tweeningFns[points.target[i][4]]
|
292
|
|
- points.tweened[i][0] = easingFn(relativeCounter(counter, points.target[i][2]), points.original[i][0], points.target[i][0] - points.original[i][0], cycleDuration)
|
293
|
|
- points.tweened[i][1] = easingFn(relativeCounter(counter, points.target[i][2]), points.original[i][1], points.target[i][1] - points.original[i][1], cycleDuration)
|
294
|
|
- }
|
|
292
|
+ for (i = 0; i < points.original.length; i++) {
|
|
293
|
+ easingFn = tweeningFns[points.target[i][4]];
|
|
294
|
+ points.tweened[i][0] = easingFn(relativeCounter(counter, points.target[i][2]), points.original[i][0], points.target[i][0] - points.original[i][0], cycleDuration);
|
|
295
|
+ points.tweened[i][1] = easingFn(relativeCounter(counter, points.target[i][2]), points.original[i][1], points.target[i][1] - points.original[i][1], cycleDuration);
|
|
296
|
+ }
|
295
|
297
|
// draw lines
|
296
|
|
- for (i = 0; i < points.original.length; i++) {
|
297
|
|
- connectionCount = 0
|
298
|
|
- for (j = i + 1; j < points.original.length; j++) {
|
|
298
|
+ for (i = 0; i < points.original.length; i++) {
|
|
299
|
+ connectionCount = 0;
|
|
300
|
+ for (j = i + 1; j < points.original.length; j++) {
|
299
|
301
|
// TODO pick the N (connectionLimit) closest connections instead of the first N that occur sequentially.
|
300
|
|
- if (connectionCount >= connectionLimit) break
|
301
|
|
- dist = distance(points.tweened[i], points.tweened[j])
|
302
|
|
- connectivity = dist / connectionDistance
|
303
|
|
- if ((j !== i) && (dist <= connectionDistance)) {
|
|
302
|
+ if (connectionCount >= connectionLimit) break;
|
|
303
|
+ dist = distance(points.tweened[i], points.tweened[j]);
|
|
304
|
+ connectivity = dist / connectionDistance;
|
|
305
|
+ if ((j !== i) && (dist <= connectionDistance)) {
|
304
|
306
|
// find average color of both points
|
305
|
|
- if ((points.tweened[i][2] === counter) || (points.tweened[j][2] === counter)) {
|
|
307
|
+ if ((points.tweened[i][2] === counter) || (points.tweened[j][2] === counter)) {
|
306
|
308
|
// avgColor = shiftColor(avgColor, Math.round(colorShiftAmt * (1 - connectivity)));
|
307
|
|
- points.tweened[i][3] = weightedAverageColor(points.tweened[i][3], points.tweened[j][3], connectivity)
|
308
|
|
- points.tweened[j][3] = weightedAverageColor(points.tweened[j][3], points.tweened[i][3], connectivity)
|
|
309
|
+ points.tweened[i][3] = weightedAverageColor(points.tweened[i][3], points.tweened[j][3], connectivity);
|
|
310
|
+ points.tweened[j][3] = weightedAverageColor(points.tweened[j][3], points.tweened[i][3], connectivity);
|
|
311
|
+ }
|
|
312
|
+ avgColor = averageColor(points.tweened[i][3], points.tweened[j][3]);
|
|
313
|
+ shadedColor = shadeColor(avgColor, connectivity);
|
|
314
|
+ polygon.lineStyle(1, rgbToHex(shadedColor), 1);
|
|
315
|
+
|
|
316
|
+ polygon.moveTo(points.tweened[i][0], points.tweened[i][1]);
|
|
317
|
+ polygon.lineTo(points.tweened[j][0], points.tweened[j][1]);
|
|
318
|
+ connectionCount = connectionCount + 1;
|
|
319
|
+ }
|
309
|
320
|
}
|
310
|
|
- avgColor = averageColor(points.tweened[i][3], points.tweened[j][3])
|
311
|
|
- shadedColor = shadeColor(avgColor, connectivity)
|
312
|
|
- polygon.lineStyle(1, rgbToHex(shadedColor), 1)
|
313
|
|
-
|
314
|
|
- polygon.moveTo(points.tweened[i][0], points.tweened[i][1])
|
315
|
|
- polygon.lineTo(points.tweened[j][0], points.tweened[j][1])
|
316
|
|
- connectionCount = connectionCount + 1
|
317
|
|
- }
|
318
|
|
- }
|
319
|
321
|
|
320
|
|
- if (connectionCount === 0) {
|
321
|
|
- points.tweened[i][3] = shiftColor(points.tweened[i][3], disconnectedColorShiftAmt)
|
322
|
|
- }
|
|
322
|
+ if (connectionCount === 0) {
|
|
323
|
+ points.tweened[i][3] = shiftColor(points.tweened[i][3], disconnectedColorShiftAmt);
|
|
324
|
+ }
|
323
|
325
|
|
324
|
326
|
// draw vectors
|
325
|
|
- polygon.lineStyle(1, rgbToHex(points.tweened[i][3]), 1)
|
326
|
|
- polygon.drawCircle(points.tweened[i][0], points.tweened[i][1], 1)
|
327
|
|
- }
|
|
327
|
+ polygon.lineStyle(1, rgbToHex(points.tweened[i][3]), 1);
|
|
328
|
+ polygon.drawCircle(points.tweened[i][0], points.tweened[i][1], 1);
|
|
329
|
+ }
|
328
|
330
|
}
|
329
|
331
|
|
330
|
332
|
function loop () {
|
331
|
|
- screenWidth = document.documentElement.clientWidth
|
332
|
|
- screenHeight = document.documentElement.clientHeight
|
333
|
|
- renderer.resize(screenWidth, screenHeight)
|
|
333
|
+ screenWidth = document.documentElement.clientWidth;
|
|
334
|
+ screenHeight = document.documentElement.clientHeight;
|
|
335
|
+ renderer.resize(screenWidth, screenHeight);
|
334
|
336
|
|
335
|
|
- polygon.clear()
|
|
337
|
+ polygon.clear();
|
336
|
338
|
|
337
|
|
- drawPolygon(polygon, polygonPoints, counter, tweeningFns)
|
|
339
|
+ drawPolygon(polygon, polygonPoints, counter, tweeningFns);
|
338
|
340
|
|
339
|
|
- counter += 1
|
340
|
|
- counter = counter % cycleDuration
|
|
341
|
+ counter += 1;
|
|
342
|
+ counter = counter % cycleDuration;
|
341
|
343
|
|
342
|
|
- if (counter === 0 && fpsEnabled) {
|
343
|
|
- thisLoop = new Date()
|
344
|
|
- fps = Math.round((1000 / (thisLoop - lastLoop)) * cycleDuration)
|
345
|
|
- fpsGraphic.setText(fps.toString())
|
346
|
|
- lastLoop = thisLoop
|
347
|
|
- }
|
|
344
|
+ if (counter === 0 && fpsEnabled) {
|
|
345
|
+ thisLoop = new Date();
|
|
346
|
+ fps = Math.round((1000 / (thisLoop - lastLoop)) * cycleDuration);
|
|
347
|
+ fpsGraphic.setText(fps.toString());
|
|
348
|
+ lastLoop = thisLoop;
|
|
349
|
+ }
|
348
|
350
|
|
349
|
|
- polygonPoints = shiftPoints(polygonPoints, pointShiftDistance, counter, tweeningFns)
|
|
351
|
+ polygonPoints = shiftPoints(polygonPoints, pointShiftDistance, counter, tweeningFns);
|
350
|
352
|
|
351
|
353
|
// var mousePosition = renderer.plugins.interaction.mouse.global;
|
352
|
354
|
// triangle.x = mousePosition.x;
|
353
|
355
|
// triangle.y = mousePosition.y;
|
354
|
356
|
|
355
|
357
|
// If user scrolled, modify cycleDuration by amount scrolled
|
356
|
|
- if (scrollDelta !== 0) {
|
357
|
|
- cycleDuration = cycleDuration + scrollDelta
|
358
|
|
- if (cycleDuration < 1) {
|
359
|
|
- cycleDuration = 1
|
|
358
|
+ if (scrollDelta !== 0) {
|
|
359
|
+ cycleDuration = cycleDuration + scrollDelta;
|
|
360
|
+ if (cycleDuration < 1) {
|
|
361
|
+ cycleDuration = 1;
|
|
362
|
+ }
|
|
363
|
+ scrollDelta = 0;
|
|
364
|
+ polygonPoints = redistributeCycles(polygonPoints);
|
360
|
365
|
}
|
361
|
|
- scrollDelta = 0
|
362
|
|
- polygonPoints = redistributeCycles(polygonPoints)
|
363
|
|
- }
|
364
|
366
|
|
365
|
367
|
// Tell the `renderer` to `render` the `stage`
|
366
|
|
- renderer.render(stage)
|
367
|
|
- requestAnimationFrame(loop)
|
|
368
|
+ renderer.render(stage);
|
|
369
|
+ window.requestAnimationFrame(loop);
|
368
|
370
|
}
|
369
|
371
|
|
370
|
372
|
function loopStart () {
|
371
|
|
- screenWidth = document.documentElement.clientWidth
|
372
|
|
- screenHeight = document.documentElement.clientHeight
|
|
373
|
+ screenWidth = document.documentElement.clientWidth;
|
|
374
|
+ screenHeight = document.documentElement.clientHeight;
|
373
|
375
|
// Create the renderer
|
374
|
|
- renderer = PIXI.autoDetectRenderer(screenWidth, screenHeight, {antialias: true, resolution: 2})
|
|
376
|
+ renderer = window.PIXI.autoDetectRenderer(screenWidth, screenHeight, {antialias: true, resolution: 2});
|
375
|
377
|
|
376
|
378
|
// Add the canvas to the HTML document
|
377
|
|
- document.body.appendChild(renderer.view)
|
|
379
|
+ document.body.appendChild(renderer.view);
|
378
|
380
|
|
379
|
381
|
// Create a container object called the `stage`
|
380
|
|
- stage = new PIXI.Container()
|
381
|
|
-
|
382
|
|
- renderer.view.style.position = 'absolute'
|
383
|
|
- renderer.view.style.display = 'block'
|
384
|
|
- renderer.autoResize = true
|
385
|
|
-
|
386
|
|
- counter = 0
|
387
|
|
- totalScreenPixels = screenWidth + screenHeight
|
388
|
|
- cycleDuration = 60
|
389
|
|
- connectionDistance = Math.min(Math.round(totalScreenPixels / 16), 75)
|
390
|
|
- connectionLimit = 10
|
391
|
|
- pointShiftDistance = Math.round(totalScreenPixels / 45)
|
392
|
|
- colorShiftAmt = 80
|
393
|
|
- disconnectedColorShiftAmt = 10
|
394
|
|
- polygon = new PIXI.Graphics()
|
395
|
|
- tweeningFns = [
|
396
|
|
- linearTweening,
|
397
|
|
- easeInSine,
|
398
|
|
- easeOutSine,
|
399
|
|
- easeInOutSine,
|
400
|
|
- easeInQuad,
|
401
|
|
- easeOutQuad,
|
402
|
|
- easeInOutQuad,
|
403
|
|
- easeInCubic,
|
404
|
|
- easeOutCubic,
|
405
|
|
- easeInOutCubic
|
|
382
|
+ stage = new window.PIXI.Container();
|
|
383
|
+
|
|
384
|
+ renderer.view.style.position = 'absolute';
|
|
385
|
+ renderer.view.style.display = 'block';
|
|
386
|
+ renderer.autoResize = true;
|
|
387
|
+
|
|
388
|
+ counter = 0;
|
|
389
|
+ totalScreenPixels = screenWidth + screenHeight;
|
|
390
|
+ cycleDuration = 60;
|
|
391
|
+ connectionDistance = Math.min(Math.round(totalScreenPixels / 16), 75);
|
|
392
|
+ connectionLimit = 10;
|
|
393
|
+ pointShiftDistance = Math.round(totalScreenPixels / 45);
|
|
394
|
+ // colorShiftAmt = 80;
|
|
395
|
+ disconnectedColorShiftAmt = 10;
|
|
396
|
+ polygon = new window.PIXI.Graphics();
|
|
397
|
+ tweeningFns = [
|
|
398
|
+ linearTweening,
|
|
399
|
+ easeInSine,
|
|
400
|
+ easeOutSine,
|
|
401
|
+ easeInOutSine,
|
|
402
|
+ easeInQuad,
|
|
403
|
+ easeOutQuad,
|
|
404
|
+ easeInOutQuad,
|
|
405
|
+ easeInCubic,
|
|
406
|
+ easeOutCubic,
|
|
407
|
+ easeInOutCubic
|
406
|
408
|
// easeOutBounce,
|
407
|
409
|
// easeInElastic,
|
408
|
410
|
// easeOutElastic,
|
|
@@ -413,58 +415,58 @@ function loopStart () {
|
413
|
415
|
// easeInCirc,
|
414
|
416
|
// easeOutCirc,
|
415
|
417
|
// easeInOutCirc
|
416
|
|
- ]
|
417
|
|
- startPoints = getRandomPoints(Math.round(totalScreenPixels / 6), screenWidth, screenHeight, tweeningFns)
|
418
|
|
- polygonPoints = {
|
419
|
|
- original: startPoints,
|
420
|
|
- target: JSON.parse(JSON.stringify(startPoints)),
|
421
|
|
- tweened: JSON.parse(JSON.stringify(startPoints))
|
422
|
|
- }
|
423
|
|
- stage.addChild(polygon)
|
424
|
|
-
|
425
|
|
- fpsGraphic = new PIXI.Text('0', {font: '25px monospace', fill: 'yellow'})
|
426
|
|
- fpsGraphic.x = 0
|
427
|
|
- fpsGraphic.y = 0
|
|
418
|
+ ];
|
|
419
|
+ startPoints = getRandomPoints(Math.round(totalScreenPixels / 6), screenWidth, screenHeight, tweeningFns);
|
|
420
|
+ polygonPoints = {
|
|
421
|
+ original: startPoints,
|
|
422
|
+ target: JSON.parse(JSON.stringify(startPoints)),
|
|
423
|
+ tweened: JSON.parse(JSON.stringify(startPoints))
|
|
424
|
+ };
|
|
425
|
+ stage.addChild(polygon);
|
|
426
|
+
|
|
427
|
+ fpsGraphic = new window.PIXI.Text('0', {font: '25px monospace', fill: 'yellow'});
|
|
428
|
+ fpsGraphic.x = 0;
|
|
429
|
+ fpsGraphic.y = 0;
|
428
|
430
|
|
429
|
|
- if (fpsEnabled) {
|
430
|
|
- stage.addChild(fpsGraphic)
|
431
|
|
- }
|
|
431
|
+ if (fpsEnabled) {
|
|
432
|
+ stage.addChild(fpsGraphic);
|
|
433
|
+ }
|
432
|
434
|
|
433
|
|
- lastLoop = new Date()
|
|
435
|
+ lastLoop = new Date();
|
434
|
436
|
|
435
|
|
- scrollDelta = 0
|
|
437
|
+ scrollDelta = 0;
|
436
|
438
|
|
437
|
|
- requestAnimationFrame(loop)
|
|
439
|
+ window.requestAnimationFrame(loop);
|
438
|
440
|
}
|
439
|
441
|
|
440
|
|
-window.onload = loopStart
|
|
442
|
+window.onload = loopStart;
|
441
|
443
|
|
442
|
444
|
window.addEventListener('mousewheel', function (e) {
|
443
|
|
- scrollDelta = scrollDelta + ((e.deltaY / 100) * 3)
|
444
|
|
-})
|
|
445
|
+ scrollDelta = scrollDelta + ((e.deltaY / 100) * 3);
|
|
446
|
+});
|
445
|
447
|
|
446
|
448
|
// TODO: use jquery PEP to allow user to "pull" at a point elastically
|
447
|
449
|
// window.addEventListener('click', function(e) {
|
448
|
450
|
// });
|
449
|
451
|
|
450
|
452
|
window.addEventListener('keydown', function (e) {
|
451
|
|
- if (e.keyCode === 37) { // left
|
452
|
|
- pointShiftBiasX = -1
|
453
|
|
- } else if (e.keyCode === 38) { // up
|
454
|
|
- pointShiftBiasY = -1
|
455
|
|
- } else if (e.keyCode === 39) { // right
|
456
|
|
- pointShiftBiasX = 1
|
457
|
|
- } else if (e.keyCode === 40) { // down
|
458
|
|
- pointShiftBiasY = 1
|
459
|
|
- } else if (e.keyCode === 70) { // f
|
460
|
|
- // toggle fpsCounter
|
461
|
|
- if (fpsEnabled) {
|
462
|
|
- stage.removeChild(fpsGraphic)
|
463
|
|
- fpsEnabled = false;
|
464
|
|
- } else {
|
465
|
|
- stage.addChild(fpsGraphic)
|
466
|
|
- fpsEnabled = true;
|
467
|
|
- lastLoop = new Date();
|
|
453
|
+ if (e.keyCode === 37) { // left
|
|
454
|
+ pointShiftBiasX = -1;
|
|
455
|
+ } else if (e.keyCode === 38) { // up
|
|
456
|
+ pointShiftBiasY = -1;
|
|
457
|
+ } else if (e.keyCode === 39) { // right
|
|
458
|
+ pointShiftBiasX = 1;
|
|
459
|
+ } else if (e.keyCode === 40) { // down
|
|
460
|
+ pointShiftBiasY = 1;
|
|
461
|
+ } else if (e.keyCode === 70) { // f
|
|
462
|
+ // toggle fpsCounter
|
|
463
|
+ if (fpsEnabled) {
|
|
464
|
+ stage.removeChild(fpsGraphic);
|
|
465
|
+ fpsEnabled = false;
|
|
466
|
+ } else {
|
|
467
|
+ stage.addChild(fpsGraphic);
|
|
468
|
+ fpsEnabled = true;
|
|
469
|
+ lastLoop = new Date();
|
|
470
|
+ }
|
468
|
471
|
}
|
469
|
|
- }
|
470
|
|
-})
|
|
472
|
+});
|