Skip to content

Commit 2a2dc51

Browse files
author
Mike Harvey
committed
use measure for mirror
1 parent 9a3935b commit 2a2dc51

2 files changed

Lines changed: 25 additions & 31 deletions

File tree

src/GeneratedDancer.js

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ class GeneratedDancer {
4040

4141
this.graphics = this.p5.createGraphics(worldW, worldH);
4242
this.graphics.pixelDensity(1);
43-
this.shouldMirror = false;
44-
this.mirror = 1;
43+
this.danceMove = null;
4544

4645
// Hand the renderer our mid-layer 2D context.
4746
this.renderer.init(this.graphics.drawingContext);
@@ -51,19 +50,7 @@ class GeneratedDancer {
5150
if (typeof src === 'number') {
5251
src = movesById[src] || movesById[0];
5352
}
54-
const movesToMirror = new Set([
55-
'rest',
56-
'clap_high',
57-
'dab',
58-
'drop',
59-
'floss',
60-
'fresh',
61-
'kick',
62-
'roll',
63-
'thriller',
64-
]);
65-
this.shouldMirror = movesToMirror.has(src);
66-
53+
this.danceMove = src;
6754
return this.renderer.setSource(src);
6855
}
6956

@@ -74,12 +61,12 @@ class GeneratedDancer {
7461
);
7562
}
7663

77-
render(frameIndex, mirror) {
64+
render(frameIndex) {
7865
if (!this.graphics || !this.renderer) {
7966
return;
8067
}
8168
// The renderer paints directly into graphics.drawingContext
82-
this.renderer.renderFrame(frameIndex, mirror);
69+
this.renderer.renderFrame(frameIndex);
8370
}
8471

8572
resize(worldW, worldH) {
@@ -110,12 +97,22 @@ class GeneratedDancer {
11097
this.p5 = null;
11198
}
11299

113-
getMirror() {
114-
return this.mirror;
115-
}
116-
117-
setMirror(mirror) {
118-
this.mirror = this.shouldMirror ? mirror : 1;
100+
shouldMirror(currentMeasure) {
101+
const movesToMirror = new Set([
102+
'rest',
103+
'clap_high',
104+
'dab',
105+
'drop',
106+
'floss',
107+
'fresh',
108+
'kick',
109+
'roll',
110+
'thriller',
111+
]);
112+
return (
113+
movesToMirror.has(this.danceMove) &&
114+
Math.floor(currentMeasure * 2) % 2 === 1
115+
);
119116
}
120117
}
121118

src/p5.dance.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -683,12 +683,7 @@ module.exports = class DanceParty {
683683
animationLength - 1,
684684
Math.floor(measureTick * animationLength)
685685
);
686-
// If the current measure is odd, mirror the generated dancer.
687-
const shouldMirror = Math.floor(currentMeasure * 2) % 2 === 1;
688-
const mirror = shouldMirror ? -1 : 1;
689-
this.generatedDancer.setMirror(mirror);
690-
691-
this.generatedDancer.render(measureFrame, mirror);
686+
this.generatedDancer.render(measureFrame);
692687
}
693688
};
694689

@@ -699,7 +694,9 @@ module.exports = class DanceParty {
699694

700695
sprite.draw = () => {
701696
if (this.generatedDancer) {
702-
sprite.mirrorX(this.generatedDancer.getMirror());
697+
sprite.mirrorX(
698+
this.generatedDancer.shouldMirror(this.getCurrentMeasure()) ? -1 : 1
699+
);
703700
this.p5_.image(
704701
this.generatedDancer.graphics,
705702
sprite.x - location.x,
@@ -1659,7 +1656,7 @@ module.exports = class DanceParty {
16591656
if (!this.generatedDancer) {
16601657
return;
16611658
}
1662-
1659+
this.danceMove = source;
16631660
this.generatedDancer.setSource(source);
16641661
}
16651662

0 commit comments

Comments
 (0)