Skip to content

Commit cad483d

Browse files
cvalenzuelashiffman
authored andcommitted
updates to way of handling strokes (#228)
1 parent 3863574 commit cad483d

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/SketchRNN/index.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,27 @@ class SketchRNN {
4848
this.rnnState = this.model.update(this.penState, this.rnnState);
4949
const pdf = this.model.getPDF(this.rnnState, temperature);
5050
this.penState = this.model.sample(pdf);
51-
return this.penState;
51+
const result = {
52+
dx: this.penState[0],
53+
dy: this.penState[1],
54+
};
55+
if (this.penState[2] === 1) {
56+
result.pen = 'down';
57+
} else if (this.penState[3] === 1) {
58+
result.pen = 'up';
59+
} else if (this.penState[4] === 1) {
60+
result.pen = 'end';
61+
}
62+
return result;
5263
}
5364

54-
async generate(options, strokes, callback) {
65+
async generate(options, seedStrokes, callback) {
66+
const strokes = seedStrokes.map((s) => {
67+
const up = s.pen === 'up' ? 1 : 0;
68+
const down = s.pen === 'down' ? 1 : 0;
69+
const end = s.pen === 'end' ? 1 : 0;
70+
return [s.dx, s.dy, down, up, end];
71+
});
5572
return callCallback(this.generateInternal(options, strokes), callback);
5673
}
5774

0 commit comments

Comments
 (0)