-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsketchRandomLoop.js
More file actions
308 lines (217 loc) · 9.23 KB
/
Copy pathsketchRandomLoop.js
File metadata and controls
308 lines (217 loc) · 9.23 KB
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
// Objectif
// Given the following CSV file called "numbers.csv"
// located in the project's root folder:
//
// words,count
//example:
//algorithm,12
let tableTwitter;
let tableYT;
let t0 = 0;
// time delay vars
// current time "snapshot" (imagine pressing the lap time button)
//var time;
// the interval to wait between time "snapshots": 2s (2000 milliseconds) in this case
//var wait = 2000;
//var RobotoMono;
const params = {
random_and_noise_Seed: 2,
}
function preload(){
//my table is comma separated value "csv"
//and has a header specifying the columns labels
tableTwitter = loadTable('twitter.csv', 'csv', 'header');
tableFacebook = loadTable('facebook.csv', 'csv', 'header');
tableYT = loadTable('youtube.csv', 'csv', 'header');
Montserrat = loadFont('Montserrat-Bold.ttf');
MontserratReg = loadFont('Montserrat-Regular.ttf');
}
function setup(){
frameRate(10);
createCanvas(960, 640); // Create SVG Canvas // , SVG
//count the columns
print(tableTwitter.getRowCount() + ' total rows in table');
print(tableTwitter.getColumnCount() + ' total columns in table');
wordsTwitter = tableTwitter.getColumn('words')
countTwitter = tableTwitter.getColumn('count')
wordsYT = tableYT.getColumn('words')
countYT = tableYT.getColumn('count')
wordsFacebook = tableFacebook.getColumn('words')
countFacebook = tableFacebook.getColumn('count')
print("tyoe of tableTwitter is ")
//console.log(typeof tableTwitter);
print(typeof tableTwitter);
//print(countTwitter);
//print(countFacebook);
//["12", "12", "4", etc.]
// Initialisation des fonctions d'aléatoire
randomSeed(params.random_and_noise_Seed)
//noiseSeed(params.random_and_noise_Seed)
//store the current time
//time = millis();
}
function map(number, inMin, inMax, outMin, outMax) {
return (number - inMin) * (outMax - outMin) / (inMax - inMin) + outMin;
}
// Get max count from each social media:
function getMaxOccurrencesFromTableCount(countRS){
//let maxCount = 0;
for(let i=0; i<countRS.length; i++){
if(countRS[i] != undefined){
return countRS[i];
}
}
//return maxCount
}
function getMaxOccurrencesFromTableCount_v2(countRS){
return countRS[0]
}
// Get min count from each social media:
function getMinOccurrencesFromTableCount(countRS){
let minCount = 1; // Attention bricolage par ici (le 1 est arbirtraire)
for(let i=0; i<countRS.length; i++){
if(countRS[i] < minCount){
minCount = countRS[i];
}
}
return minCount
}
function getMinOccurrencesFromTableCount_v2(countRS){
return countRS[countRS.length - 1]
}
// Création d'une table des mots communs aux RS
function createCommonTable(table1, table2){
wordsTable1 = table1.getColumn('words')
countTable1 = table1.getColumn('count')
wordsTable2 = table2.getColumn('words')
countTable2 = table2.getColumn('count')
var table3 = {
words: [],
count: []
};
for(let t1=0; t1<countTable1.length; t1++){
for(let t2=0; t2<countTable2.length; t2++){
if(wordsTable1[t1] == wordsTable2[t2]){
table3.words[t1] = wordsTable1[t1];
table3.count[t1] = (countTable1[t1]); // + countTable2[t2])/2 à la fin bugge (on obtient trop grd count résultant)
}
}
}
return table3;
}
function removeCommonElementsInTable(table1, table2){
wordsTable1 = table1.getColumn('words')
countTable1 = table1.getColumn('count')
wordsTable2 = table2.getColumn('words')
countTable2 = table2.getColumn('count')
var table3 = {
words: [],
count: []
};
// Copie de table1 dans table3
for(let t3=0; t3<countTable1.length; t3++){
table3.words[t3] = wordsTable1[t3];
table3.count[t3] = countTable1[t3];
}
// Retrait des elts communs à table3 (càd table1) et table2
for(let t1=0; t1<countTable1.length; t1++){
for(let t2=0; t2<countTable2.length; t2++){
if(table3.words[t1] == wordsTable2[t2]){
table3.words[t1] = undefined;
table3.count[t1] = undefined;
}
}
}
return table3;
}
function delay(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
// -------- Drawing -------
function draw(){
random(params.random_and_noise_Seed)
t0 += 3;
background(28, 28, 28);
noStroke();
fill(51, 255, 0, 50);
let colorShift = 20;
//------------ Tracé du nuage correspondant aux mots Twitter----------------------
tableTwitterWithoutFb = removeCommonElementsInTable(tableTwitter, tableFacebook);
wordsTwitterWithoutFb = tableTwitterWithoutFb.words;
countTwitterWithoutFb = tableTwitterWithoutFb.count;
/*
print("test table TwitterWithoutFb : "); // DEBUG
print(tableTwitterWithoutFb);
print("test max occurence v1 de table TwitterWithoutFb : ")
print(getMaxOccurrencesFromTableCount(countTwitterWithoutFb))
*/
textFont(Montserrat);
for (let t = 0; t < countTwitterWithoutFb.length; t++){
if(wordsTwitterWithoutFb[t] != undefined && t<t0){ //&& millis() - time >= wait
tailleTxt = map(countTwitterWithoutFb[t], getMinOccurrencesFromTableCount_v2(countTwitterWithoutFb), getMaxOccurrencesFromTableCount(countTwitterWithoutFb), 8, width/8)
textSize(tailleTxt); // count[t] // Math.exp(count[t])
fill(random(56 - colorShift, 56 + colorShift), random(161 - colorShift, 161 + colorShift), random(243 - colorShift, 243 + colorShift), map(tailleTxt, 12, width/8, 255, 50))
text(wordsTwitterWithoutFb[t], random(0, width - 650), random(60, height/2));
//time = millis();
}
}
// --------------------Tracé du nuage correspondant aux mots FB------------------
tableFbWithoutTwitter = removeCommonElementsInTable(tableFacebook, tableTwitter);
wordsFbWithoutTwitter = tableFbWithoutTwitter.words;
countFbWithoutTwitter = tableFbWithoutTwitter.count;
//print("test table Fb sans twitter : "); // DEBUG
//print(tableFbWithoutTwitter);
for (let t = 0; t < countFbWithoutTwitter.length; t++){
if(wordsFbWithoutTwitter[t] != undefined && t<t0){
tailleTxt = map(countFbWithoutTwitter[t], getMinOccurrencesFromTableCount_v2(countFbWithoutTwitter), getMaxOccurrencesFromTableCount(countFbWithoutTwitter), 8, width/8)
textSize(tailleTxt); // count[t] // Math.exp(count[t])
fill(random(46,86), random(83,123), random(158,198), map(tailleTxt, 12, width/8, 255, 50))
text(wordsFbWithoutTwitter[t], random(width/2, width - 200), random(60, height/2));
}
}
// -----------------Tracé du nuage correspondant aux mots table commune-------------------
tableCommune = createCommonTable(tableTwitter, tableFacebook);
wordsCommune = tableCommune.words;
countCommune = tableCommune.count;
print("test table commune : ");
print(tableCommune); // MARCHE
//print("test 1er mot de table commune : ");
//print(wordsCommune.words[0]);
//cycle through the table to print the table DEBUG
for (let r = 0; r < countCommune.length; r++){
for (let c = 0; c < 2; c++){ // 2 colonnes dans la table
print(tableCommune.words[r]);
print(tableCommune.count[r]);
}
}
let tailleTexteFixe = 14;
for (let t = 0; t < tableCommune.count.length; t++){
if(wordsCommune[t] != undefined && t<t0){
tailleTxt = map(countCommune[t], getMinOccurrencesFromTableCount_v2(countCommune), getMaxOccurrencesFromTableCount(countCommune), 8, width/8)
textSize(tailleTxt); // count[t] // Math.exp(count[t])
fill(random(189 - colorShift, 189 + colorShift), random(55 - colorShift, 55 + colorShift), random(55 - colorShift, 55 + colorShift), map(tailleTxt, 12, width/8, 255, 50))
text(wordsCommune[t], random(width/8 - 20, 7*width/8), random(height/2 + 60, height - 90));
}
}
// ---------- LEGENDE ------------
textSize(11);
textAlign(CENTER);
fill(240,240,240);
text("Nuages de mots mettant en avant les termes les plus tweetés au sujet des algorithmes de Twitter et de Facebook (source : API Twitter)", width/2, height - 20);
textFont(MontserratReg);
textAlign(LEFT);
fill(56,161,243);
text("Termes spécifiques aux tweets discutant de l'algorithme de Twitter", 10, height - 69);
fill(66,103,178);
text("Termes spécifiques aux tweets discutant de l'algorithme de Facebook", 10, height - 57);
fill(189,55,55);
text("Termes communs aux tweets discutant de ces deux algorithmes", 10, height - 45);
//save("mySVG.svg"); // give file name
//print("saved svg");
//noLoop(); // we just want to export once
// wait 2s then call draw() manually
//delay(2000).then(draw);
if(t0 >= max(countTwitterWithoutFb.length, countFbWithoutTwitter.length, countCommune.length)){
noLoop();
}
}