forked from external-repos/squoosh
Fade into the center
This commit is contained in:
@@ -204,6 +204,7 @@ interface BackgroundBlob {
|
|||||||
velocity: number;
|
velocity: number;
|
||||||
spinTime: number;
|
spinTime: number;
|
||||||
alpha: number;
|
alpha: number;
|
||||||
|
alphaMultiplier: number;
|
||||||
rotatePos: number;
|
rotatePos: number;
|
||||||
radius: number;
|
radius: number;
|
||||||
x: number;
|
x: number;
|
||||||
@@ -230,6 +231,7 @@ class BackgroundBlobs {
|
|||||||
alpha:
|
alpha:
|
||||||
Math.random() ** 3 * (bgBlobsMaxAlpha - bgBlobsMinAlpha) +
|
Math.random() ** 3 * (bgBlobsMaxAlpha - bgBlobsMinAlpha) +
|
||||||
bgBlobsMinAlpha,
|
bgBlobsMinAlpha,
|
||||||
|
alphaMultiplier: 1,
|
||||||
spinTime:
|
spinTime:
|
||||||
Math.random() * (bgBlobsMaxSpinTime - bgBlobsMinSpinTime) +
|
Math.random() * (bgBlobsMaxSpinTime - bgBlobsMinSpinTime) +
|
||||||
bgBlobsMinSpinTime,
|
bgBlobsMinSpinTime,
|
||||||
@@ -249,6 +251,7 @@ class BackgroundBlobs {
|
|||||||
bounds: DOMRect,
|
bounds: DOMRect,
|
||||||
targetX: number,
|
targetX: number,
|
||||||
targetY: number,
|
targetY: number,
|
||||||
|
targetRadius: number,
|
||||||
) {
|
) {
|
||||||
if (this.overallAlphaPos !== 1) {
|
if (this.overallAlphaPos !== 1) {
|
||||||
this.overallAlphaPos = Math.min(
|
this.overallAlphaPos = Math.min(
|
||||||
@@ -258,14 +261,13 @@ class BackgroundBlobs {
|
|||||||
}
|
}
|
||||||
for (const bgBlob of this.bgBlobs) {
|
for (const bgBlob of this.bgBlobs) {
|
||||||
bgBlob.blob.advance(timeDelta);
|
bgBlob.blob.advance(timeDelta);
|
||||||
const dist = Math.hypot(bgBlob.x - targetX, bgBlob.y - targetY);
|
let dist = Math.hypot(bgBlob.x - targetX, bgBlob.y - targetY);
|
||||||
bgBlob.rotatePos = (bgBlob.rotatePos + timeDelta / bgBlob.spinTime) % 1;
|
bgBlob.rotatePos = (bgBlob.rotatePos + timeDelta / bgBlob.spinTime) % 1;
|
||||||
const shiftDist = bgBlob.velocity * timeDelta;
|
const shiftDist = bgBlob.velocity * timeDelta;
|
||||||
|
|
||||||
if (dist < 10) {
|
if (dist < 10) {
|
||||||
// Move the circle out to a random edge
|
// Move the circle out to a random edge
|
||||||
const tlbr = Math.floor(Math.random() * 4);
|
switch (Math.floor(Math.random() * 4)) {
|
||||||
switch (tlbr) {
|
|
||||||
case 0: // top
|
case 0: // top
|
||||||
bgBlob.x = Math.random() * bounds.width;
|
bgBlob.x = Math.random() * bounds.width;
|
||||||
bgBlob.y = -(bgBlob.radius * (1 + maxPointDistance));
|
bgBlob.y = -(bgBlob.radius * (1 + maxPointDistance));
|
||||||
@@ -284,12 +286,13 @@ class BackgroundBlobs {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
dist = Math.hypot(bgBlob.x - targetX, bgBlob.y - targetY);
|
||||||
const direction = Math.atan2(targetX - bgBlob.x, targetY - bgBlob.y);
|
const direction = Math.atan2(targetX - bgBlob.x, targetY - bgBlob.y);
|
||||||
const xShift = Math.sin(direction) * shiftDist;
|
const xShift = Math.sin(direction) * shiftDist;
|
||||||
const yShift = Math.cos(direction) * shiftDist;
|
const yShift = Math.cos(direction) * shiftDist;
|
||||||
bgBlob.x += xShift;
|
bgBlob.x += xShift;
|
||||||
bgBlob.y += yShift;
|
bgBlob.y += yShift;
|
||||||
|
bgBlob.alphaMultiplier = Math.min(dist / targetRadius, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -298,7 +301,7 @@ class BackgroundBlobs {
|
|||||||
|
|
||||||
for (const bgBlob of this.bgBlobs) {
|
for (const bgBlob of this.bgBlobs) {
|
||||||
ctx.save();
|
ctx.save();
|
||||||
ctx.globalAlpha = bgBlob.alpha * overallAlpha;
|
ctx.globalAlpha = bgBlob.alpha * bgBlob.alphaMultiplier * overallAlpha;
|
||||||
ctx.translate(bgBlob.x, bgBlob.y);
|
ctx.translate(bgBlob.x, bgBlob.y);
|
||||||
ctx.scale(bgBlob.radius, bgBlob.radius);
|
ctx.scale(bgBlob.radius, bgBlob.radius);
|
||||||
ctx.rotate(Math.PI * 2 * bgBlob.rotatePos);
|
ctx.rotate(Math.PI * 2 * bgBlob.rotatePos);
|
||||||
@@ -352,6 +355,7 @@ export function startBlobAnim(canvas: HTMLCanvasElement) {
|
|||||||
loadImgBounds.left - canvasBounds.left + loadImgBounds.width / 2;
|
loadImgBounds.left - canvasBounds.left + loadImgBounds.width / 2;
|
||||||
const loadImgCenterY =
|
const loadImgCenterY =
|
||||||
loadImgBounds.top - canvasBounds.top + loadImgBounds.height / 2;
|
loadImgBounds.top - canvasBounds.top + loadImgBounds.height / 2;
|
||||||
|
const loadImgRadius = loadImgBounds.height / 2 / (1 + maxPointDistance);
|
||||||
|
|
||||||
ctx.scale(devicePixelRatio, devicePixelRatio);
|
ctx.scale(devicePixelRatio, devicePixelRatio);
|
||||||
|
|
||||||
@@ -361,6 +365,7 @@ export function startBlobAnim(canvas: HTMLCanvasElement) {
|
|||||||
canvasBounds,
|
canvasBounds,
|
||||||
loadImgCenterX,
|
loadImgCenterX,
|
||||||
loadImgCenterY,
|
loadImgCenterY,
|
||||||
|
loadImgRadius,
|
||||||
);
|
);
|
||||||
centralBlobs.advance(delta);
|
centralBlobs.advance(delta);
|
||||||
|
|
||||||
@@ -370,13 +375,7 @@ export function startBlobAnim(canvas: HTMLCanvasElement) {
|
|||||||
ctx.fillStyle = blobPink;
|
ctx.fillStyle = blobPink;
|
||||||
|
|
||||||
backgroundBlobs.draw(ctx);
|
backgroundBlobs.draw(ctx);
|
||||||
|
centralBlobs.draw(ctx, loadImgCenterX, loadImgCenterY, loadImgRadius);
|
||||||
centralBlobs.draw(
|
|
||||||
ctx,
|
|
||||||
loadImgCenterX,
|
|
||||||
loadImgCenterY,
|
|
||||||
loadImgBounds.height / 2 / (1 + maxPointDistance),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function frame(time: number) {
|
function frame(time: number) {
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
justify-items: center;
|
justify-items: center;
|
||||||
position: relative;
|
position: relative;
|
||||||
--blob-pink: var(--hot-pink);
|
--blob-pink: var(--hot-pink);
|
||||||
--center-blob-opacity: 0.6;
|
--center-blob-opacity: 0.3;
|
||||||
}
|
}
|
||||||
|
|
||||||
.logo-container {
|
.logo-container {
|
||||||
|
|||||||
Reference in New Issue
Block a user