Browse Source

Some cleaning up and organization, eslint

Tyler Hallada 7 years ago
parent
commit
7eac4894ed
10 changed files with 748 additions and 132 deletions
  1. 12 0
      .eslintrc.json
  2. 4 0
      .eslintrc.yml
  3. 4 0
      css/style.css
  4. 4 3
      index.html
  5. 111 0
      js/easingFunctions.js
  6. 455 0
      js/field.js
  7. 129 0
      js/tutorial.js
  8. 5 0
      notes.md
  9. 24 0
      package.json
  10. 0 129
      tutorial.js

+ 12 - 0
.eslintrc.json

@@ -0,0 +1,12 @@
1
+{
2
+  "parserOptions": {
3
+    "ecmaVersion": 6,
4
+    "sourceType": "module",
5
+    "ecmaFeatures": {
6
+      "jsx": true
7
+    }
8
+  },
9
+  "rules": {
10
+    "semi": "always"
11
+  }
12
+}

+ 4 - 0
.eslintrc.yml

@@ -0,0 +1,4 @@
1
+extends: standard
2
+plugins:
3
+  - standard
4
+  - promise

style.css → css/style.css

@@ -2,3 +2,7 @@
2 2
     padding: 0;
3 3
     margin: 0;
4 4
 }
5
+
6
+html {
7
+    overflow: hidden;
8
+}

+ 4 - 3
index.html

@@ -1,10 +1,11 @@
1 1
 <html lang="en">
2 2
     <head>
3
-        <title>Pixi.js stuff</title>
4
-        <link rel="stylesheet" href="style.css">
3
+        <title>Proximity Structures</title>
4
+        <link rel="stylesheet" href="css/style.css">
5
+        <meta name="viewport" content="width=device-width, initial-scale=1.0">
5 6
     </head>
6 7
     <body>
7 8
         <script src="https://cdnjs.cloudflare.com/ajax/libs/pixi.js/4.2.2/pixi.min.js"></script>
8
-        <script src="tutorial.js"></script>
9
+        <script src="js/field.js"></script>
9 10
     </body>
10 11
 </html>

+ 111 - 0
js/easingFunctions.js

@@ -0,0 +1,111 @@
1
+
2
+// These functions are taken from: https://github.com/danro/jquery-easing/blob/master/jquery.easing.js
3
+// (with slight modifications to the function signatures)
4
+
5
+function linearTweening (t, b, c, d) {
6
+    // t = current time
7
+    // b = start value
8
+    // c = change in value
9
+    // d = duration
10
+  return ((c * t) / d) + b
11
+}
12
+
13
+function easeOutBounce (t, b, c, d) {
14
+  if ((t /= d) < (1 / 2.75)) {
15
+    return c * (7.5625 * t * t) + b
16
+  } else if (t < (2 / 2.75)) {
17
+    return c * (7.5625 * (t -= (1.5 / 2.75)) * t + 0.75) + b
18
+  } else if (t < (2.5 / 2.75)) {
19
+    return c * (7.5625 * (t -= (2.25 / 2.75)) * t + 0.9375) + b
20
+  } else {
21
+    return c * (7.5625 * (t -= (2.625 / 2.75)) * t + 0.984375) + b
22
+  }
23
+}
24
+
25
+function easeInSine (t, b, c, d) {
26
+  return -c * Math.cos(t / d * (Math.PI / 2)) + c + b
27
+}
28
+
29
+function easeOutSine (t, b, c, d) {
30
+  return c * Math.sin(t / d * (Math.PI / 2)) + b
31
+}
32
+
33
+function easeInOutSine (t, b, c, d) {
34
+  return -c / 2 * (Math.cos(Math.PI * t / d) - 1) + b
35
+}
36
+
37
+function easeInQuad (t, b, c, d) {
38
+  return c * (t /= d) * t + b
39
+}
40
+
41
+function easeOutQuad (t, b, c, d) {
42
+  return -c * (t /= d) * (t - 2) + b
43
+}
44
+
45
+function easeInOutQuad (t, b, c, d) {
46
+  if ((t /= d / 2) < 1) return c / 2 * t * t + b
47
+  return -c / 2 * ((--t) * (t - 2) - 1) + b
48
+}
49
+
50
+function easeInCubic (t, b, c, d) {
51
+  return c * (t /= d) * t * t + b
52
+}
53
+
54
+function easeOutCubic (t, b, c, d) {
55
+  return c * ((t = t / d - 1) * t * t + 1) + b
56
+}
57
+
58
+function easeInOutCubic (t, b, c, d) {
59
+  if ((t /= d / 2) < 1) return c / 2 * t * t * t + b
60
+  return c / 2 * ((t -= 2) * t * t + 2) + b
61
+}
62
+
63
+function easeInExpo (t, b, c, d) {
64
+  return (t == 0) ? b : c * Math.pow(2, 10 * (t / d - 1)) + b
65
+}
66
+
67
+function easeOutExpo (t, b, c, d) {
68
+  return (t == d) ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b
69
+}
70
+
71
+function easeInOutExpo (t, b, c, d) {
72
+  if (t == 0) return b
73
+  if (t == d) return b + c
74
+  if ((t /= d / 2) < 1) return c / 2 * Math.pow(2, 10 * (t - 1)) + b
75
+  return c / 2 * (-Math.pow(2, -10 * --t) + 2) + b
76
+}
77
+
78
+function easeInElastic (t, b, c, d) {
79
+  var s = 1.70158; var p = 0; var a = c
80
+  if (t == 0) return b; if ((t /= d) == 1) return b + c; if (!p) p = d * 0.3
81
+  if (a < Math.abs(c)) { a = c; var s = p / 4 }	else var s = p / (2 * Math.PI) * Math.asin(c / a)
82
+  return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b
83
+}
84
+
85
+function easeOutElastic (t, b, c, d) {
86
+  var s = 1.70158; var p = 0; var a = c
87
+  if (t == 0) return b; if ((t /= d) == 1) return b + c; if (!p) p = d * 0.3
88
+  if (a < Math.abs(c)) { a = c; var s = p / 4 }	else var s = p / (2 * Math.PI) * Math.asin(c / a)
89
+  return a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + c + b
90
+}
91
+
92
+function easeInOutElastic (t, b, c, d) {
93
+  var s = 1.70158; var p = 0; var a = c
94
+  if (t == 0) return b; if ((t /= d / 2) == 2) return b + c; if (!p) p = d * (0.3 * 1.5)
95
+  if (a < Math.abs(c)) { a = c; var s = p / 4 }	else var s = p / (2 * Math.PI) * Math.asin(c / a)
96
+  if (t < 1) return -0.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b
97
+  return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p) * 0.5 + c + b
98
+}
99
+
100
+function easeInCirc (t, b, c, d) {
101
+  return -c * (Math.sqrt(1 - (t /= d) * t) - 1) + b
102
+}
103
+
104
+function easeOutCirc (t, b, c, d) {
105
+  return c * Math.sqrt(1 - (t = t / d - 1) * t) + b
106
+}
107
+
108
+function easeInOutCirc (t, b, c, d) {
109
+  if ((t /= d / 2) < 1) return -c / 2 * (Math.sqrt(1 - t * t) - 1) + b
110
+  return c / 2 * (Math.sqrt(1 - (t -= 2) * t) + 1) + b
111
+}

