-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
58 lines (48 loc) · 1.54 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
let model;
let strokePath = null;
let x, y;
let pen = "down";
const allModels = ['cat', 'yoga', 'pineapple', 'crab', 'flamingo', 'truck', 'face', 'spider', 'bird', 'bicyle', 'angel', 'the mona lisa', 'butterfly', 'mosquito', 'garden', 'octopus', 'windmill', 'pig', 'helicopter', 'calendar', 'sea', 'toothbrush', 'duck', 'toothpaste', 'flower', 'postcard', 'peas', 'trombone', 'barn', 'owl', 'paintbrush', 'palm tree', 'diving board', 'power outlet', 'bridge', 'floweryoga', 'couch'];
setup = () => {
createCanvas(windowWidth, windowHeight);
x = windowWidth / 2;
y = windowHeight / 2;
// Pick random sketch from array list
let rnd = Math.floor(Math.random() * allModels.length);
console.log('Drawing: ', allModels[rnd]);
model = ml5.SketchRNN(allModels[rnd], modelReady);
background(0);
}
modelReady = () => {
console.log("model ready");
model.reset();
model.generate(gotSketch);
}
draw = () => {
if (strokePath !== null) {
let newX = x + strokePath.dx;
let newY = y + strokePath.dy;
if (pen == "down") {
stroke(255);
strokeWeight(3);
line(x, y, newX, newY);
}
pen = strokePath.pen;
strokePath = null;
x = newX;
y = newY;
if (pen !== "end") {
model.generate(gotSketch);
} else {
console.log("drawing complete");
}
}
}
gotSketch = (err, s) => {
if (err) {
console.error(err);
} else {
strokePath = s;
//console.log(strokePath);
}
}