mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-01 19:42:03 +00:00
* feat(catalog): put the variables panel back, on payloads The panel drove its preview by loading an .html from docs/public, a type the host does not publish, so it showed an empty frame in production and was parked when the catalog was re-landed. It now mounts the same JSON payload the plain player uses and re-mounts it as values change, injecting them as window.__hfVariables into the composition head before any of its scripts run, which is where the runtime reads overrides from. Doing it in the markup rather than after load is what stops the composition initialising with the wrong values first. 172 items with variables get the panel back; the playhead carries across a change so a tweak mid-shot does not jump back to frame zero. * fix(docs): drop the unused url form and the needless escapes * fix(docs): the panel cannot reference a binding beside the export * feat(catalog): make importing an SVG the obvious move A reader arrives at this control with a shape, not with path data, and the panel asked for the coordinates first. Import is now the primary action in a drop target you can see is a drop target, and the raw path sits behind a disclosure for anyone who wants it. * feat(cli): let a fruitless catalog search report the gap An agent that searches by meaning and finds nothing worth installing knows something we do not: the name of a move the catalog is missing. There was no way to tell us, so that knowledge was lost at the end of every run. hyperframes feedback --search-miss "<query>" --wanted "<the move>" records it. It carries no rating, so it never lands in the rating metric, and it is a separate deliberate command rather than something catalog --query does on its own: plain search still sends nothing, which is what the CLI promises. --rating stops being required at the arg level, since a miss has no rating to give. The check moved into the run body, where an absent one is now handled rather than crashing on undefined. * feat(cli): carry tuned variable values into the install snippet Someone who tunes a block on its catalog page had no way to keep those values: the install command was the same one everybody gets, and the tuning stayed on the page. hyperframes add <item> --vars '<json>' now prints a mount element carrying data-variable-values, so the values land where the block is used. They ride on the host rather than being written into the installed file. That keeps the composition on disk byte-identical to the registry's, so a later reinstall can still tell an edit from an update, and it lets two mounts of the same block carry different values. * fix(catalog): serve the item's own directory so runtime paths resolve Some compositions assemble their asset URLs at run time — "compositions/components/" + texture + ".png" for the texture masks, a font the compiler pulled into _remote_media — and no scan of the markup can see a string that does not exist until a script concatenates it. Those items either rendered black or were dropped to a video that had never been uploaded. Each item that needs it now has its prepared directory published, and its payload carries a <base> pointing at it, so any relative path the composition invents resolves. caption-texture renders its masks again, and variable-font-flex has a preview at all for the first time: its MP4 and poster are both 403. Both layouts are published, because which one a composition asks for differs per item, and a directory only earns that if it is under 2 MB. The 12 MB texture sheet keeps the recorded video it already had. * fix(catalog): let the variables panel actually drive the composition Every control on the panel was inert. The values reached the composition and nothing repainted, because the payload had already been compiled: compiling inlines a mounted component and resolves its variables into the markup and CSS, so by the time a reader turns a knob there is nothing left to change. An item that declares variables now ships uncompiled, keeping the mount the runtime loads at run time, which is the only state where data-variable-values still means anything. The component travels inline as a data URI rather than a sibling file, because .html is the one type the docs host will not publish. The demo's own pinned values come off, so the reader's choices reach the mount instead of losing to the values the demo picked to show itself off. Measured on the rendered frame rather than the DOM: green rgb(98,207,144), blue rgb(6,6,199), violet rgb(177,147,230), and back to green. docs/public/catalog drops from 48 MB to 35 MB along the way, since an uncompiled payload carries far less than an inlined one. * feat(catalog): keep variable changes in the url A reader who tuned a piece lost it on reload, and had nothing to send anyone. The values now live in the query string, scoped by composition id so two links never read each other,and only the ones that differ from the defaults are written, so changing one knob gives a short URL rather than every variable spelled out. replaceState rather than pushState: dragging a slider should not leave a trail of history entries. An unreadable value is ignored rather than thrown, so a truncated or hand-edited link opens the piece at its defaults. * fix(catalog): only rewrite the url when a value actually changed * refactor(catalog): memoise the declared defaults on their content * feat(catalog): offer an install command carrying the tuned values The Install block is generated before anyone touches a knob, so it can only ever print the plain command. Someone who spent a minute tuning a piece copied it and got the defaults back. The panel now carries its own command in the Snippet tab, with --vars holding exactly the values that differ. An untouched piece still offers the same short command, so nothing gets noisier for the common case. * fix(catalog): a piece with nothing to render is a skip, not a failure caption-blend-difference is a stylesheet and a paragraph of prose — a class you add to your own captions, with no standalone scene to show. The generator treated that as a build failure, so every run ended by reporting something broken when nothing was. It now reports the shape it is and keeps its recorded video, which is the only honest preview such an item has. A genuine render failure still throws. * fix(catalog): restore variables from the url on a cold load A shared link opened at the defaults. The first render happens on the server, where there is no window to read the query string from, and React then hydrates against that markup and never revisits it — so the values only appeared once you touched a control. The URL is read again after mount, which is the first moment it exists. The value is also escaped once now rather than twice: URLSearchParams already decodes on the way out, and decoding a second time turned an SVG path full of percent-escapes into something that no longer parsed, besides doubling the length of every link. * fix(catalog): mount the preview with the values a link carried The frame was built from the declared defaults and the shared values were posted to it afterwards, which is too late for anything the composition reads once at init: a path arrived after the mark had already been drawn from the default one, so a link looked right in the panel and wrong on screen. * feat(catalog): the install command follows the values you tuned Copying the Install line gave the plain command back, because that block is generated before anyone touches a knob and had no way to know what changed. The tuned command only existed in the panel Snippet tab, which is not where anyone looks for it. The line now reads the same query string the panel writes, so the two agree without either component knowing the other exists, and a shared link carries the right command too. replaceState fires no event, so the panel announces its own writes. * fix(catalog): send a text variable to the preview once it is finished Every other control in the explorer reports a whole value on every event: a slider at any position is a position, a swatch is a colour. A text field is not. Typing v3 into a badge posted v first, so the preview remounted and rendered a composition built from half a word. The post now waits while a text field has focus and goes out when the edit is committed, with Enter or by clicking away. The field itself is unchanged and still tracks every keystroke. --------- Co-authored-by: Miguel Angel Simon Sierra <miguelangelsi07@gmail.com>
1107 lines
48 KiB
Plaintext
1107 lines
48 KiB
Plaintext
---
|
|
title: "Soft Blob Touch"
|
|
description: "A granular soft blob idles with slow internal drift; a scripted touch dot decel-arrives, the blob deforms toward it with an attraction bulge, then recovers with a velocity-preserving spring. No hard edges anywhere."
|
|
---
|
|
|
|
import { InstallCommand } from "/snippets/install-command.jsx";
|
|
import { VariablesExplorer } from "/snippets/variables-explorer.jsx";
|
|
|
|
<VariablesExplorer
|
|
previewSrc="/public/catalog/components/soft-blob-touch.json"
|
|
compositionId="soft-blob-touch"
|
|
compositionSrc="compositions/components/soft-blob-touch.html"
|
|
variables={[{"id":"touch_x","type":"number","role":"layout","label":"Touch X","description":"Touch point, percent of host width.","default":66,"min":8,"max":92,"step":1,"unit":"%"},{"id":"touch_y","type":"number","role":"layout","label":"Touch Y","description":"Touch point, percent of host height.","default":38,"min":8,"max":92,"step":1,"unit":"%"},{"id":"touch_at","type":"number","role":"timing","label":"Touch at","description":"Seconds from mount start when the dot makes contact.","default":1.6,"min":0.9,"max":10,"step":0.1,"unit":"s"},{"id":"grain","type":"enum","role":"style","label":"Grain","description":"Speck register for the granular body.","default":"fine","options":[{"value":"fine","label":"Fine"},{"value":"coarse","label":"Coarse"}]},{"id":"accent","type":"enum","role":"style","label":"Accent","description":"Body tint: green rides --brand, blue rides --accent, violet rides --accent-2.","default":"green","options":[{"value":"green","label":"Green"},{"value":"blue","label":"Blue"},{"value":"violet","label":"Violet"}]},{"id":"exit","type":"enum","role":"timing","label":"Exit","description":"Optional departure. Default none: the settled blob holds until the frame cuts.","default":"none","options":[{"value":"none","label":"None"},{"value":"fade","label":"Fade"},{"value":"up","label":"Up"}]}]}
|
|
>
|
|
|
|
```html soft-blob-touch.html
|
|
<!doctype html>
|
|
<!--
|
|
soft-blob-touch: HyperFrames video primitive (product demo / material)
|
|
|
|
A granular soft blob idles with slow internal drift; a scripted touch dot
|
|
decel-arrives at a caller-positioned point; the blob deforms toward it
|
|
(an attraction bulge with mass), then recovers with an interruptible
|
|
spring once the dot retreats. The AI-orb material beat. Softness is the
|
|
whole point: the body is layered radial gradients plus a seeded grain
|
|
field, and nothing in the frame has a hard edge.
|
|
|
|
Reference: alexwidua 1702356241186476225 sheet-02 (granular blob leaning
|
|
toward a finger; fuzzy boundary, mass, recovery wobble).
|
|
|
|
Variables (declared in data-composition-variables below):
|
|
- touch_x, touch_y (numbers, percent of host box): where the dot lands.
|
|
- touch_at (seconds): when the dot makes contact. Clamped so the whole
|
|
deform and recover tail stays inside the clip.
|
|
- grain ("fine" | "coarse"): speck count and size for the body.
|
|
- accent ("green" | "blue" | "violet"): green rides --brand, blue rides
|
|
--accent, violet rides --accent-2.
|
|
- exit ("none" | "fade" | "up"): default none, the settled blob holds.
|
|
|
|
Envelope, fixed IN and OUT with elastic HOLD only (never timeScale):
|
|
IN ends when the recovery spring settles (touch_at + 1.57s); HOLD is
|
|
dead still (drift completes integer sine cycles and ends at exactly
|
|
zero by then); OUT = 0.45s only when exit is not none.
|
|
|
|
Deformation model (law L1, interruptible spring):
|
|
Two plain-object params (bulge, lean) feed ONE onUpdate painter. The
|
|
attack tween is the first 75 percent of a power2.out lean-in, cut
|
|
mid-flight when the dot lifts (analytic cut: the junction value AND
|
|
velocity are computed in closed form). The recovery tween's ease is a
|
|
closed-form underdamped spring whose initial velocity equals the cut
|
|
velocity, so the redirect preserves momentum exactly. Both tweens have
|
|
explicit endpoints; any seek order lands identical values.
|
|
|
|
Determinism (canvas 2D law, per particle-image-reveal):
|
|
One grain table is computed exactly once at build from fixed LCG seed
|
|
0x50f7b10b. Every painted frame is a pure function of (table, params,
|
|
timeline time). onUpdate clears and redraws from scratch; no
|
|
Math.random, no wall clock, no incremental state. Eventful seeks
|
|
(suppressEvents false) repaint identically in any order.
|
|
-->
|
|
<html
|
|
lang="en"
|
|
data-composition-id="soft-blob-touch"
|
|
data-composition-duration="4"
|
|
data-composition-variables='[
|
|
{ "id": "touch_x", "type": "number", "role": "layout", "label": "Touch X", "description": "Touch point, percent of host width.", "default": 66, "min": 8, "max": 92, "step": 1, "unit": "%" },
|
|
{ "id": "touch_y", "type": "number", "role": "layout", "label": "Touch Y", "description": "Touch point, percent of host height.", "default": 38, "min": 8, "max": 92, "step": 1, "unit": "%" },
|
|
{ "id": "touch_at", "type": "number", "role": "timing", "label": "Touch at", "description": "Seconds from mount start when the dot makes contact.", "default": 1.6, "min": 0.9, "max": 10, "step": 0.1, "unit": "s" },
|
|
{ "id": "grain", "type": "enum", "role": "style", "label": "Grain", "description": "Speck register for the granular body.", "default": "fine", "options": [{ "value": "fine", "label": "Fine" }, { "value": "coarse", "label": "Coarse" }] },
|
|
{ "id": "accent", "type": "enum", "role": "style", "label": "Accent", "description": "Body tint: green rides --brand, blue rides --accent, violet rides --accent-2.", "default": "green", "options": [{ "value": "green", "label": "Green" }, { "value": "blue", "label": "Blue" }, { "value": "violet", "label": "Violet" }] },
|
|
{ "id": "exit", "type": "enum", "role": "timing", "label": "Exit", "description": "Optional departure. Default none: the settled blob holds until the frame cuts.", "default": "none", "options": [{ "value": "none", "label": "None" }, { "value": "fade", "label": "Fade" }, { "value": "up", "label": "Up" }] }
|
|
]'
|
|
>
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<title>Soft Blob Touch</title>
|
|
</head>
|
|
<body>
|
|
<template>
|
|
<div id="root" data-composition-id="soft-blob-touch" data-duration="4" data-fps="30">
|
|
<style>
|
|
*,
|
|
*::before,
|
|
*::after {
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
#root {
|
|
position: absolute;
|
|
inset: 0;
|
|
overflow: hidden;
|
|
container-type: size;
|
|
isolation: isolate;
|
|
color: var(--fg, #f8fafc);
|
|
font-family: var(--font-body, "Inter", system-ui, sans-serif);
|
|
pointer-events: none;
|
|
}
|
|
|
|
.sbt-clip {
|
|
position: absolute;
|
|
inset: 0;
|
|
overflow: hidden;
|
|
}
|
|
|
|
.sbt-stage {
|
|
position: absolute;
|
|
inset: 0;
|
|
will-change: transform, opacity;
|
|
}
|
|
|
|
.sbt-canvas {
|
|
position: absolute;
|
|
inset: 0;
|
|
width: 100%;
|
|
height: 100%;
|
|
}
|
|
|
|
/* The touch dot: a soft disc with a gradient falloff, no hard rim.
|
|
Motion rides transforms only (px), never left or top. */
|
|
.sbt-touch {
|
|
position: absolute;
|
|
left: 0;
|
|
top: 0;
|
|
width: 4.6cqmin;
|
|
height: 4.6cqmin;
|
|
margin-left: -2.3cqmin;
|
|
margin-top: -2.3cqmin;
|
|
border-radius: 50%;
|
|
background: radial-gradient(
|
|
circle at 42% 38%,
|
|
color-mix(in srgb, var(--fg, #f8fafc) 96%, transparent) 0%,
|
|
color-mix(in srgb, var(--fg, #f8fafc) 78%, transparent) 34%,
|
|
color-mix(in srgb, var(--fg, #f8fafc) 26%, transparent) 62%,
|
|
transparent 78%
|
|
);
|
|
will-change: transform, opacity;
|
|
}
|
|
</style>
|
|
|
|
<div
|
|
id="soft-blob-touch-clip"
|
|
class="sbt-clip clip"
|
|
data-start="0"
|
|
data-duration="4"
|
|
data-track-index="0"
|
|
>
|
|
<div class="sbt-stage">
|
|
<canvas class="sbt-canvas" aria-hidden="true"></canvas>
|
|
<div class="sbt-touch" aria-hidden="true"></div>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/gsap@3.14.2/dist/gsap.min.js"></script>
|
|
<script>
|
|
(function () {
|
|
"use strict";
|
|
|
|
var root = document.getElementById("root");
|
|
var stage = root.querySelector(".sbt-stage");
|
|
var canvas = root.querySelector(".sbt-canvas");
|
|
var touchDot = root.querySelector(".sbt-touch");
|
|
var vars =
|
|
window.__hyperframes && window.__hyperframes.getVariables
|
|
? window.__hyperframes.getVariables()
|
|
: {};
|
|
|
|
function num(value, fallback, min, max) {
|
|
var n = Number(value);
|
|
if (!isFinite(n)) n = fallback;
|
|
return Math.max(min, Math.min(max, n));
|
|
}
|
|
|
|
var grain = vars.grain === "coarse" ? "coarse" : "fine";
|
|
var exit = vars.exit === "fade" || vars.exit === "up" ? vars.exit : "none";
|
|
// Each enum choice routes to a DIFFERENT contract token so the
|
|
// variable stays meaningful under a theme.
|
|
var accentColors = {
|
|
green: "var(--brand, #71f5a7)",
|
|
blue: "var(--accent, #61a8ff)",
|
|
violet: "var(--accent-2, #c5a3ff)",
|
|
};
|
|
var accent = Object.prototype.hasOwnProperty.call(accentColors, vars.accent)
|
|
? vars.accent
|
|
: "green";
|
|
// The bundler mirrors composition variables as scoped CSS custom
|
|
// props, so this unit's own accent variable shadows the contract
|
|
// --accent token inside the subtree ("blue" is a valid CSS color
|
|
// and would render pure blue). When the shadow is present, fall
|
|
// back to the literal contract value instead of var(--accent).
|
|
var computedAccent = getComputedStyle(root).getPropertyValue("--accent").trim();
|
|
if (
|
|
computedAccent === "green" ||
|
|
computedAccent === "blue" ||
|
|
computedAccent === "violet"
|
|
) {
|
|
accentColors.blue = "#61a8ff";
|
|
}
|
|
|
|
// Envelope. The deform tail is ATTACK + RECOVER after contact;
|
|
// clamp touch_at so the spring settles inside the clip.
|
|
var ATTACK_NAT = 0.55; // natural length of the uncut lean-in
|
|
var CUT_FRAC = 0.75; // the dot lifts at 75 percent of it
|
|
var ATTACK = ATTACK_NAT * CUT_FRAC;
|
|
var RECOVER = 1.15;
|
|
var duration = Math.max(0.001, parseFloat(root.dataset.duration || "4"));
|
|
var OUT = exit === "none" ? 0 : 0.45;
|
|
var maxTouch = Math.max(0.9, duration - (ATTACK + RECOVER) - OUT - 0.05);
|
|
var touchAt = num(vars.touch_at, 1.6, 0.9, maxTouch);
|
|
var cutAt = touchAt + ATTACK;
|
|
var IN_END = cutAt + RECOVER;
|
|
var OUT_START = IN_END + Math.max(0, duration - IN_END - OUT);
|
|
|
|
// Canvas raster basis is fixed once at mount (elastic root: the
|
|
// host box decides the resolution; same host, same raster).
|
|
var dpr = Math.min(2, Math.max(1, Number(window.devicePixelRatio) || 1));
|
|
var box = root.getBoundingClientRect();
|
|
var cssW = Math.max(1, Math.round(box.width) || 640);
|
|
var cssH = Math.max(1, Math.round(box.height) || 360);
|
|
canvas.width = Math.round(cssW * dpr);
|
|
canvas.height = Math.round(cssH * dpr);
|
|
var ctx = canvas.getContext("2d");
|
|
var W = canvas.width;
|
|
var H = canvas.height;
|
|
var minDim = Math.min(W, H);
|
|
|
|
var touchX = (num(vars.touch_x, 66, 8, 92) / 100) * W;
|
|
var touchY = (num(vars.touch_y, 38, 8, 92) / 100) * H;
|
|
var centerX = W * 0.5;
|
|
var centerY = H * 0.5;
|
|
var R = minDim * 0.26;
|
|
|
|
// Direction of attraction, guarded for a touch at dead center.
|
|
var dxT = touchX - centerX;
|
|
var dyT = touchY - centerY;
|
|
var distT = Math.hypot(dxT, dyT);
|
|
var dirX = distT > 1 ? dxT / distT : 0.7071;
|
|
var dirY = distT > 1 ? dyT / distT : -0.7071;
|
|
|
|
// Resolve accent and fg to concrete rgb once at mount so canvas
|
|
// fills never depend on style recalc during seeks. Mixing happens
|
|
// numerically here (computed color-mix strings are not parseable
|
|
// across engines).
|
|
function probeColor(cssColor, fallback) {
|
|
var probe = root.ownerDocument.createElement("span");
|
|
probe.style.color = cssColor;
|
|
root.appendChild(probe);
|
|
var out = getComputedStyle(probe).color || fallback;
|
|
probe.remove();
|
|
var m = out.match(/rgba?\(\s*([\d.]+)[,\s]+([\d.]+)[,\s]+([\d.]+)/);
|
|
if (!m) {
|
|
m = fallback.match(/rgba?\(\s*([\d.]+)[,\s]+([\d.]+)[,\s]+([\d.]+)/);
|
|
}
|
|
return m ? [Number(m[1]), Number(m[2]), Number(m[3])] : [113, 245, 167];
|
|
}
|
|
var accentRgb = probeColor(accentColors[accent], "rgb(113, 245, 167)");
|
|
var fgRgb = probeColor("var(--fg, #f8fafc)", "rgb(248, 250, 252)");
|
|
function mix(a, b, t) {
|
|
return [
|
|
Math.round(a[0] + (b[0] - a[0]) * t),
|
|
Math.round(a[1] + (b[1] - a[1]) * t),
|
|
Math.round(a[2] + (b[2] - a[2]) * t),
|
|
];
|
|
}
|
|
function rgba(c, a) {
|
|
return "rgba(" + c[0] + "," + c[1] + "," + c[2] + "," + a + ")";
|
|
}
|
|
var bodyRgb = mix(accentRgb, fgRgb, 0.18);
|
|
var softRgb = mix(accentRgb, fgRgb, 0.55);
|
|
|
|
// The grain table: computed exactly once, then only read.
|
|
var counts = { fine: 1500, coarse: 760 };
|
|
var sizes = { fine: 0.0055, coarse: 0.0102 };
|
|
var COUNT = counts[grain];
|
|
var SPECK = sizes[grain] * minDim;
|
|
var grains = (function () {
|
|
var state = 0x50f7b10b;
|
|
function next() {
|
|
state = (Math.imul(1664525, state) + 1013904223) >>> 0;
|
|
return state / 4294967296;
|
|
}
|
|
var rows = [];
|
|
for (var i = 0; i < COUNT; i += 1) {
|
|
// Radial distribution with a fuzzy tail past R: density thins
|
|
// toward the boundary and alpha fades it out, so the edge is
|
|
// granular vapor, never a line.
|
|
var rr = Math.pow(next(), 0.55) * R * 1.16;
|
|
var th = next() * Math.PI * 2;
|
|
var edge = Math.max(0, Math.min(1, (1.16 - rr / R) / 0.42));
|
|
rows.push({
|
|
x: Math.cos(th) * rr,
|
|
y: Math.sin(th) * rr * 0.94,
|
|
size: SPECK * (0.5 + 0.9 * next()),
|
|
dim: (0.3 + 0.7 * next()) * edge,
|
|
tone: next(),
|
|
driftAmp: (0.008 + 0.014 * next()) * minDim,
|
|
driftCycles: next() < 0.5 ? 1 : 2,
|
|
phaseX: next() * Math.PI * 2,
|
|
phaseY: next() * Math.PI * 2,
|
|
});
|
|
}
|
|
return rows;
|
|
})();
|
|
|
|
function clamp01(v) {
|
|
return v < 0 ? 0 : v > 1 ? 1 : v;
|
|
}
|
|
|
|
// Deformation params. Attack lifts both toward CUT value; the
|
|
// recovery springs them home. The painter owns all amplitudes.
|
|
var P = { bulge: 0, lean: 0 };
|
|
var bCut = 1 - Math.pow(1 - CUT_FRAC, 2); // power2.out at the cut
|
|
var vCut = (2 * (1 - CUT_FRAC)) / ATTACK_NAT; // slope there, per s
|
|
var attackEase = function (p) {
|
|
return (1 - Math.pow(1 - p * CUT_FRAC, 2)) / bCut;
|
|
};
|
|
// Closed-form underdamped spring x(s), x(0) = 1, x'(0) = vCut/bCut
|
|
// (velocity preserved across the cut), corrected by a linear ramp
|
|
// so x(RECOVER) is exactly zero. Higher frequency for the local
|
|
// bulge, lower for the whole-mass lean: the surface snaps back
|
|
// faster than the body.
|
|
function springEase(lambda, omega) {
|
|
var v0 = vCut / bCut;
|
|
var c2 = (v0 + lambda) / omega;
|
|
function x(s) {
|
|
return Math.exp(-lambda * s) * (Math.cos(omega * s) + c2 * Math.sin(omega * s));
|
|
}
|
|
var xEnd = x(RECOVER);
|
|
return function (p) {
|
|
var s = p * RECOVER;
|
|
return 1 - (x(s) - (s / RECOVER) * xEnd);
|
|
};
|
|
}
|
|
var bulgeSpring = springEase(4.2, Math.PI * 2 * 2.2);
|
|
var leanSpring = springEase(3.6, Math.PI * 2 * 1.5);
|
|
|
|
// Pure repaint: clear, then rebuild the whole frame from
|
|
// (grain table, P, t). Drift phase u completes integer sine
|
|
// cycles over [0, IN_END] and is exactly zero from IN_END on,
|
|
// so the HOLD frame is dead still.
|
|
var sigma = R * 0.85;
|
|
var bulgeAmp = R * 0.62;
|
|
var leanAmp = minDim * 0.045;
|
|
function paint(t) {
|
|
ctx.clearRect(0, 0, W, H);
|
|
var u = clamp01(t / IN_END);
|
|
var lx = leanAmp * P.lean * dirX;
|
|
var ly = leanAmp * P.lean * dirY;
|
|
var cx = centerX + lx;
|
|
var cy = centerY + ly;
|
|
|
|
// Layered radial gradients: wide aura, mid glow, dense core,
|
|
// and a bulge lobe that swells toward the touch point.
|
|
var aura = ctx.createRadialGradient(cx, cy, 0, cx, cy, R * 1.9);
|
|
aura.addColorStop(0, rgba(accentRgb, 0.16));
|
|
aura.addColorStop(0.55, rgba(accentRgb, 0.06));
|
|
aura.addColorStop(1, rgba(accentRgb, 0));
|
|
ctx.fillStyle = aura;
|
|
ctx.fillRect(0, 0, W, H);
|
|
|
|
var mid = ctx.createRadialGradient(cx, cy, 0, cx, cy, R * 1.12);
|
|
mid.addColorStop(0, rgba(bodyRgb, 0.34));
|
|
mid.addColorStop(0.62, rgba(bodyRgb, 0.16));
|
|
mid.addColorStop(1, rgba(bodyRgb, 0));
|
|
ctx.fillStyle = mid;
|
|
ctx.fillRect(0, 0, W, H);
|
|
|
|
var core = ctx.createRadialGradient(
|
|
cx - R * 0.12,
|
|
cy - R * 0.14,
|
|
0,
|
|
cx,
|
|
cy,
|
|
R * 0.62,
|
|
);
|
|
core.addColorStop(0, rgba(softRgb, 0.4));
|
|
core.addColorStop(1, rgba(softRgb, 0));
|
|
ctx.fillStyle = core;
|
|
ctx.fillRect(0, 0, W, H);
|
|
|
|
if (P.bulge > 0.001) {
|
|
var lobeX = cx + dirX * R * 0.72;
|
|
var lobeY = cy + dirY * R * 0.72;
|
|
var lobeR = R * (0.22 + 0.5 * P.bulge);
|
|
var lobe = ctx.createRadialGradient(lobeX, lobeY, 0, lobeX, lobeY, lobeR);
|
|
lobe.addColorStop(0, rgba(softRgb, 0.34 * P.bulge));
|
|
lobe.addColorStop(1, rgba(softRgb, 0));
|
|
ctx.fillStyle = lobe;
|
|
ctx.fillRect(0, 0, W, H);
|
|
}
|
|
|
|
// Grain field. Each speck drifts on its own integer-cycle sine
|
|
// (zero at u = 0 and u = 1) and is attracted toward the touch
|
|
// point with an exponential falloff: the material near the dot
|
|
// reaches for it, the far side barely stirs.
|
|
var TAU = Math.PI * 2;
|
|
for (var i = 0; i < grains.length; i += 1) {
|
|
var g = grains[i];
|
|
var driftX =
|
|
g.driftAmp * (Math.sin(TAU * g.driftCycles * u + g.phaseX) - Math.sin(g.phaseX));
|
|
var driftY =
|
|
g.driftAmp * (Math.sin(TAU * g.driftCycles * u + g.phaseY) - Math.sin(g.phaseY));
|
|
var gx = cx + g.x + driftX;
|
|
var gy = cy + g.y + driftY;
|
|
if (P.bulge > 0.001) {
|
|
var tx = touchX - gx;
|
|
var ty = touchY - gy;
|
|
var td = Math.hypot(tx, ty);
|
|
if (td > 0.5) {
|
|
var w = Math.exp(-td / sigma);
|
|
var pull = (bulgeAmp * P.bulge * w) / td;
|
|
gx += tx * pull;
|
|
gy += ty * pull;
|
|
}
|
|
}
|
|
var c = g.tone < 0.62 ? softRgb : fgRgb;
|
|
ctx.globalAlpha = g.dim * 0.85;
|
|
ctx.fillStyle = rgba(c, 1);
|
|
ctx.beginPath();
|
|
ctx.arc(gx, gy, g.size, 0, TAU);
|
|
ctx.fill();
|
|
}
|
|
ctx.globalAlpha = 1;
|
|
}
|
|
|
|
// Touch dot choreography, transforms only, px space of the host
|
|
// box (canvas coordinates divided by dpr).
|
|
var stageW = cssW;
|
|
var stageH = cssH;
|
|
var dotX = touchX / dpr;
|
|
var dotY = touchY / dpr;
|
|
// Enter and leave along the attraction axis, from off stage.
|
|
var away = Math.hypot(stageW, stageH) * 0.7;
|
|
var offX = dotX + dirX * away;
|
|
var offY = dotY + dirY * away;
|
|
|
|
gsap.set(stage, { opacity: 1, y: "0cqh" });
|
|
gsap.set(touchDot, { x: offX, y: offY, opacity: 0 });
|
|
|
|
var tl = gsap.timeline({
|
|
paused: true,
|
|
onUpdate: function () {
|
|
paint(tl.time());
|
|
},
|
|
});
|
|
|
|
// Anchor tween: spans the full authored duration so seeks into
|
|
// the hold keep tl.time() honest and onUpdate (the canvas
|
|
// repaint) fires for every eventful seek anywhere in [0, D].
|
|
tl.to({ p: 0 }, { p: 1, duration: duration, ease: "none" }, 0);
|
|
|
|
// The dot decel-arrives (power3.out: it arrives, it never
|
|
// passes through), dwells for the press, then accelerates away.
|
|
var arriveStart = Math.max(0, touchAt - 0.85);
|
|
tl.fromTo(
|
|
touchDot,
|
|
{ x: offX, y: offY, opacity: 0 },
|
|
{
|
|
x: dotX,
|
|
y: dotY,
|
|
opacity: 1,
|
|
duration: touchAt - arriveStart,
|
|
ease: "power3.out",
|
|
},
|
|
arriveStart,
|
|
);
|
|
tl.fromTo(
|
|
touchDot,
|
|
{ x: dotX, y: dotY, opacity: 1 },
|
|
{
|
|
x: offX,
|
|
y: offY,
|
|
opacity: 0,
|
|
duration: 0.55,
|
|
ease: "power2.in",
|
|
immediateRender: false,
|
|
},
|
|
cutAt,
|
|
);
|
|
|
|
// Attack: the truncated lean-in, cut mid-flight at the dot lift.
|
|
tl.fromTo(
|
|
P,
|
|
{ bulge: 0, lean: 0 },
|
|
{ bulge: bCut, lean: bCut, duration: ATTACK, ease: attackEase },
|
|
touchAt,
|
|
);
|
|
// Recovery: velocity-matched closed-form springs back to rest.
|
|
tl.fromTo(
|
|
P,
|
|
{ bulge: bCut },
|
|
{
|
|
bulge: 0,
|
|
duration: RECOVER,
|
|
ease: bulgeSpring,
|
|
immediateRender: false,
|
|
},
|
|
cutAt,
|
|
);
|
|
tl.fromTo(
|
|
P,
|
|
{ lean: bCut },
|
|
{
|
|
lean: 0,
|
|
duration: RECOVER,
|
|
ease: leanSpring,
|
|
immediateRender: false,
|
|
},
|
|
cutAt,
|
|
);
|
|
|
|
// HOLD: truly still. Drift is zero past IN_END by construction
|
|
// and both params are home, so every hold frame is identical.
|
|
|
|
// OUT: optional departure; exit none holds until the frame cuts.
|
|
if (exit === "up") {
|
|
tl.to(stage, { y: "-4cqh", duration: OUT, ease: "power2.in" }, OUT_START);
|
|
tl.to(stage, { opacity: 0, duration: OUT, ease: "power2.in" }, OUT_START);
|
|
} else if (exit === "fade") {
|
|
tl.to(stage, { opacity: 0, duration: OUT, ease: "power2.in" }, OUT_START);
|
|
}
|
|
|
|
tl.seek(0);
|
|
paint(0);
|
|
window.__timelines = window.__timelines || {};
|
|
window.__timelines["soft-blob-touch"] = tl;
|
|
})();
|
|
</script>
|
|
</div>
|
|
</template>
|
|
</body>
|
|
</html>
|
|
```
|
|
|
|
</VariablesExplorer>
|
|
|
|
## Install
|
|
|
|
<InstallCommand command="npx hyperframes add soft-blob-touch" item="soft-blob-touch" />
|
|
|
|
That writes one file: `compositions/components/soft-blob-touch.html`.
|
|
|
|
## Paste it into your composition
|
|
|
|
Open `compositions/components/soft-blob-touch.html` and copy what is inside into your own composition.
|
|
|
|
A component has no size or duration of its own. It takes both from the composition
|
|
you paste it into.
|
|
|
|
## Variables
|
|
|
|
Every one of these has a default, so the piece works untouched. Set the ones you
|
|
want to change on the element:
|
|
|
|
| Variable | Default | Accepts | What it does |
|
|
| --- | --- | --- | --- |
|
|
| `touch_x` | `66` | 8% to 92%, step 1% | Touch point, percent of host width. |
|
|
| `touch_y` | `38` | 8% to 92%, step 1% | Touch point, percent of host height. |
|
|
| `touch_at` | `1.6` | 0.9s to 10s, step 0.1s | Seconds from mount start when the dot makes contact. |
|
|
| `grain` | `fine` | `fine`, `coarse` | Speck register for the granular body. |
|
|
| `accent` | `green` | `green`, `blue`, `violet` | Body tint: green rides --brand, blue rides --accent, violet rides --accent-2. |
|
|
| `exit` | `none` | `none`, `fade`, `up` | Optional departure. Default none: the settled blob holds until the frame cuts. |
|
|
|
|
Set them with `data-variable-values` on the element that mounts it. These are the
|
|
defaults, so this behaves exactly like the preview above until you change one:
|
|
|
|
```html wrap
|
|
<div
|
|
data-composition-id="soft-blob-touch"
|
|
data-composition-src="compositions/components/soft-blob-touch.html"
|
|
data-variable-values='{"touch_x":66,"touch_y":38,"touch_at":1.6,"grain":"fine","accent":"green","exit":"none"}'
|
|
></div>
|
|
```
|
|
|
|
## Source
|
|
|
|
<Accordion title={`soft-blob-touch.html`}>
|
|
|
|
```html
|
|
<!doctype html>
|
|
<!--
|
|
soft-blob-touch: HyperFrames video primitive (product demo / material)
|
|
|
|
A granular soft blob idles with slow internal drift; a scripted touch dot
|
|
decel-arrives at a caller-positioned point; the blob deforms toward it
|
|
(an attraction bulge with mass), then recovers with an interruptible
|
|
spring once the dot retreats. The AI-orb material beat. Softness is the
|
|
whole point: the body is layered radial gradients plus a seeded grain
|
|
field, and nothing in the frame has a hard edge.
|
|
|
|
Reference: alexwidua 1702356241186476225 sheet-02 (granular blob leaning
|
|
toward a finger; fuzzy boundary, mass, recovery wobble).
|
|
|
|
Variables (declared in data-composition-variables below):
|
|
- touch_x, touch_y (numbers, percent of host box): where the dot lands.
|
|
- touch_at (seconds): when the dot makes contact. Clamped so the whole
|
|
deform and recover tail stays inside the clip.
|
|
- grain ("fine" | "coarse"): speck count and size for the body.
|
|
- accent ("green" | "blue" | "violet"): green rides --brand, blue rides
|
|
--accent, violet rides --accent-2.
|
|
- exit ("none" | "fade" | "up"): default none, the settled blob holds.
|
|
|
|
Envelope, fixed IN and OUT with elastic HOLD only (never timeScale):
|
|
IN ends when the recovery spring settles (touch_at + 1.57s); HOLD is
|
|
dead still (drift completes integer sine cycles and ends at exactly
|
|
zero by then); OUT = 0.45s only when exit is not none.
|
|
|
|
Deformation model (law L1, interruptible spring):
|
|
Two plain-object params (bulge, lean) feed ONE onUpdate painter. The
|
|
attack tween is the first 75 percent of a power2.out lean-in, cut
|
|
mid-flight when the dot lifts (analytic cut: the junction value AND
|
|
velocity are computed in closed form). The recovery tween's ease is a
|
|
closed-form underdamped spring whose initial velocity equals the cut
|
|
velocity, so the redirect preserves momentum exactly. Both tweens have
|
|
explicit endpoints; any seek order lands identical values.
|
|
|
|
Determinism (canvas 2D law, per particle-image-reveal):
|
|
One grain table is computed exactly once at build from fixed LCG seed
|
|
0x50f7b10b. Every painted frame is a pure function of (table, params,
|
|
timeline time). onUpdate clears and redraws from scratch; no
|
|
Math.random, no wall clock, no incremental state. Eventful seeks
|
|
(suppressEvents false) repaint identically in any order.
|
|
-->
|
|
<html
|
|
lang="en"
|
|
data-composition-id="soft-blob-touch"
|
|
data-composition-duration="4"
|
|
data-composition-variables='[
|
|
{ "id": "touch_x", "type": "number", "role": "layout", "label": "Touch X", "description": "Touch point, percent of host width.", "default": 66, "min": 8, "max": 92, "step": 1, "unit": "%" },
|
|
{ "id": "touch_y", "type": "number", "role": "layout", "label": "Touch Y", "description": "Touch point, percent of host height.", "default": 38, "min": 8, "max": 92, "step": 1, "unit": "%" },
|
|
{ "id": "touch_at", "type": "number", "role": "timing", "label": "Touch at", "description": "Seconds from mount start when the dot makes contact.", "default": 1.6, "min": 0.9, "max": 10, "step": 0.1, "unit": "s" },
|
|
{ "id": "grain", "type": "enum", "role": "style", "label": "Grain", "description": "Speck register for the granular body.", "default": "fine", "options": [{ "value": "fine", "label": "Fine" }, { "value": "coarse", "label": "Coarse" }] },
|
|
{ "id": "accent", "type": "enum", "role": "style", "label": "Accent", "description": "Body tint: green rides --brand, blue rides --accent, violet rides --accent-2.", "default": "green", "options": [{ "value": "green", "label": "Green" }, { "value": "blue", "label": "Blue" }, { "value": "violet", "label": "Violet" }] },
|
|
{ "id": "exit", "type": "enum", "role": "timing", "label": "Exit", "description": "Optional departure. Default none: the settled blob holds until the frame cuts.", "default": "none", "options": [{ "value": "none", "label": "None" }, { "value": "fade", "label": "Fade" }, { "value": "up", "label": "Up" }] }
|
|
]'
|
|
>
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<title>Soft Blob Touch</title>
|
|
</head>
|
|
<body>
|
|
<template>
|
|
<div id="root" data-composition-id="soft-blob-touch" data-duration="4" data-fps="30">
|
|
<style>
|
|
*,
|
|
*::before,
|
|
*::after {
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
#root {
|
|
position: absolute;
|
|
inset: 0;
|
|
overflow: hidden;
|
|
container-type: size;
|
|
isolation: isolate;
|
|
color: var(--fg, #f8fafc);
|
|
font-family: var(--font-body, "Inter", system-ui, sans-serif);
|
|
pointer-events: none;
|
|
}
|
|
|
|
.sbt-clip {
|
|
position: absolute;
|
|
inset: 0;
|
|
overflow: hidden;
|
|
}
|
|
|
|
.sbt-stage {
|
|
position: absolute;
|
|
inset: 0;
|
|
will-change: transform, opacity;
|
|
}
|
|
|
|
.sbt-canvas {
|
|
position: absolute;
|
|
inset: 0;
|
|
width: 100%;
|
|
height: 100%;
|
|
}
|
|
|
|
/* The touch dot: a soft disc with a gradient falloff, no hard rim.
|
|
Motion rides transforms only (px), never left or top. */
|
|
.sbt-touch {
|
|
position: absolute;
|
|
left: 0;
|
|
top: 0;
|
|
width: 4.6cqmin;
|
|
height: 4.6cqmin;
|
|
margin-left: -2.3cqmin;
|
|
margin-top: -2.3cqmin;
|
|
border-radius: 50%;
|
|
background: radial-gradient(
|
|
circle at 42% 38%,
|
|
color-mix(in srgb, var(--fg, #f8fafc) 96%, transparent) 0%,
|
|
color-mix(in srgb, var(--fg, #f8fafc) 78%, transparent) 34%,
|
|
color-mix(in srgb, var(--fg, #f8fafc) 26%, transparent) 62%,
|
|
transparent 78%
|
|
);
|
|
will-change: transform, opacity;
|
|
}
|
|
</style>
|
|
|
|
<div
|
|
id="soft-blob-touch-clip"
|
|
class="sbt-clip clip"
|
|
data-start="0"
|
|
data-duration="4"
|
|
data-track-index="0"
|
|
>
|
|
<div class="sbt-stage">
|
|
<canvas class="sbt-canvas" aria-hidden="true"></canvas>
|
|
<div class="sbt-touch" aria-hidden="true"></div>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/gsap@3.14.2/dist/gsap.min.js"></script>
|
|
<script>
|
|
(function () {
|
|
"use strict";
|
|
|
|
var root = document.getElementById("root");
|
|
var stage = root.querySelector(".sbt-stage");
|
|
var canvas = root.querySelector(".sbt-canvas");
|
|
var touchDot = root.querySelector(".sbt-touch");
|
|
var vars =
|
|
window.__hyperframes && window.__hyperframes.getVariables
|
|
? window.__hyperframes.getVariables()
|
|
: {};
|
|
|
|
function num(value, fallback, min, max) {
|
|
var n = Number(value);
|
|
if (!isFinite(n)) n = fallback;
|
|
return Math.max(min, Math.min(max, n));
|
|
}
|
|
|
|
var grain = vars.grain === "coarse" ? "coarse" : "fine";
|
|
var exit = vars.exit === "fade" || vars.exit === "up" ? vars.exit : "none";
|
|
// Each enum choice routes to a DIFFERENT contract token so the
|
|
// variable stays meaningful under a theme.
|
|
var accentColors = {
|
|
green: "var(--brand, #71f5a7)",
|
|
blue: "var(--accent, #61a8ff)",
|
|
violet: "var(--accent-2, #c5a3ff)",
|
|
};
|
|
var accent = Object.prototype.hasOwnProperty.call(accentColors, vars.accent)
|
|
? vars.accent
|
|
: "green";
|
|
// The bundler mirrors composition variables as scoped CSS custom
|
|
// props, so this unit's own accent variable shadows the contract
|
|
// --accent token inside the subtree ("blue" is a valid CSS color
|
|
// and would render pure blue). When the shadow is present, fall
|
|
// back to the literal contract value instead of var(--accent).
|
|
var computedAccent = getComputedStyle(root).getPropertyValue("--accent").trim();
|
|
if (
|
|
computedAccent === "green" ||
|
|
computedAccent === "blue" ||
|
|
computedAccent === "violet"
|
|
) {
|
|
accentColors.blue = "#61a8ff";
|
|
}
|
|
|
|
// Envelope. The deform tail is ATTACK + RECOVER after contact;
|
|
// clamp touch_at so the spring settles inside the clip.
|
|
var ATTACK_NAT = 0.55; // natural length of the uncut lean-in
|
|
var CUT_FRAC = 0.75; // the dot lifts at 75 percent of it
|
|
var ATTACK = ATTACK_NAT * CUT_FRAC;
|
|
var RECOVER = 1.15;
|
|
var duration = Math.max(0.001, parseFloat(root.dataset.duration || "4"));
|
|
var OUT = exit === "none" ? 0 : 0.45;
|
|
var maxTouch = Math.max(0.9, duration - (ATTACK + RECOVER) - OUT - 0.05);
|
|
var touchAt = num(vars.touch_at, 1.6, 0.9, maxTouch);
|
|
var cutAt = touchAt + ATTACK;
|
|
var IN_END = cutAt + RECOVER;
|
|
var OUT_START = IN_END + Math.max(0, duration - IN_END - OUT);
|
|
|
|
// Canvas raster basis is fixed once at mount (elastic root: the
|
|
// host box decides the resolution; same host, same raster).
|
|
var dpr = Math.min(2, Math.max(1, Number(window.devicePixelRatio) || 1));
|
|
var box = root.getBoundingClientRect();
|
|
var cssW = Math.max(1, Math.round(box.width) || 640);
|
|
var cssH = Math.max(1, Math.round(box.height) || 360);
|
|
canvas.width = Math.round(cssW * dpr);
|
|
canvas.height = Math.round(cssH * dpr);
|
|
var ctx = canvas.getContext("2d");
|
|
var W = canvas.width;
|
|
var H = canvas.height;
|
|
var minDim = Math.min(W, H);
|
|
|
|
var touchX = (num(vars.touch_x, 66, 8, 92) / 100) * W;
|
|
var touchY = (num(vars.touch_y, 38, 8, 92) / 100) * H;
|
|
var centerX = W * 0.5;
|
|
var centerY = H * 0.5;
|
|
var R = minDim * 0.26;
|
|
|
|
// Direction of attraction, guarded for a touch at dead center.
|
|
var dxT = touchX - centerX;
|
|
var dyT = touchY - centerY;
|
|
var distT = Math.hypot(dxT, dyT);
|
|
var dirX = distT > 1 ? dxT / distT : 0.7071;
|
|
var dirY = distT > 1 ? dyT / distT : -0.7071;
|
|
|
|
// Resolve accent and fg to concrete rgb once at mount so canvas
|
|
// fills never depend on style recalc during seeks. Mixing happens
|
|
// numerically here (computed color-mix strings are not parseable
|
|
// across engines).
|
|
function probeColor(cssColor, fallback) {
|
|
var probe = root.ownerDocument.createElement("span");
|
|
probe.style.color = cssColor;
|
|
root.appendChild(probe);
|
|
var out = getComputedStyle(probe).color || fallback;
|
|
probe.remove();
|
|
var m = out.match(/rgba?\(\s*([\d.]+)[,\s]+([\d.]+)[,\s]+([\d.]+)/);
|
|
if (!m) {
|
|
m = fallback.match(/rgba?\(\s*([\d.]+)[,\s]+([\d.]+)[,\s]+([\d.]+)/);
|
|
}
|
|
return m ? [Number(m[1]), Number(m[2]), Number(m[3])] : [113, 245, 167];
|
|
}
|
|
var accentRgb = probeColor(accentColors[accent], "rgb(113, 245, 167)");
|
|
var fgRgb = probeColor("var(--fg, #f8fafc)", "rgb(248, 250, 252)");
|
|
function mix(a, b, t) {
|
|
return [
|
|
Math.round(a[0] + (b[0] - a[0]) * t),
|
|
Math.round(a[1] + (b[1] - a[1]) * t),
|
|
Math.round(a[2] + (b[2] - a[2]) * t),
|
|
];
|
|
}
|
|
function rgba(c, a) {
|
|
return "rgba(" + c[0] + "," + c[1] + "," + c[2] + "," + a + ")";
|
|
}
|
|
var bodyRgb = mix(accentRgb, fgRgb, 0.18);
|
|
var softRgb = mix(accentRgb, fgRgb, 0.55);
|
|
|
|
// The grain table: computed exactly once, then only read.
|
|
var counts = { fine: 1500, coarse: 760 };
|
|
var sizes = { fine: 0.0055, coarse: 0.0102 };
|
|
var COUNT = counts[grain];
|
|
var SPECK = sizes[grain] * minDim;
|
|
var grains = (function () {
|
|
var state = 0x50f7b10b;
|
|
function next() {
|
|
state = (Math.imul(1664525, state) + 1013904223) >>> 0;
|
|
return state / 4294967296;
|
|
}
|
|
var rows = [];
|
|
for (var i = 0; i < COUNT; i += 1) {
|
|
// Radial distribution with a fuzzy tail past R: density thins
|
|
// toward the boundary and alpha fades it out, so the edge is
|
|
// granular vapor, never a line.
|
|
var rr = Math.pow(next(), 0.55) * R * 1.16;
|
|
var th = next() * Math.PI * 2;
|
|
var edge = Math.max(0, Math.min(1, (1.16 - rr / R) / 0.42));
|
|
rows.push({
|
|
x: Math.cos(th) * rr,
|
|
y: Math.sin(th) * rr * 0.94,
|
|
size: SPECK * (0.5 + 0.9 * next()),
|
|
dim: (0.3 + 0.7 * next()) * edge,
|
|
tone: next(),
|
|
driftAmp: (0.008 + 0.014 * next()) * minDim,
|
|
driftCycles: next() < 0.5 ? 1 : 2,
|
|
phaseX: next() * Math.PI * 2,
|
|
phaseY: next() * Math.PI * 2,
|
|
});
|
|
}
|
|
return rows;
|
|
})();
|
|
|
|
function clamp01(v) {
|
|
return v < 0 ? 0 : v > 1 ? 1 : v;
|
|
}
|
|
|
|
// Deformation params. Attack lifts both toward CUT value; the
|
|
// recovery springs them home. The painter owns all amplitudes.
|
|
var P = { bulge: 0, lean: 0 };
|
|
var bCut = 1 - Math.pow(1 - CUT_FRAC, 2); // power2.out at the cut
|
|
var vCut = (2 * (1 - CUT_FRAC)) / ATTACK_NAT; // slope there, per s
|
|
var attackEase = function (p) {
|
|
return (1 - Math.pow(1 - p * CUT_FRAC, 2)) / bCut;
|
|
};
|
|
// Closed-form underdamped spring x(s), x(0) = 1, x'(0) = vCut/bCut
|
|
// (velocity preserved across the cut), corrected by a linear ramp
|
|
// so x(RECOVER) is exactly zero. Higher frequency for the local
|
|
// bulge, lower for the whole-mass lean: the surface snaps back
|
|
// faster than the body.
|
|
function springEase(lambda, omega) {
|
|
var v0 = vCut / bCut;
|
|
var c2 = (v0 + lambda) / omega;
|
|
function x(s) {
|
|
return Math.exp(-lambda * s) * (Math.cos(omega * s) + c2 * Math.sin(omega * s));
|
|
}
|
|
var xEnd = x(RECOVER);
|
|
return function (p) {
|
|
var s = p * RECOVER;
|
|
return 1 - (x(s) - (s / RECOVER) * xEnd);
|
|
};
|
|
}
|
|
var bulgeSpring = springEase(4.2, Math.PI * 2 * 2.2);
|
|
var leanSpring = springEase(3.6, Math.PI * 2 * 1.5);
|
|
|
|
// Pure repaint: clear, then rebuild the whole frame from
|
|
// (grain table, P, t). Drift phase u completes integer sine
|
|
// cycles over [0, IN_END] and is exactly zero from IN_END on,
|
|
// so the HOLD frame is dead still.
|
|
var sigma = R * 0.85;
|
|
var bulgeAmp = R * 0.62;
|
|
var leanAmp = minDim * 0.045;
|
|
function paint(t) {
|
|
ctx.clearRect(0, 0, W, H);
|
|
var u = clamp01(t / IN_END);
|
|
var lx = leanAmp * P.lean * dirX;
|
|
var ly = leanAmp * P.lean * dirY;
|
|
var cx = centerX + lx;
|
|
var cy = centerY + ly;
|
|
|
|
// Layered radial gradients: wide aura, mid glow, dense core,
|
|
// and a bulge lobe that swells toward the touch point.
|
|
var aura = ctx.createRadialGradient(cx, cy, 0, cx, cy, R * 1.9);
|
|
aura.addColorStop(0, rgba(accentRgb, 0.16));
|
|
aura.addColorStop(0.55, rgba(accentRgb, 0.06));
|
|
aura.addColorStop(1, rgba(accentRgb, 0));
|
|
ctx.fillStyle = aura;
|
|
ctx.fillRect(0, 0, W, H);
|
|
|
|
var mid = ctx.createRadialGradient(cx, cy, 0, cx, cy, R * 1.12);
|
|
mid.addColorStop(0, rgba(bodyRgb, 0.34));
|
|
mid.addColorStop(0.62, rgba(bodyRgb, 0.16));
|
|
mid.addColorStop(1, rgba(bodyRgb, 0));
|
|
ctx.fillStyle = mid;
|
|
ctx.fillRect(0, 0, W, H);
|
|
|
|
var core = ctx.createRadialGradient(
|
|
cx - R * 0.12,
|
|
cy - R * 0.14,
|
|
0,
|
|
cx,
|
|
cy,
|
|
R * 0.62,
|
|
);
|
|
core.addColorStop(0, rgba(softRgb, 0.4));
|
|
core.addColorStop(1, rgba(softRgb, 0));
|
|
ctx.fillStyle = core;
|
|
ctx.fillRect(0, 0, W, H);
|
|
|
|
if (P.bulge > 0.001) {
|
|
var lobeX = cx + dirX * R * 0.72;
|
|
var lobeY = cy + dirY * R * 0.72;
|
|
var lobeR = R * (0.22 + 0.5 * P.bulge);
|
|
var lobe = ctx.createRadialGradient(lobeX, lobeY, 0, lobeX, lobeY, lobeR);
|
|
lobe.addColorStop(0, rgba(softRgb, 0.34 * P.bulge));
|
|
lobe.addColorStop(1, rgba(softRgb, 0));
|
|
ctx.fillStyle = lobe;
|
|
ctx.fillRect(0, 0, W, H);
|
|
}
|
|
|
|
// Grain field. Each speck drifts on its own integer-cycle sine
|
|
// (zero at u = 0 and u = 1) and is attracted toward the touch
|
|
// point with an exponential falloff: the material near the dot
|
|
// reaches for it, the far side barely stirs.
|
|
var TAU = Math.PI * 2;
|
|
for (var i = 0; i < grains.length; i += 1) {
|
|
var g = grains[i];
|
|
var driftX =
|
|
g.driftAmp * (Math.sin(TAU * g.driftCycles * u + g.phaseX) - Math.sin(g.phaseX));
|
|
var driftY =
|
|
g.driftAmp * (Math.sin(TAU * g.driftCycles * u + g.phaseY) - Math.sin(g.phaseY));
|
|
var gx = cx + g.x + driftX;
|
|
var gy = cy + g.y + driftY;
|
|
if (P.bulge > 0.001) {
|
|
var tx = touchX - gx;
|
|
var ty = touchY - gy;
|
|
var td = Math.hypot(tx, ty);
|
|
if (td > 0.5) {
|
|
var w = Math.exp(-td / sigma);
|
|
var pull = (bulgeAmp * P.bulge * w) / td;
|
|
gx += tx * pull;
|
|
gy += ty * pull;
|
|
}
|
|
}
|
|
var c = g.tone < 0.62 ? softRgb : fgRgb;
|
|
ctx.globalAlpha = g.dim * 0.85;
|
|
ctx.fillStyle = rgba(c, 1);
|
|
ctx.beginPath();
|
|
ctx.arc(gx, gy, g.size, 0, TAU);
|
|
ctx.fill();
|
|
}
|
|
ctx.globalAlpha = 1;
|
|
}
|
|
|
|
// Touch dot choreography, transforms only, px space of the host
|
|
// box (canvas coordinates divided by dpr).
|
|
var stageW = cssW;
|
|
var stageH = cssH;
|
|
var dotX = touchX / dpr;
|
|
var dotY = touchY / dpr;
|
|
// Enter and leave along the attraction axis, from off stage.
|
|
var away = Math.hypot(stageW, stageH) * 0.7;
|
|
var offX = dotX + dirX * away;
|
|
var offY = dotY + dirY * away;
|
|
|
|
gsap.set(stage, { opacity: 1, y: "0cqh" });
|
|
gsap.set(touchDot, { x: offX, y: offY, opacity: 0 });
|
|
|
|
var tl = gsap.timeline({
|
|
paused: true,
|
|
onUpdate: function () {
|
|
paint(tl.time());
|
|
},
|
|
});
|
|
|
|
// Anchor tween: spans the full authored duration so seeks into
|
|
// the hold keep tl.time() honest and onUpdate (the canvas
|
|
// repaint) fires for every eventful seek anywhere in [0, D].
|
|
tl.to({ p: 0 }, { p: 1, duration: duration, ease: "none" }, 0);
|
|
|
|
// The dot decel-arrives (power3.out: it arrives, it never
|
|
// passes through), dwells for the press, then accelerates away.
|
|
var arriveStart = Math.max(0, touchAt - 0.85);
|
|
tl.fromTo(
|
|
touchDot,
|
|
{ x: offX, y: offY, opacity: 0 },
|
|
{
|
|
x: dotX,
|
|
y: dotY,
|
|
opacity: 1,
|
|
duration: touchAt - arriveStart,
|
|
ease: "power3.out",
|
|
},
|
|
arriveStart,
|
|
);
|
|
tl.fromTo(
|
|
touchDot,
|
|
{ x: dotX, y: dotY, opacity: 1 },
|
|
{
|
|
x: offX,
|
|
y: offY,
|
|
opacity: 0,
|
|
duration: 0.55,
|
|
ease: "power2.in",
|
|
immediateRender: false,
|
|
},
|
|
cutAt,
|
|
);
|
|
|
|
// Attack: the truncated lean-in, cut mid-flight at the dot lift.
|
|
tl.fromTo(
|
|
P,
|
|
{ bulge: 0, lean: 0 },
|
|
{ bulge: bCut, lean: bCut, duration: ATTACK, ease: attackEase },
|
|
touchAt,
|
|
);
|
|
// Recovery: velocity-matched closed-form springs back to rest.
|
|
tl.fromTo(
|
|
P,
|
|
{ bulge: bCut },
|
|
{
|
|
bulge: 0,
|
|
duration: RECOVER,
|
|
ease: bulgeSpring,
|
|
immediateRender: false,
|
|
},
|
|
cutAt,
|
|
);
|
|
tl.fromTo(
|
|
P,
|
|
{ lean: bCut },
|
|
{
|
|
lean: 0,
|
|
duration: RECOVER,
|
|
ease: leanSpring,
|
|
immediateRender: false,
|
|
},
|
|
cutAt,
|
|
);
|
|
|
|
// HOLD: truly still. Drift is zero past IN_END by construction
|
|
// and both params are home, so every hold frame is identical.
|
|
|
|
// OUT: optional departure; exit none holds until the frame cuts.
|
|
if (exit === "up") {
|
|
tl.to(stage, { y: "-4cqh", duration: OUT, ease: "power2.in" }, OUT_START);
|
|
tl.to(stage, { opacity: 0, duration: OUT, ease: "power2.in" }, OUT_START);
|
|
} else if (exit === "fade") {
|
|
tl.to(stage, { opacity: 0, duration: OUT, ease: "power2.in" }, OUT_START);
|
|
}
|
|
|
|
tl.seek(0);
|
|
paint(0);
|
|
window.__timelines = window.__timelines || {};
|
|
window.__timelines["soft-blob-touch"] = tl;
|
|
})();
|
|
</script>
|
|
</div>
|
|
</template>
|
|
</body>
|
|
</html>
|
|
```
|
|
|
|
</Accordion>
|
|
|
|
{/* hf:generated-footer */}
|
|
|
|
Tagged `motion-primitive` `product-demo` `material` `blob` `touch` `grain`.
|
|
|
|
## Related topics
|
|
|
|
- [Browse the complete Catalog](/catalog)
|
|
- [Add assets and Catalog items in Studio](/studio/assets-and-blocks)
|
|
- [Build a richer composition](/go-further)
|