+ 455 - 0
js/field.js

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

+ 129 - 0
js/tutorial.js

@@ -0,0 +1,129 @@
1
+// Create the renderer
2
+var renderer = PIXI.autoDetectRenderer(256, 256, {antialias: true})
3
+
4
+// Add the canvas to the HTML document
5
+document.body.appendChild(renderer.view)
6
+
7
+// Create a container object called the `stage`
8
+var stage = new PIXI.Container()
9
+
10
+renderer.view.style.position = 'absolute'
11
+renderer.view.style.display = 'block'
12
+renderer.autoResize = true
13
+renderer.resize(window.innerWidth, window.innerHeight)
14
+
15
+var counter = 0,
16
+  cycleDuration = 60,
17
+  tri = {
18
+    original: [
19
+            [0, 0],
20
+            [-50, 50],
21
+            [50, 50]
22
+    ],
23
+    target: [
24
+            [0, 0],
25
+            [-50, 50],
26
+            [50, 50]
27
+    ]
28
+  },
29
+  triangle = new PIXI.Graphics()
30
+
31
+stage.addChild(triangle)
32
+
33
+function randomInt (min, max) {
34
+  return Math.floor(Math.random() * (max - min + 1)) + min
35
+}
36
+
37
+function linearTweening (t, b, c, d) {
38
+    // t = current time
39
+    // b = start value
40
+    // c = change in value
41
+    // d = duration
42
+  return ((c * t) / d) + b
43
+}
44
+
45
+function easeOutBounce (t, b, c, d) {
46
+  if ((t /= d) < (1 / 2.75)) {
47
+    return c * (7.5625 * t * t) + b
48
+  } else if (t < (2 / 2.75)) {
49
+    return c * (7.5625 * (t -= (1.5 / 2.75)) * t + 0.75) + b
50
+  } else if (t < (2.5 / 2.75)) {
51
+    return c * (7.5625 * (t -= (2.25 / 2.75)) * t + 0.9375) + b
52
+  } else {
53
+    return c * (7.5625 * (t -= (2.625 / 2.75)) * t + 0.984375) + b
54
+  }
55
+}
56
+
57
+function easeInOutExpo (t, b, c, d) {
58
+  if (t == 0) return b
59
+  if (t == d) return b + c
60
+  if ((t /= d / 2) < 1) return c / 2 * Math.pow(2, 10 * (t - 1)) + b
61
+  return c / 2 * (-Math.pow(2, -10 * --t) + 2) + b
62
+}
63
+
64
+function drawLine (x1, y1, x2, y2) {
65
+  var line = new PIXI.Graphics()
66
+  line.lineStyle(1, 0xFFFFFF, 1)
67
+  line.moveTo(x1, y1)
68
+  line.lineTo(x2, y2)
69
+  line.x = x1
70
+  line.y = y1
71
+  stage.addChild(line)
72
+}
73
+
74
+function drawShiftingTriangle (triangle, originalPoints, targetPoints, counter, easingFn) {
75
+  var i = 0
76
+  if (counter === 0) {
77
+        // Given originalPoints, randomly shifts them by some amount, draws it, and returns new array of points
78
+    var newPoints = []
79
+        // Start new cycle. New original is old target. New target is newly generated newPoints.
80
+    originalPoints = targetPoints
81
+
82
+    for (i = 0; i < originalPoints.length; i++) {
83
+      newPoints[i] = [originalPoints[i][0] + randomInt(-10, 10),
84
+        originalPoints[i][1] + randomInt(-10, 10)]
85
+    }
86
+    targetPoints = newPoints
87
+  }
88
+  triangle.lineStyle(1, 0xFAFAFA, 1)
89
+    // triangle.beginFill(0x66FF33);
90
+  for (i = 0; i < 4; i++) {
91
+    if (i === 0) {
92
+      triangle.moveTo(easingFn(counter, originalPoints[0][0], targetPoints[0][0] - originalPoints[0][0], cycleDuration),
93
+                            easingFn(counter, originalPoints[0][1], targetPoints[0][1] - originalPoints[0][1], cycleDuration))
94
+    } else if (i === 3) {
95
+      triangle.lineTo(easingFn(counter, originalPoints[0][0], targetPoints[0][0] - originalPoints[0][0], cycleDuration),
96
+                            easingFn(counter, originalPoints[0][1], targetPoints[0][1] - originalPoints[0][1], cycleDuration))
97
+    } else {
98
+      triangle.lineTo(easingFn(counter, originalPoints[i][0], targetPoints[i][0] - originalPoints[i][0], cycleDuration),
99
+                            easingFn(counter, originalPoints[i][1], targetPoints[i][1] - originalPoints[i][1], cycleDuration))
100
+    }
101
+  }
102
+    // triangle.endFill();
103
+
104
+  return {
105
+    original: originalPoints,
106
+    target: targetPoints
107
+  }
108
+}
109
+
110
+function loop () {
111
+  requestAnimationFrame(loop)
112
+
113
+  triangle.clear()
114
+
115
+    // drawLine(0, 0, counter, counter);
116
+  tri = drawShiftingTriangle(triangle, tri.original, tri.target, counter, linearTweening)
117
+
118
+  counter += 1
119
+  counter = counter % cycleDuration
120
+
121
+  var mousePosition = renderer.plugins.interaction.mouse.global
122
+  triangle.x = mousePosition.x
123
+  triangle.y = mousePosition.y
124
+
125
+    // Tell the `renderer` to `render` the `stage`
126
+  renderer.render(stage)
127
+}
128
+
129
+loop()

