Skip to content
This repository was archived by the owner on Apr 6, 2020. It is now read-only.

Commit 4c2326f

Browse files
shiffmanjoeyklee
authored andcommitted
GAN example cleanup (#146)
1 parent fb2df46 commit 4c2326f

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

p5js/DCGAN/sketch.js

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,38 +7,39 @@
77
ml5 Example
88
DCGAN example
99
=== */
10+
1011
let dcgan;
11-
let outputCanvas;
12-
let button;
13-
let statusMsg;
12+
let outputCanvas;
13+
let button;
1414

1515
function setup() {
16-
createCanvas(400, 400)
17-
//load the model
18-
//we can have multiple pre-trained models (e.g. cats, flowers, etc.), just like SketchRNN
19-
dcgan = ml5.DCGAN('face', modelReady);
20-
21-
// //button to generate an image
22-
button = createButton('generate');
23-
button.mousePressed(generate);
16+
createCanvas(400, 400);
17+
// Load the model
18+
// There can be multiple pre-trained models (e.g. cats, flowers, etc.), just like SketchRNN
19+
dcgan = ml5.DCGAN('face', modelReady);
2420

21+
// Button to generate an image
22+
button = createButton('generate');
23+
button.mousePressed(generate);
24+
// Hiding button until model is ready
25+
button.hide();
2526
}
2627

2728
function generate() {
28-
//the generate function takes an output canvas to draw on
29-
// and a callback with possible info like time elapsed to generate the image
30-
dcgan.generate(displayImage);
29+
// Generate function receives a callback for when image is ready
30+
dcgan.generate(displayImage);
3131
}
3232

33-
function displayImage(err, result){
34-
//some callback
35-
if(err){
36-
console.log(err);
37-
return
38-
}
39-
image(result.image, 0, 0, 400, 400)
33+
function displayImage(err, result) {
34+
if (err) {
35+
console.log(err);
36+
return;
37+
}
38+
image(result.image, 0, 0, 400, 400);
4039
}
4140

4241
function modelReady() {
43-
generate();
44-
}
42+
console.log('model is ready');
43+
button.show();
44+
generate();
45+
}

0 commit comments

Comments
 (0)