Skip to content

Commit e6e3ad2

Browse files
committed
Fixed two bugs in makelab-logo-morpher.js
Fixed draw message text showing up in two places (and added a nice y loc animation for the message text) Fixed the mapping between art triangles and the logo so that only visible triangles in the logo are used
1 parent dc9b639 commit e6e3ad2

8 files changed

Lines changed: 118 additions & 60 deletions

File tree

dist/makelab.all.js

Lines changed: 38 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/makelab.all.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/makelab.all.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/makelab.logo.js

Lines changed: 38 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/makelab.logo.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/makelab.logo.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/apps/makelogo/TriangleArtMorphTest2-MorphLib/sketch.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,6 @@ function drawLoop() {
169169

170170
morpher.update(currentLerpAmt);
171171
morpher.draw(ctx);
172-
173-
// Art message fades out as morph progresses
174-
if (currentArt?.message) {
175-
currentArt.drawMessage(ctx, 1 - currentLerpAmt);
176-
}
177172
}
178173

179174
requestAnimationFrame(drawLoop);

src/lib/logo/makelab-logo-morpher.js

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,14 @@ export class MakeabilityLabLogoMorpher {
258258
this._artMessage = null;
259259
this._artMessageColor = null;
260260

261-
const logoTris = this.makeLabLogo.getAllTriangles();
262-
const animTris = this.makeLabLogoAnimated.getAllTriangles();
261+
// CHANGE: Filter for visible triangles only
262+
const logoTris = this.makeLabLogo.getAllTriangles().filter(t => t.visible);
263+
const animTris = this.makeLabLogoAnimated.getAllTriangles().filter(t => t.visible);
264+
263265
const endSize = this.makeLabLogo.cellSize;
264266

265-
// Set all animated triangles to the neutral start color before scattering
266-
this.makeLabLogoAnimated.setColors(this.startFillColor, this.startStrokeColor);
267+
// Set colors on the filtered pool
268+
animTris.forEach(tri => tri.setColors(this.startFillColor, this.startStrokeColor));
267269

268270
this._animTris = animTris.map((tri, i) => {
269271
const dest = logoTris[i];
@@ -280,7 +282,7 @@ export class MakeabilityLabLogoMorpher {
280282
tri.strokeWidth = this.explodeStrokeWidth ? tri.strokeWidth : dest.strokeWidth;
281283

282284
tri._start = _snapshot(tri);
283-
tri._dest = _snapshot(dest, 0 /* angle always 0 at destination */);
285+
tri._dest = _snapshot(dest, 0);
284286
return tri;
285287
});
286288
}
@@ -319,7 +321,8 @@ export class MakeabilityLabLogoMorpher {
319321
// Build direction-grouped destination map from the logo triangles.
320322
// Shuffle within each group so every call produces a fresh mapping.
321323
// -----------------------------------------------------------------
322-
const destByDir = _groupByDirection(this.makeLabLogo.getAllTriangles());
324+
const visibleLogoTris = this.makeLabLogo.getAllTriangles().filter(t => t.visible);
325+
const destByDir = _groupByDirection(visibleLogoTris);
323326
for (const group of destByDir.values()) shuffle(group);
324327

325328
const destIndex = new Map(); // round-robin index per direction
@@ -506,25 +509,43 @@ export class MakeabilityLabLogoMorpher {
506509
* @private
507510
*/
508511
_drawArtMessage(ctx, lerpAmt) {
509-
// Fade out over the first half of the morph
510-
const alpha = Math.max(0, 1 - lerpAmt * 2);
512+
const alpha = Math.max(0, 1 - lerpAmt * 1.1); // fades out faster than linear
511513
if (alpha <= 0) return;
512514

513-
ctx.save();
514-
ctx.globalAlpha = alpha;
515-
ctx.font = `bold ${this._artMessageFontSize}px sans-serif`;
516-
ctx.fillStyle = this._artMessageColor;
517-
ctx.textAlign = 'center';
518-
ctx.textBaseline = 'alphabetic';
515+
// 1. Find the current highest point among all triangles in this frame
516+
let currentMinY = Infinity;
517+
518+
// Check the animated triangles (the morphing set)
519+
for (const tri of this._animTris) {
520+
if (tri.visible) {
521+
// Subtract half size because (x,y) is the center
522+
const triTop = tri.y - (tri.size / 2);
523+
if (triTop < currentMinY) currentMinY = triTop;
524+
}
525+
}
519526

520-
// Center horizontally over the logo; position above it vertically
527+
// 2. Also check the target logo's bounds (the destination)
528+
// to ensure the label doesn't "dip" into the final logo position.
521529
const logoBox = this.makeLabLogo.getBoundingBox();
522-
const cx = logoBox.x + logoBox.width / 2;
523-
const cy = logoBox.y - this._artMessageFontSize * 0.3;
530+
const absoluteTop = Math.min(currentMinY, logoBox.y);
531+
532+
// 3. Render the text relative to that dynamic peak
533+
const margin = this._artMessageFontSize * 0.4;
534+
const cx = logoBox.x + logoBox.width / 2;
535+
const cy = absoluteTop - margin;
536+
537+
ctx.save();
538+
ctx.globalAlpha = alpha;
539+
ctx.font = `bold ${this._artMessageFontSize}px sans-serif`;
540+
ctx.fillStyle = this._artMessageColor;
541+
ctx.textAlign = 'center';
542+
ctx.textBaseline = 'alphabetic';
524543
ctx.fillText(this._artMessage, cx, cy);
525544
ctx.restore();
526545
}
527546

547+
548+
528549
/**
529550
* Draws the "Makeability Lab" label with a fade-in and upward slide entrance.
530551
* Only active once lerpAmt exceeds labelAppearThreshold.

0 commit comments

Comments
 (0)