+ 5 - 0
notes.md

@@ -0,0 +1,5 @@
1
+Space the dots out more. Don't let them get close.
2
+
3
+Rotate the dots around the page in a circular pattern.
4
+
5
+

+ 24 - 0
package.json

@@ -0,0 +1,24 @@
1
+{
2
+  "name": "proximity-structures",
3
+  "version": "1.0.0",
4
+  "description": "",
5
+  "main": "index.js",
6
+  "scripts": {
7
+    "eslint": "eslint",
8
+    "test": "echo \"Error: no test specified\" && exit 1"
9
+  },
10
+  "repository": {
11
+    "type": "git",
12
+    "url": "git@git.hallada.net:pixi.git"
13
+  },
14
+  "author": "Tyler Hallada",
15
+  "license": "ISC",
16
+  "devDependencies": {
17
+    "eslint": "^3.17.0",
18
+    "eslint-config-airbnb-base": "^11.1.1",
19
+    "eslint-config-standard": "^7.0.0",
20
+    "eslint-plugin-import": "^2.2.0",
21
+    "eslint-plugin-promise": "^3.5.0",
22
+    "eslint-plugin-standard": "^2.1.1"
23
+  }
24
+}

+ 0 - 129
tutorial.js

@@ -1,129 +0,0 @@
1
-//Create the renderer
2
-var renderer = PIXI.autoDetectRenderer(256, 256, {antialias: true});
3
-
4
-//Add the canvas to the HTML document
5
-document.body.appendChild(renderer.view);
6
-
7
-//Create a container object called the `stage`
8
-var stage = new PIXI.Container();
9
-
10
-renderer.view.style.position = "absolute";
11
-renderer.view.style.display = "block";
12
-renderer.autoResize = true;
13
-renderer.resize(window.innerWidth, window.innerHeight);
14
-
15
-var counter = 0,
16
-    cycleDuration = 60,
17
-    tri = {
18
-        original: [
19
-            [0, 0],
20
-            [-50, 50],
21
-            [50, 50]
22
-        ],
23
-        target: [
24
-            [0, 0],
25
-            [-50, 50],
26
-            [50, 50]
27
-        ]
28
-    },
29
-    triangle = new PIXI.Graphics();
30
-
31
-stage.addChild(triangle);
32
-
33
-function randomInt(min, max) {
34
-  return Math.floor(Math.random() * (max - min + 1)) + min;
35
-}
36
-
37
-function linearTweening(t, b, c, d) {
38
-    // t = current time
39
-    // b = start value
40
-    // c = change in value
41
-    // d = duration
42
-    return ((c * t) / d) + b;
43
-}
44
-
45
-function easeOutBounce(t, b, c, d) {
46
-	if ((t/=d) < (1/2.75)) {
47
-		return c*(7.5625*t*t) + b;
48
-	} else if (t < (2/2.75)) {
49
-		return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
50
-	} else if (t < (2.5/2.75)) {
51
-		return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
52
-	} else {
53
-		return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
54
-	}
55
-}
56
-
57
-function easeInOutExpo(t, b, c, d) {
58
-	if (t==0) return b;
59
-	if (t==d) return b+c;
60
-	if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
61
-	return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
62
-}
63
-
64
-function drawLine(x1, y1, x2, y2) {
65
-    var line = new PIXI.Graphics();
66
-    line.lineStyle(1, 0xFFFFFF, 1);
67
-    line.moveTo(x1, y1);
68
-    line.lineTo(x2, y2);
69
-    line.x = x1;
70
-    line.y = y1;
71
-    stage.addChild(line);
72
-}
73
-
74
-function drawShiftingTriangle(triangle, originalPoints, targetPoints, counter, easingFn) {
75
-    var i = 0;
76
-    if (counter === 0) {
77
-        // Given originalPoints, randomly shifts them by some amount, draws it, and returns new array of points
78
-        var newPoints = [];
79
-        // Start new cycle. New original is old target. New target is newly generated newPoints.
80
-        originalPoints = targetPoints;
81
-
82
-        for (i = 0; i < originalPoints.length; i++) {
83
-            newPoints[i] = [originalPoints[i][0] + randomInt(-10, 10),
84
-                            originalPoints[i][1] + randomInt(-10, 10)];
85
-        }
86
-        targetPoints = newPoints;
87
-    }
88
-    triangle.lineStyle(1, 0xFAFAFA, 1);
89
-    // triangle.beginFill(0x66FF33);
90
-    for (i = 0; i < 4; i++) {
91
-        if (i === 0) {
92
-            triangle.moveTo(easingFn(counter, originalPoints[0][0], targetPoints[0][0] - originalPoints[0][0], cycleDuration),
93
-                            easingFn(counter, originalPoints[0][1], targetPoints[0][1] - originalPoints[0][1], cycleDuration));
94
-        } else if (i === 3) {
95
-            triangle.lineTo(easingFn(counter, originalPoints[0][0], targetPoints[0][0] - originalPoints[0][0], cycleDuration),
96
-                            easingFn(counter, originalPoints[0][1], targetPoints[0][1] - originalPoints[0][1], cycleDuration));
97
-        } else {
98
-            triangle.lineTo(easingFn(counter, originalPoints[i][0], targetPoints[i][0] - originalPoints[i][0], cycleDuration),
99
-                            easingFn(counter, originalPoints[i][1], targetPoints[i][1] - originalPoints[i][1], cycleDuration));
100
-        }
101
-    }
102
-    // triangle.endFill();
103
-    
104
-    return {
105
-        original: originalPoints,
106
-        target: targetPoints
107
-    };
108
-}
109
-
110
-function loop(){
111
-    requestAnimationFrame(loop);
112
-
113
-    triangle.clear();
114
-
115
-    // drawLine(0, 0, counter, counter);
116
-    tri = drawShiftingTriangle(triangle, tri.original, tri.target, counter, linearTweening);
117
-
118
-    counter += 1;
119
-    counter = counter % cycleDuration;
120
-
121
-    var mousePosition = renderer.plugins.interaction.mouse.global;
122
-    triangle.x = mousePosition.x;
123
-    triangle.y = mousePosition.y;
124
-
125
-    //Tell the `renderer` to `render` the `stage`
126
-    renderer.render(stage);
127
-}
128
-
129
-loop();