@@ -19,6 +19,7 @@ If you want to know more about the course visit [this website](https://drawwithc
19
19
* [ Federico Pozzi] ( https://federicopozzi.github.io/portfolio/index.html )
20
20
21
21
### Table of Contents
22
+ 0 . [ How to run] ( #how-to-run )
22
23
1 . [ Concept] ( #concept )
23
24
* Project idea
24
25
* Communication aim
@@ -36,6 +37,13 @@ If you want to know more about the course visit [this website](https://drawwithc
36
37
* ES6 features
37
38
4 . [ Credits] ( #credits )
38
39
40
+ ## How to run
41
+
42
+ Be sure to have [ node and npm] ( https://nodejs.org/ ) installed.
43
+
44
+ * Install node dependencies: ` npm install `
45
+ * Run local server: ` node server.js `
46
+
39
47
## Concept
40
48
41
49
### Project idea
@@ -116,7 +124,8 @@ class Player {
116
124
}
117
125
```
118
126
119
- We gave shape to the landmarks by connecting them with a stroke.
127
+ We gave shape to the landmarks by connecting them with a stroke.
128
+ We used the same function to avoid code repetitions.
120
129
121
130
``` js
122
131
const col = palette[this .feeling ];
@@ -145,8 +154,8 @@ function onPlayerLeft(id) {
145
154
}
146
155
```
147
156
148
- Detect performs facial recognition.
149
-
157
+ Face detection is triggered through ` detectFace() ` function. It runs recursively, with a little
158
+ delay in some cases to avoid client overload.
150
159
``` js
151
160
async function detectFace () {
152
161
if (! me) {
@@ -159,13 +168,16 @@ async function detectFace() {
159
168
160
169
detection = await faceapi .detectSingleFace (video .elt ,
161
170
detectionOptions).withFaceLandmarks ().withFaceExpressions ();
171
+ }
162
172
```
163
173
164
174
If face-api.js finds a face but has a degree of certainty lower than the threshold value, detection starts again.
175
+ When the detection runs correctly, the result is assigned to detection (which actually is a ` setter ` function) of ` me ` .
176
+ After that, other players connected are updated through socket.
165
177
166
178
``` js
167
- if (detection) {
168
- const threshold = .8 ;
179
+ if (detection) {
180
+ const threshold = .9 ;
169
181
170
182
const score = detection .detection ._score ;
171
183
@@ -177,7 +189,7 @@ If face-api.js finds a face but has a degree of certainty lower than the thresho
177
189
me .detection = detection;
178
190
179
191
me .broadcast ();
180
-
192
+ }
181
193
```
182
194
183
195
Initially, face-api recognised many expressions as neutral. We therefore tried to ** decrease the neutrals** , favouring
@@ -196,9 +208,9 @@ for (const feeling of feelings) {
196
208
197
209
#### Position of the avatar
198
210
199
- The position of the avatar is calculated by the browser of each user, making the site faster. The position is calculated
200
- on the basis of gravity points
201
- that [apply forces to points ](https://www.youtube.com/watch?v=MkXoQVWRDJs&ab_channel=TheCodingTrain) with the same
211
+ The position of the avatar is calculated by the browser of each user, making the site faster and avoiding lagging.
212
+ The position is calculated on the basis of gravity points
213
+ that [ apply forces to players ] ( https://www.youtube.com/watch?v=MkXoQVWRDJs&ab_channel=TheCodingTrain ) with the same
202
214
feeling.
203
215
204
216
This class generates the ** centres of gravity** of the emotions.
@@ -245,13 +257,14 @@ class GravityPoint {
245
257
text (this .feeling .toUpperCase (), this .pos .x , this .pos .y + 20 );
246
258
pop ();
247
259
}
260
+ }
248
261
```
249
262
250
- Set the position of the **centre of gravity**.
263
+ The position of the ** centre of gravity** are created in this class method, which is also run
264
+ by ` windowResized() ` .
251
265
252
266
``` js
253
- setPosition ()
254
- {
267
+ setPosition () {
255
268
let hUnit = height / 8 ;
256
269
257
270
switch (this .feeling ) {
@@ -330,8 +343,7 @@ class Room {
330
343
331
344
### Background
332
345
333
- For the background, we decided very early in development that we wanted to design a **responsive generative artwork**
334
- .The artwork needed to further the connection between the users and their algorithmic representation. In order to
346
+ For the background, we decided very early in development that we wanted to design a ** responsive generative artwork** . The artwork needed to further the connection between the users and their algorithmic representation. In order to
335
347
achieve this result, we decided that we needed to show the ** sum of the emotions** of every person in the room at any
336
348
given time.
337
349
@@ -427,7 +439,7 @@ setInterval(function() {
427
439
In the p5 ` draw() ` function, the interpolated values are set to the shader with the ` setUniform() ` function.
428
440
429
441
``` js
430
- const {prev , next , lastTimestamp , interval } = summedFeelings;
442
+ const {prev , next , lastTimestamp , interval } = summedFeelings;
431
443
if (prev && next) {
432
444
bg .shader (bgShader);
433
445
const now = Date .now ();
@@ -439,14 +451,13 @@ if (prev && next) {
439
451
bg .quad (- 1 , - 1 , 1 , - 1 , 1 , 1 , - 1 , 1 );
440
452
bgShader .setUniform (' time' , millis () / 1000.0 );
441
453
}
442
- }
443
454
```
444
455
445
456
The user also has the option of ** saving** the background.
446
457
447
458
``` html
448
-
449
- < button class = " menu btn btn-text p-0 cool-underlined " onclick= " bg.saveCanvas('MOODboard', 'png')" > Save< / button>
459
+ < button class = " menu btn btn-text p-0 cool-underlined "
460
+ onclick =" bg.saveCanvas('MOODboard', 'png')" >Save</button >
450
461
```
451
462
452
463
## Miscellaneus
@@ -577,7 +588,7 @@ function onPlayerUpdated(id, feelings, landmarks, dimensions) {
577
588
#### For...of
578
589
579
590
[ For...of] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of ) was used to improve
580
- the readability and to iterate ` Map ` objects.
591
+ the readability and to iterate ` Map ` and other iterables objects.
581
592
582
593
``` js
583
594
for (const feeling of feelings) {
@@ -587,12 +598,13 @@ for (const feeling of feelings) {
587
598
588
599
## Credits
589
600
590
- Font: [Karrik](https://velvetyne.fr/fonts/karrik/)
591
- Libraries: P5js
592
-
593
- ## How to run
601
+ Font: [ Karrik] ( https://velvetyne.fr/fonts/karrik/ ) .
594
602
595
- Be sure to have node installed: https://nodejs.org/
603
+ Libraries and frameworks:
596
604
597
- * install node dependencies: ` npm install`
598
- * run local server: ` node server .js `
605
+ * [ p5.js] ( https://p5js.org/ )
606
+ * [ face-api.js] ( https://github.com/justadudewhohacks/face-api.js/ )
607
+ * [ socket.io] ( https://socket.io/ )
608
+ * [ Bootstrap 5] ( https://getbootstrap.com/ )
609
+ * [ uuid] ( https://github.com/uuidjs/uuid )
610
+ * [ Express] ( https://expressjs.com/it/ )
0 commit comments