@@ -10,12 +10,16 @@ let imgRightEye;
10
10
let imgMouth ;
11
11
let imgBackground ;
12
12
13
+ let loadCount = 0 ;
14
+
13
15
const faceApiOptions = {
14
16
withLandmarks : true ,
15
17
withDescriptors : false
16
18
}
17
19
18
- function preload ( ) {
20
+ function setup ( ) {
21
+ createCanvas ( windowWidth , windowHeight ) ;
22
+
19
23
let hlRandomSeed = hl . random ( 1e12 ) ;
20
24
randomSeed ( hlRandomSeed ) ;
21
25
@@ -24,58 +28,77 @@ function preload() {
24
28
25
29
let backgroundId = random ( backgrounds_data ) ;
26
30
27
- hl . token . setTraits ( {
28
- "Base portrait" : baseId [ 2 ] + ", " + baseId [ 3 ] ,
29
- "Left eye" : leftEyeId [ 2 ] + ", " + leftEyeId [ 3 ] ,
30
- "Right eye" : rightEyeId [ 2 ] + ", " + rightEyeId [ 3 ] ,
31
- "Mouth" : mouthId [ 2 ] + ", " + mouthId [ 3 ] ,
32
- "Background" : backgroundId [ 2 ] + ", " + backgroundId [ 3 ]
33
- } ) ;
34
-
35
- imgBase = loadImage ( "portraits/" + baseId [ 0 ] + "." + baseId [ 1 ] , ( ) => console . log ( "Base portrait: " + baseId [ 2 ] + ", " + baseId [ 3 ] ) ) ;
36
- imgLeftEye = loadImage ( "portraits/" + leftEyeId [ 0 ] + "." + leftEyeId [ 1 ] , ( ) => console . log ( "Left eye: " + leftEyeId [ 2 ] + ", " + leftEyeId [ 3 ] ) ) ;
37
- imgRightEye = loadImage ( "portraits/" + rightEyeId [ 0 ] + "." + rightEyeId [ 1 ] , ( ) => console . log ( "Right eye: " + rightEyeId [ 2 ] + ", " + rightEyeId [ 3 ] ) ) ;
38
- imgMouth = loadImage ( "portraits/" + mouthId [ 0 ] + "." + mouthId [ 1 ] , ( ) => console . log ( "Mouth: " + mouthId [ 2 ] + ", " + mouthId [ 3 ] ) ) ;
39
-
40
- bodyPixBase = loadJSON ( "ml/bodyPix_" + baseId [ 0 ] + ".json" ) ;
41
- faceApiBase = loadJSON ( "ml/faceApi_" + baseId [ 0 ] + ".json" ) ;
42
- faceApiLeftEye = loadJSON ( "ml/faceApi_" + leftEyeId [ 0 ] + ".json" ) ;
43
- faceApiRightEye = loadJSON ( "ml/faceApi_" + rightEyeId [ 0 ] + ".json" ) ;
44
- faceApiMouth = loadJSON ( "ml/faceApi_" + mouthId [ 0 ] + ".json" ) ;
45
-
46
- imgBackground = loadImage ( "backgrounds/" + backgroundId [ 0 ] + "." + backgroundId [ 1 ] , ( ) => console . log ( "Background: " + backgroundId [ 2 ] + ", " + backgroundId [ 3 ] ) ) ;
31
+ imgBase = loadImage ( "portraits/" + baseId [ 0 ] + "." + baseId [ 1 ] , ( ) => { console . log ( "Base portrait: " + baseId [ 2 ] + ", " + baseId [ 3 ] ) ; loadCount ++ } ) ;
32
+ imgLeftEye = loadImage ( "portraits/" + leftEyeId [ 0 ] + "." + leftEyeId [ 1 ] , ( ) => { console . log ( "Left eye: " + leftEyeId [ 2 ] + ", " + leftEyeId [ 3 ] ) ; loadCount ++ } ) ;
33
+ imgRightEye = loadImage ( "portraits/" + rightEyeId [ 0 ] + "." + rightEyeId [ 1 ] , ( ) => { console . log ( "Right eye: " + rightEyeId [ 2 ] + ", " + rightEyeId [ 3 ] ) ; loadCount ++ } ) ;
34
+ imgMouth = loadImage ( "portraits/" + mouthId [ 0 ] + "." + mouthId [ 1 ] , ( ) => { console . log ( "Mouth: " + mouthId [ 2 ] + ", " + mouthId [ 3 ] ) ; loadCount ++ } ) ;
35
+
36
+ bodyPixBase = loadJSON ( "ml/bodyPix_" + baseId [ 0 ] + ".json" , ( ) => loadCount ++ ) ;
37
+ faceApiBase = loadJSON ( "ml/faceApi_" + baseId [ 0 ] + ".json" , ( ) => loadCount ++ ) ;
38
+ faceApiLeftEye = loadJSON ( "ml/faceApi_" + leftEyeId [ 0 ] + ".json" , ( ) => loadCount ++ ) ;
39
+ faceApiRightEye = loadJSON ( "ml/faceApi_" + rightEyeId [ 0 ] + ".json" , ( ) => loadCount ++ ) ;
40
+ faceApiMouth = loadJSON ( "ml/faceApi_" + mouthId [ 0 ] + ".json" , ( ) => loadCount ++ ) ;
41
+
42
+ imgBackground = loadImage ( "backgrounds/" + backgroundId [ 0 ] + "." + backgroundId [ 1 ] , ( ) => { console . log ( "Background: " + backgroundId [ 2 ] + ", " + backgroundId [ 3 ] ) ; loadCount ++ } ) ;
47
43
}
48
44
49
- function setup ( ) {
50
- let ratio = imgBase . height / imgBase . width ;
51
- let W = windowWidth , H = windowHeight ;
52
- if ( W * ratio < H ) createCanvas ( W , W * ratio ) ;
53
- else createCanvas ( H / ratio , H ) ;
54
-
55
- pixelDensity ( 2 ) ;
56
- noLoop ( ) ;
57
-
58
- if ( imgBase . width < width ) imgBase . resize ( width , 0 ) ;
59
- if ( imgBase . height < height ) imgBase . resize ( 0 , height ) ;
60
- if ( imgLeftEye . width < width ) imgLeftEye . resize ( width , 0 ) ;
61
- if ( imgLeftEye . height < height ) imgLeftEye . resize ( 0 , height ) ;
62
- if ( imgRightEye . width < width ) imgRightEye . resize ( width , 0 ) ;
63
- if ( imgRightEye . height < height ) imgRightEye . resize ( 0 , height ) ;
64
- if ( imgMouth . width < width ) imgMouth . resize ( width , 0 ) ;
65
- if ( imgMouth . height < height ) imgMouth . resize ( 0 , height ) ;
66
-
67
- imgBackground . resize ( 0 , height ) ;
68
-
69
- image ( imgBackground , random ( width - imgBackground . width ) , 0 ) ;
70
-
71
- drawingContext . shadowOffsetX = 0 ;
72
- drawingContext . shadowOffsetY = 0 ;
73
- drawingContext . shadowBlur = width / 100 ;
74
- drawingContext . shadowColor = "#00000095" ;
75
-
76
- cutOutline ( ) ;
77
- drawFacialFeatures ( ) ;
78
- hl . token . capturePreview ( ) ;
45
+ function draw ( ) {
46
+ background ( 0 ) ;
47
+ frameRate ( 20 ) ;
48
+ noStroke ( ) ;
49
+ fill ( 255 ) ;
50
+ textAlign ( LEFT , CENTER ) ;
51
+ let fonts = shuffle ( [ "Arial" , "Verdana" , "Tahoma" , "Times New Roman" , "Georgia" , "Garamond" , "Courier New" ] ) ;
52
+ let letters = "Loading" . split ( "" ) ;
53
+ let x = width / 2 - 40 ;
54
+ for ( let l of letters ) {
55
+ textFont ( fonts . pop ( ) , 24 ) ;
56
+ text ( l , x , height / 2 ) ;
57
+ x += textWidth ( l ) ;
58
+ }
59
+ //text("Loading...", width/2, height/2);
60
+
61
+ if ( loadCount == 10 ) {
62
+ console . log ( loadCount )
63
+ let ratio = imgBase . height / imgBase . width ;
64
+ let W = windowWidth , H = windowHeight ;
65
+ if ( W * ratio < H ) resizeCanvas ( W , W * ratio ) ;
66
+ else resizeCanvas ( H / ratio , H ) ;
67
+
68
+ pixelDensity ( 2 ) ;
69
+ noLoop ( ) ;
70
+
71
+ if ( imgBase . width < width ) imgBase . resize ( width , 0 ) ;
72
+ if ( imgBase . height < height ) imgBase . resize ( 0 , height ) ;
73
+ if ( imgLeftEye . width < width ) imgLeftEye . resize ( width , 0 ) ;
74
+ if ( imgLeftEye . height < height ) imgLeftEye . resize ( 0 , height ) ;
75
+ if ( imgRightEye . width < width ) imgRightEye . resize ( width , 0 ) ;
76
+ if ( imgRightEye . height < height ) imgRightEye . resize ( 0 , height ) ;
77
+ if ( imgMouth . width < width ) imgMouth . resize ( width , 0 ) ;
78
+ if ( imgMouth . height < height ) imgMouth . resize ( 0 , height ) ;
79
+
80
+ imgBackground . resize ( 0 , height ) ;
81
+
82
+ image ( imgBackground , random ( width - imgBackground . width ) , 0 ) ;
83
+
84
+ drawingContext . shadowOffsetX = 0 ;
85
+ drawingContext . shadowOffsetY = 0 ;
86
+ drawingContext . shadowBlur = width / 100 ;
87
+ drawingContext . shadowColor = "#00000095" ;
88
+
89
+ cutOutline ( ) ;
90
+ drawFacialFeatures ( ) ;
91
+ hl . token . capturePreview ( ) ;
92
+ }
93
+ }
94
+
95
+ function keyPressed ( ) {
96
+ if ( key == "r" ) {
97
+ loadCount = 0 ;
98
+ console . clear ( ) ;
99
+ loop ( ) ;
100
+ setup ( ) ;
101
+ }
79
102
}
80
103
81
104
// BACKGROUND
0 commit comments