-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsketch.js
331 lines (314 loc) · 9.87 KB
/
sketch.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
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
p5.disableFriendlyErrors = true;
document.addEventListener('touchmove', function (n) {
n.preventDefault();
}, {
passive: false
});
document.addEventListener('dblclick', () => {
nuit = !nuit
}, {
passive: false
});
let tapedTwice = false;
function Dclick(event) {
if (!tapedTwice) {
tapedTwice = true;
setTimeout(function () {
tapedTwice = false;
}, 300);
return false;
}
event.preventDefault();
}
let ee = 0;
let state = -1;
let doubleClick, ts = [];
let mic, osc, filt;
let locss = [];
let cityA = [],
placeA = [];
let cityArray = [];
let placeArray = [];
let img, font;
let mouseP = [];
let nuit = true;
let predict = [];
let locs;
let [m, n] = [
[],
[]
];
let stage = -1;
backgroundColor = [255, 255, 255, 100];
cityHabitText = [255, 255, 20, 50];
// text habit city
cityTextFill = [255, 255, 0, 100];
// circles habit city
cityHabitFill = [100, 0, 0, 10];
parcoursCirclesFill = [0, 0, 110, 50];
rightTextBlue = [0, 0, 150, 80];
rightTextRed = [150, 0, 0, 100];
cityHighlight = rightTextRed;
city = [0, 0, 180, 20];
parcoursStroke = [200, 200, 20, 80];
parcoursFill = [130, 10, 10, 180];
innerCercleS = [50, 0, 100, 80];
navBar = [30, 50, 150, 100];
function preload() {
table = loadTable("assets/e5.csv", "csv", "header");
// font = loadFont('assets/SpaceMono-Regular.ttf');
// font = loadFont('assets/iosevka-regular.ttf')
font = loadFont('assets/AndaleMono.ttf');
sound = loadSound("assets/click.m4a");
}
function setup() {
// pixelDensity() > 2.0 ? pixelDensity(2.0) : "";
pixelDensity(2.0);
masterVolume(0.2)
textFont(font);
// noCursor();
sound.play();
// get information from tables
for (let e = 0; e < 210; e++) {
let m = split(table.getString(e, 1), ",");
let str = split(table.getString(e, 5), ",")[0];
str = str.split(":")[0];
let point = {
n: split(table.getString(e, 0), ","),
x: split(table.getString(e, 1), ","),
y: split(table.getString(e, 2), ","),
place: split(table.getString(e, 3), ",")[0],
city: split(table.getString(e, 6), ",")[0],
date: split(table.getString(e, 4), ","),
time: split(table.getString(e, 5), ","),
hour: str,
size: Math.random() * 20
}
locss.push(point);
let mm = point.city;
let nn = point.place;
// city & place names without duplites
cityA.indexOf(mm) === -1 ? cityA.push(mm) : "";
placeA.indexOf(nn) === -1 ? placeA.push(nn) : "";
}
createCanvas(windowWidth, windowHeight);
// calculate data x-y range
let [minx, maxx, miny, maxy] = [Infinity, -Infinity, Infinity, -Infinity];
locss.forEach(point => {
point.x > maxx ? maxx = point.x : ""
point.y > maxy ? maxy = point.y : ""
point.y < miny ? miny = point.y : ""
point.x < minx ? minx = point.x : ""
})
// MAP TO SCREEN
if (height > width) {
locss.map(point => {
point.x = map(point.x, minx, maxx, width * 0.9 - 50, width * 0.1 + 100);
point.y = map(point.y, miny, maxy, height * 0.3, height * 0.91);
})
} else {
locss.map(point => {
point.x = map(point.x, minx, maxx, width * 0.9 - 100, width * 0.1 + 100);
point.y = map(point.y, miny, maxy, height * 0.23 + 50, height * 0.9 - 50);
})
}
locs = locss.slice(0, 1);
for (let i = 0; i < cityA.length; i++) {
cityArray[i] = locs.filter(obj => obj.city === cityA[i]);
}
for (let i = 0; i < placeA.length; i++) {
placeArray[i] = locs.filter(obj => obj.place === placeA[i]);
}
// 3rd arrays with items sorted by frequency
m = [...cityArray];
m = m.sort((a, b) => (b.length - a.length));
n = [...placeArray];
n = n.sort((a, b) => (b.length - a.length));
//fake predict
// for(let i =0;i<locss.length;i++){
// let t = {
// x:locss[i].x+random(-1,1)*(locss.length-i),
// y:locss[i].x+random(-1,1)*(locss.length-i)
// }
// predict.push(t);
// }
// mouseY = height;
// mouseX = 0;
}
function sizeT(n) {
let tSmall = 15;
let tMid = 30;
let tInt = 40;
let scl = 1.2;
if (n === 0) {
if (height > width) {
return tSmall * scl;
}
return tSmall;
}
if (n === 1) {
if (height > width) {
return tMid * scl;
}
return tMid;
}
if (n === -1) {
if (height > width) {
return tInt * scl;
}
return tInt;
}
if (n === -2) {
if (height > width) {
return tInt / 1.5;
}
return tInt / 1.5;
}
}
function draw() {
// splice array, create cityArray&placeArray
barLimit() ? stage = 0 : "";
locs = (abs(mouseX - pmouseX) > 0 || abs(mouseY - pmouseY) > 0) && (stage === 0) && barLimit() ? Choose(locss) : locs;
if ((abs(mouseX - pmouseX) > 0 || abs(mouseY - pmouseY) > 0) && (stage === 0) && barLimit()) {
// 2nd arrays with frequency
for (let i = 0; i < cityA.length; i++) {
cityArray[i] = locs.filter(obj => obj.city === cityA[i]);
}
for (let i = 0; i < placeA.length; i++) {
placeArray[i] = locs.filter(obj => obj.place === placeA[i]);
}
// 3rd arrays with items sorted by frequency
m = [...cityArray];
m = m.sort((a, b) => (b.length - a.length));
n = [...placeArray];
n = n.sort((a, b) => (b.length - a.length));
}
scolor(nuit);
background(backgroundColor);
// Texts
// info text Right
if (locs) {
const top = sizeT(-1) * 1.5;
const left = width - sizeT(-1) * 0.7;
push();
strokeWeight(0);
textAlign(RIGHT);
textSize(sizeT(1) * 1.5);
fill(rightTextBlue);
text("Where's Jane Joe", left, top);
textSize(sizeT(0) * 1.5);
fill(rightTextRed);
text("From 03/07/19 to 23/07/19", left, top + sizeT(-1));
pop();
}
// Time & Left Citys
let t = () => {
push();
textSize(sizeT(1));
noStroke();
fill(rightTextRed[0], rightTextRed[1], rightTextRed[2], (Math.sin(frameCount / 20) + 0.5) * 80);
fill(100);
// textAlign(CENTER)
if (width > height) {
text(">>> Drag here to begin >>>", 60, height - 20);
} else {
translate(width, height);
rotate(-PI / 2);
text(">>> Drag here to begin", 60, -20);
}
pop();
}
// LINES, CIRCLES
beginShape();
fill(0, 0);
// color stroke
// dynamic
nuit ? stroke(parcoursStroke[0], parcoursStroke[1] + Math.random() * 200, parcoursStroke[2], parcoursStroke[3]) : stroke(parcoursStroke[0], parcoursStroke[1] - Math.random() * 200, parcoursStroke[2], parcoursStroke[3]);
let x = 0;
let y = 0;
for (let i = 0; i < locs.length; i++) {
vertex(locs[i].x, locs[i].y);
// get No. of this city
let d = cityA.indexOf(locs[i].city);
// draw parcours points
push();
noStroke();
// color blue parcours circles
nuit ? fill(parcoursCirclesFill[0], parcoursCirclesFill[1], parcoursCirclesFill[2] - Math.random() * 10, parcoursCirclesFill[3]) : fill(parcoursCirclesFill[0], parcoursCirclesFill[1], parcoursCirclesFill[2] + Math.random() * 10, parcoursCirclesFill[3]);
ellipse(locs[i].x, locs[i].y, 10 + Math.random() * 10 + locs[i].size);
textSize(sizeT(0) + Math.random() / 2);
textAlign(CENTER);
// Draw frequented cities
if (cityArray[d].length > 4) {
fill(cityHabitFill);
let r = constrain(cityArray[d].length * 8, 0, 300) + random(-10, 10) * cityArray[d].length / 1.3;
if (cityArray[d].length > 30) {
fill(cityHabitFill[0], cityHabitFill[1], cityHabitFill[2], cityHabitFill[3] / 5);
r = constrain(cityArray[d].length * 8, 0, 300) + random(-10, 10) * cityArray[d].length / 4;
}
ellipse(cityArray[d][0].x, cityArray[d][0].y, r);
// invert
nuit ? fill(cityHabitText[0] + cityArray[d].length * 1, cityHabitText[1] + cityArray[d].length * 5, cityHabitText[2], cityHabitText[3]) : fill(cityHabitText[0] + cityArray[d].length * 1, cityHabitText[1] + cityArray[d].length * 5, cityHabitText[2], cityHabitText[3]);
textSize(locs.length > 1 ? constrain(cityArray[d].length * 1.8, 10, 45) : 0);
cityArray[d][0].y > height / 2 ? text(locs[i].city + " ", cityArray[d][0].x, cityArray[d][0].y - cityArray[d].length) : text(locs[i].city + " ", cityArray[d][0].x, cityArray[d][0].y + cityArray[d].length * 4 + Math.random() * 2);
}
pop();
push();
nuit ? stroke(innerCercleS[0], innerCercleS[1] - Math.random() * 155, innerCercleS[2], innerCercleS[3]) : stroke(innerCercleS[0], innerCercleS[1] + Math.random() * 155, innerCercleS[2], innerCercleS[3]);
ellipse(locs[i].x, locs[i].y, 10 + Math.random() * 5);
pop();
}
endShape();
push();
// on Circle text
fill(locs.length > 1 ? [...parcoursStroke].slice(0, 3).concat(195) : [0, 0]);
textAlign(CENTER);
ellipse(locs[locs.length - 1].x, locs[locs.length - 1].y, 70 - Math.random() * 25);
fill(locs.length > 1 ? parcoursFill : (0, 0));
noStroke();
textSize(sizeT(0) * 1.2);
text(locs[locs.length - 1].place, locs[locs.length - 1].x, locs[locs.length - 1].y + sizeT(-1) * 1.5);
pop();
// bar de navigation
bar(locs, locss);
stageControl();
stage != -1 ? texts() : t();
}
const Choose = (array) => {
let e = Math.floor(constrain(map(mouseX, 0, width, 0, array.length), 0, array.length)) + 1;
if (height > width) {
e = Math.floor(constrain(map(height - mouseY, 0, height, 0, array.length), 0, array.length)) + 1;
}
if (ee != e) {
sound.rate(1 + Math.random() / 100);
sound.play();
ee = e;
}
if (e < 2) {
stage = -1;
}
return array.slice(0, e);
}
const bar = (a1, a2) => {
let long = constrain(a1.length / a2.length, 0.02, 0.995);
if (height > width) {
push();
stroke(0, 0);
fill(navBar);
rect(width - 15, height - long * height, 15, long * height);
fill(rightTextRed[0], rightTextRed[1], rightTextRed[2], 150 - Math.random() * 50);
rect(width - 25, (1 - long) * height - 10, 40, 10);
pop();
} else {
push();
stroke(0, 0);
fill(navBar);
rect(0, height - 20, long * width, 15);
fill(rightTextRed[0], rightTextRed[1], rightTextRed[2], 150 - Math.random() * 50);
rect(long * width, height - 25, 10, 40);
pop();
}
}
document.touchmove = function (n) {
n.preventDefault();
}