From 27f7dbb84d43a0ae7274bd6b74cc6c9bb1cf7235 Mon Sep 17 00:00:00 2001 From: Mike Harvey Date: Tue, 28 Oct 2025 15:35:26 -0400 Subject: [PATCH 1/3] mirror generated dancer sprites --- src/GeneratedDancer.js | 27 +++++++++++++++++++++++++-- src/p5.dance.js | 7 ++++++- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/GeneratedDancer.js b/src/GeneratedDancer.js index 5f5bd7ee..1a5b3f86 100644 --- a/src/GeneratedDancer.js +++ b/src/GeneratedDancer.js @@ -40,6 +40,8 @@ class GeneratedDancer { this.graphics = this.p5.createGraphics(worldW, worldH); this.graphics.pixelDensity(1); + this.shouldMirror = 1; + this.mirror = 1; // Hand the renderer our mid-layer 2D context. this.renderer.init(this.graphics.drawingContext); @@ -49,6 +51,19 @@ class GeneratedDancer { if (typeof src === 'number') { src = movesById[src] || movesById[0]; } + const movesToMirror = new Set([ + 'rest', + 'clap_high', + 'dab', + 'drop', + 'floss', + 'fresh', + 'kick', + 'roll', + 'thriller', + ]); + this.shouldMirror = movesToMirror.has(src); + return this.renderer.setSource(src); } @@ -59,12 +74,12 @@ class GeneratedDancer { ); } - render(frameIndex) { + render(frameIndex, mirror) { if (!this.graphics || !this.renderer) { return; } // The renderer paints directly into graphics.drawingContext - this.renderer.renderFrame(frameIndex); + this.renderer.renderFrame(frameIndex, mirror); } resize(worldW, worldH) { @@ -94,6 +109,14 @@ class GeneratedDancer { this.renderer = null; this.p5 = null; } + + getMirror() { + return this.mirror; + } + + setMirror(mirror) { + this.mirror = this.shouldMirror ? mirror : 1; + } } module.exports = GeneratedDancer; diff --git a/src/p5.dance.js b/src/p5.dance.js index 13596a53..b1ca162d 100644 --- a/src/p5.dance.js +++ b/src/p5.dance.js @@ -683,8 +683,12 @@ module.exports = class DanceParty { animationLength - 1, Math.floor(measureTick * animationLength) ); + // If the current measure is odd, mirror the generated dancer. + const shouldMirror = Math.floor(currentMeasure * 2) % 2 === 1; + const mirror = shouldMirror ? -1 : 1; + this.generatedDancer.setMirror(mirror); - this.generatedDancer.render(measureFrame); + this.generatedDancer.render(measureFrame, mirror); } }; @@ -695,6 +699,7 @@ module.exports = class DanceParty { sprite.draw = () => { if (this.generatedDancer) { + sprite.mirrorX(this.generatedDancer.getMirror()); this.p5_.image( this.generatedDancer.graphics, sprite.x - location.x, From 9a3935beedf195aa3505aa1793e06b2b26f6a655 Mon Sep 17 00:00:00 2001 From: Mike Harvey Date: Tue, 28 Oct 2025 18:02:12 -0400 Subject: [PATCH 2/3] use boolean for shouldMirror --- src/GeneratedDancer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GeneratedDancer.js b/src/GeneratedDancer.js index 1a5b3f86..e6c255fd 100644 --- a/src/GeneratedDancer.js +++ b/src/GeneratedDancer.js @@ -40,7 +40,7 @@ class GeneratedDancer { this.graphics = this.p5.createGraphics(worldW, worldH); this.graphics.pixelDensity(1); - this.shouldMirror = 1; + this.shouldMirror = false; this.mirror = 1; // Hand the renderer our mid-layer 2D context. From 2a2dc51fea5470773eacbf34186526279cb197ba Mon Sep 17 00:00:00 2001 From: Mike Harvey Date: Tue, 28 Oct 2025 19:06:17 -0400 Subject: [PATCH 3/3] use measure for mirror --- src/GeneratedDancer.js | 43 ++++++++++++++++++++---------------------- src/p5.dance.js | 13 +++++-------- 2 files changed, 25 insertions(+), 31 deletions(-) diff --git a/src/GeneratedDancer.js b/src/GeneratedDancer.js index e6c255fd..68f8b3ef 100644 --- a/src/GeneratedDancer.js +++ b/src/GeneratedDancer.js @@ -40,8 +40,7 @@ class GeneratedDancer { this.graphics = this.p5.createGraphics(worldW, worldH); this.graphics.pixelDensity(1); - this.shouldMirror = false; - this.mirror = 1; + this.danceMove = null; // Hand the renderer our mid-layer 2D context. this.renderer.init(this.graphics.drawingContext); @@ -51,19 +50,7 @@ class GeneratedDancer { if (typeof src === 'number') { src = movesById[src] || movesById[0]; } - const movesToMirror = new Set([ - 'rest', - 'clap_high', - 'dab', - 'drop', - 'floss', - 'fresh', - 'kick', - 'roll', - 'thriller', - ]); - this.shouldMirror = movesToMirror.has(src); - + this.danceMove = src; return this.renderer.setSource(src); } @@ -74,12 +61,12 @@ class GeneratedDancer { ); } - render(frameIndex, mirror) { + render(frameIndex) { if (!this.graphics || !this.renderer) { return; } // The renderer paints directly into graphics.drawingContext - this.renderer.renderFrame(frameIndex, mirror); + this.renderer.renderFrame(frameIndex); } resize(worldW, worldH) { @@ -110,12 +97,22 @@ class GeneratedDancer { this.p5 = null; } - getMirror() { - return this.mirror; - } - - setMirror(mirror) { - this.mirror = this.shouldMirror ? mirror : 1; + shouldMirror(currentMeasure) { + const movesToMirror = new Set([ + 'rest', + 'clap_high', + 'dab', + 'drop', + 'floss', + 'fresh', + 'kick', + 'roll', + 'thriller', + ]); + return ( + movesToMirror.has(this.danceMove) && + Math.floor(currentMeasure * 2) % 2 === 1 + ); } } diff --git a/src/p5.dance.js b/src/p5.dance.js index b1ca162d..fcd34e75 100644 --- a/src/p5.dance.js +++ b/src/p5.dance.js @@ -683,12 +683,7 @@ module.exports = class DanceParty { animationLength - 1, Math.floor(measureTick * animationLength) ); - // If the current measure is odd, mirror the generated dancer. - const shouldMirror = Math.floor(currentMeasure * 2) % 2 === 1; - const mirror = shouldMirror ? -1 : 1; - this.generatedDancer.setMirror(mirror); - - this.generatedDancer.render(measureFrame, mirror); + this.generatedDancer.render(measureFrame); } }; @@ -699,7 +694,9 @@ module.exports = class DanceParty { sprite.draw = () => { if (this.generatedDancer) { - sprite.mirrorX(this.generatedDancer.getMirror()); + sprite.mirrorX( + this.generatedDancer.shouldMirror(this.getCurrentMeasure()) ? -1 : 1 + ); this.p5_.image( this.generatedDancer.graphics, sprite.x - location.x, @@ -1659,7 +1656,7 @@ module.exports = class DanceParty { if (!this.generatedDancer) { return; } - + this.danceMove = source; this.generatedDancer.setSource(source); }