Back to the app
The code
Jelly Cat by GPT-6.2 Sol
Exactly as the AI wrote it. Shown as text, so nothing runs on this page.
index.html
works · auto-checked (Checked by an automated pass. Not hand-played yet.)<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<meta name="theme-color" content="#f8f4ed">
<title>Jelly Cat · Jelly Lab</title>
<style>
:root {
color-scheme: light;
--paper: #f8f4ed;
--ink: #30221b;
--muted: #6e5c50;
--line: #e8dcd0;
--accent: #bd3e1c;
--orange: #de5b32;
font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; min-width: 280px; background: var(--paper); color: var(--ink); }
button, input { font: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
.shell { width: min(1248px, calc(100% - 96px)); margin-inline: auto; }
.topbar { border-bottom: 1px solid var(--line); }
.bar { height: 74px; display: flex; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 11px; font-size: 22px; font-weight: 750; letter-spacing: -.055em; }
.brand-mark { display: grid; place-items: center; width: 37px; height: 37px; border-radius: 12px; color: #fff9f0; background: var(--accent); }
.sound {
display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 15px;
border-radius: 100px; border: 1px solid #e5d6c9; background: #fdf9f3; color: #50372b;
font-size: 13px; font-weight: 680; white-space: nowrap; transition: background .18s;
}
.sound:hover, .reset:hover { background: #fff9ed; }
.sound[aria-pressed="true"] .mute-mark, .sound[aria-pressed="false"] .sound-waves { display: none; }
.layout {
display: grid; grid-template-columns: minmax(292px, 1fr) minmax(0, 2.28fr);
grid-template-areas: "intro stage" "controls stage"; grid-template-rows: auto 1fr;
gap: 31px 52px; padding-block: 46px 40px;
}
.intro { grid-area: intro; padding-top: clamp(28px, 5.2vh, 62px); }
h1 { margin: 0; font-size: clamp(54px, 5.45vw, 82px); font-weight: 760; line-height: .99; letter-spacing: -.083em; }
h1 em { display: block; width: max-content; color: var(--accent); font: italic 400 1.07em/.99 Georgia, "Times New Roman", serif; letter-spacing: -.077em; }
.intro p { margin: 24px 0 0; max-width: 295px; font-size: 16px; line-height: 1.68; color: var(--muted); }
.stage {
grid-area: stage; position: relative; isolation: isolate; overflow: hidden; height: clamp(500px, 70vh, 655px);
border: 1px solid #ead7c4; border-radius: 29px; touch-action: none; cursor: grab; user-select: none;
background: radial-gradient(ellipse at 46% 36%, #fff5e6, #f0dac4 85%);
box-shadow: 0 18px 45px -32px #8c513d72;
}
.stage.grabbing { cursor: grabbing; }
.stage canvas { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }
.stage canvas[hidden] { display: none; }
.status {
position: absolute; top: 20px; left: 20px; min-height: 38px; display: inline-flex; align-items: center; gap: 9px;
padding: 0 13px; border: 1px solid #fff8eacf; border-radius: 100px;
background: #fff8edcf; color: #624635; font-size: 12px; font-weight: 680; pointer-events: none;
}
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #d46b42; box-shadow: 0 0 0 3px #d46b421c; }
.stage.purring .status-dot { animation: purr-dot .48s ease-in-out infinite alternate; }
@keyframes purr-dot { to { box-shadow: 0 0 0 5px #d46b4232; } }
.reset {
position: absolute; right: 19px; top: 18px; width: 44px; height: 44px; display: grid; place-items: center;
border: 1px solid #fff8eacf; border-radius: 50%; background: #fff8edcf; color: #624635; transition: background .18s;
}
.reset:active, .sound:active { transform: translateY(1px); }
.demo-hand { position: absolute; left: 0; top: 0; opacity: 0; pointer-events: none; transition: opacity .18s; }
.demo-hand.visible { opacity: 1; }
.demo-hand i {
position: absolute; width: 28px; height: 28px; left: -14px; top: -14px; border: 2px solid #fff9e9;
border-radius: 50%; background: #c7462c63; box-shadow: 0 0 0 2px #77311b45, 0 2px 8px #63251c47;
transition: transform .17s, background .17s;
}
.demo-hand.down i { transform: scale(.71); background: #c7462cce; }
.controls { grid-area: controls; display: flex; flex-direction: column; gap: 13px; align-self: start; }
.texture-card { padding: 18px 18px 15px; border: 1px solid var(--line); border-radius: 18px; background: #fdf9f3; }
.texture-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.texture-header label { font-size: 14px; font-weight: 730; }
.texture-value { padding: 5px 9px; border-radius: 7px; background: #f8e5d9; color: #903b23; font-size: 11px; font-weight: 750; }
.texture-range {
--mix: 48%; appearance: none; width: 100%; height: 34px; margin: 8px 0 0;
background: transparent; display: block; accent-color: var(--accent); cursor: pointer;
}
.texture-range::-webkit-slider-runnable-track { height: 6px; border-radius: 20px; background: linear-gradient(to right, #e18b68 0%, #cf502a var(--mix), #eaded3 var(--mix), #eaded3 100%); }
.texture-range::-moz-range-track { height: 6px; border-radius: 20px; background: linear-gradient(to right, #e18b68 0%, #cf502a var(--mix), #eaded3 var(--mix), #eaded3 100%); }
.texture-range::-webkit-slider-thumb {
appearance: none; width: 21px; height: 21px; margin-top: -7.5px; border: 3px solid #fffaf2;
border-radius: 50%; background: #c94925; box-shadow: 0 0 0 1px #c7532d, 0 2px 5px #8c3c3147;
}
.texture-range::-moz-range-thumb {
width: 15px; height: 15px; border: 3px solid #fffaf2; border-radius: 50%; background: #c94925;
box-shadow: 0 0 0 1px #c7532d, 0 2px 5px #8c3c3147;
}
.endpoints { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; font-weight: 570; }
.drop {
display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 55px; width: 100%;
padding: 0 16px; border: 1px solid #a73519; border-radius: 14px; color: #fff9ef; background: var(--accent);
box-shadow: 0 4px 0 #a73519, 0 9px 16px -11px #9a3c29; font-size: 15px; font-weight: 740;
transition: background .18s, transform .14s, box-shadow .14s;
}
.drop:hover { background: #aa3417; }
.drop:active { transform: translateY(3px); box-shadow: 0 1px 0 #a73519; }
@media (max-width: 1040px) {
.shell { width: calc(100% - 56px); }
.layout { column-gap: 30px; grid-template-columns: minmax(250px, 1fr) minmax(0, 1.95fr); }
h1 { font-size: clamp(50px, 6.4vw, 68px); }
}
@media (max-width: 720px) {
.shell { width: calc(100% - 32px); }
.bar { height: 62px; }
.brand-mark { width: 34px; height: 34px; }
.brand { font-size: 20px; }
.layout { grid-template-columns: minmax(0, 1fr); grid-template-areas: "intro" "stage" "controls"; gap: 19px; padding-block: 22px 29px; }
.intro { padding: 0 1px; }
h1 { font-size: clamp(41px, 11.3vw, 68px); }
h1 em { display: inline; }
.intro p { margin-top: 11px; font-size: 14px; line-height: 1.48; max-width: 390px; }
.stage { height: clamp(318px, 92vw, 460px); border-radius: 22px; }
.status { top: 12px; left: 12px; min-height: 34px; }
.reset { top: 9px; right: 10px; }
.controls { gap: 11px; }
.texture-card { padding: 14px 16px 12px; }
.drop { min-height: 51px; }
}
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after { transition-duration: .01ms !important; }
.stage.purring .status-dot { animation: none; }
}
</style>
</head>
<body>
<header class="topbar">
<div class="shell bar">
<div class="brand">
<span class="brand-mark" aria-hidden="true">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none">
<path d="M4.8 12.7 4.5 6c0-.7.7-1 1.2-.6L9.2 8a9 9 0 0 1 5.6 0l3.5-2.6c.5-.4 1.2-.1 1.2.6l-.3 6.7c0 3-2.9 5.2-7.2 5.2s-7.2-2.2-7.2-5.2Z" stroke="currentColor" stroke-width="1.55" stroke-linejoin="round"/>
<path d="M9.2 12.5v.8m5.6-.8v.8m-3.7 1.7.9.5.9-.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
</span>
<span>jelly lab</span>
</div>
<button type="button" class="sound" id="sound" aria-pressed="true" aria-label="Sound">
<svg width="17" height="17" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<path d="M11 5 6 9H3v6h3l5 4V5Z"/>
<path class="sound-waves" d="M15 9c1.6 1.8 1.6 4.2 0 6m3-8c2.7 2.8 2.7 7.2 0 10"/>
<path class="mute-mark" d="m16 10 5 5m0-5-5 5"/>
</svg>
<span id="soundLabel">Sound on</span>
</button>
</div>
</header>
<main class="shell layout">
<section class="intro" aria-labelledby="title">
<h1 id="title">Meet <em>Jelly Cat.</em></h1>
<p>Press to squish. Tug its ears, cheeks, or tail. Rub its head and it’ll purr.</p>
</section>
<section class="stage" id="stage" aria-label="Jelly Cat play area">
<canvas id="glCanvas" role="img" aria-label="A glossy orange jelly cat sitting on a cream plate"></canvas>
<canvas id="paintCanvas" role="img" aria-label="An orange jelly cat sitting on a cream plate" hidden></canvas>
<div class="status" role="status"><span class="status-dot" aria-hidden="true"></span><span id="status">Ready to play</span></div>
<button class="reset" id="reset" type="button" aria-label="Reset cat and texture" title="Reset cat and texture">
<svg width="19" height="19" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<path d="M4 11a8 8 0 1 1 2.3 6.6M4 5v6h6"/>
</svg>
</button>
<div class="demo-hand" id="demoHand" aria-hidden="true"><i></i></div>
</section>
<section class="controls" aria-label="Jelly controls">
<div class="texture-card">
<div class="texture-header">
<label for="firmness">Jelly texture</label>
<output class="texture-value" id="textureValue" for="firmness">Bouncy</output>
</div>
<input class="texture-range" type="range" id="firmness" min="0" max="100" step="1" value="48">
<div class="endpoints"><span>Soft pudding</span><span>Firm gummy</span></div>
</div>
<button class="drop" id="drop" type="button">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 3v12m-5-5 5 5 5-5M5 20h14"/></svg>
Drop the cat
</button>
</section>
</main>
<script type="x-shader/x-vertex" id="quad-vertex">
precision highp float;
attribute vec2 aPosition;
varying vec2 vUV;
void main() {
vUV = aPosition * .5 + .5;
gl_Position = vec4(aPosition, 0., 1.);
}
</script>
<script type="x-shader/x-fragment" id="studio-fragment">
precision highp float;
varying vec2 vUV;
uniform vec2 uSpan;
uniform vec3 uTarget, uRight, uUp, uView;
void main() {
vec2 screen = (vUV * 2. - 1.) * uSpan;
vec3 origin = uTarget + screen.x * uRight + screen.y * uUp;
vec3 floorPoint = origin + uView * ((-.142 - origin.y) / uView.y);
vec2 p = floorPoint.xz - vec2(.22, .025);
vec2 halo = (vUV - vec2(.43,.65)) * vec2(1.26, 1.);
float light = exp(-3.65 * dot(halo,halo));
vec3 color = mix(vec3(.929,.831,.733), vec3(1.,.962,.902), light);
color = mix(color, vec3(.990,.924,.843), (1. - vUV.y) * .35);
vec2 penumbra = (p - vec2(.39,-.31)) / vec2(2.06,1.70);
float broad = exp(-1.44 * dot(penumbra,penumbra));
float contact = 1. - smoothstep(1.26,2.19,length(p));
color *= 1. - vec3(.17,.228,.284) * (broad * .71 + contact * .24);
float grain = fract(sin(dot(gl_FragCoord.xy,vec2(12.9898,78.233))) * 43758.5453);
gl_FragColor = vec4(color + (grain - .5) * .011,1.);
}
</script>
<script type="x-shader/x-vertex" id="plate-vertex">
precision highp float;
attribute vec3 aPosition, aNormal;
uniform vec2 uSpan;
uniform vec3 uTarget, uRight, uUp, uView;
varying vec3 vWorld, vNormal;
void main() {
vWorld = aPosition;
vNormal = aNormal;
vec3 p = aPosition - uTarget;
gl_Position = vec4(dot(p,uRight)/uSpan.x,dot(p,uUp)/uSpan.y,-dot(p,uView)/9.,1.);
}
</script>
<script type="x-shader/x-fragment" id="plate-fragment">
precision highp float;
uniform vec3 uView;
uniform float uHeight;
varying vec3 vWorld, vNormal;
void main() {
vec3 n = normalize(vNormal);
vec3 light = normalize(vec3(-.64,.93,.70));
float lit = .49 + .51 * max(0.,dot(light,n));
float r = length(vWorld.xz - vec2(.22,.025));
vec3 porcelain = mix(vec3(.839,.716,.606),vec3(.992,.943,.858),lit);
porcelain = mix(porcelain,vec3(1.,.973,.920),smoothstep(.30,.95,n.y)*.57);
float rim = 1. - smoothstep(.008,.020,abs(r-1.854));
porcelain = mix(porcelain,vec3(.768,.588,.455),rim * .28 * smoothstep(.56,.90,n.y));
float rimLight = 1. - smoothstep(.008,.021,abs(r-1.910));
porcelain += rimLight * .034 * smoothstep(.30,.92,n.y);
float gloss = pow(max(0.,dot(n,normalize(light+uView))),24.);
porcelain += vec3(.092,.084,.068)*gloss;
vec2 q = (vWorld.xz - vec2(.15,.22)) / (vec2(1.10,.78) + uHeight * .30);
float shadow = exp(-1.36*dot(q,q)) / (1. + uHeight * 1.65);
vec2 tail = (vWorld.xz - vec2(1.69,-.22)) / vec2(.60,.40);
float tailShadow = exp(-1.48*dot(tail,tail)) / (1. + uHeight * 3.);
porcelain *= 1. - vec3(.145,.190,.230)*(shadow + tailShadow*.42)*max(0.,n.y);
vec2 hot = (vWorld.xz - vec2(.38,.78)) / vec2(.96,.43);
float caustic = exp(-1.58*dot(hot,hot))/(1. + uHeight*4.);
porcelain = mix(porcelain, vec3(1.,.659,.355),caustic*.28*max(0.,n.y));
gl_FragColor = vec4(porcelain,1.);
}
</script>
<script type="x-shader/x-vertex" id="jelly-vertex">
precision highp float;
attribute vec3 aPosition, aNormal;
uniform vec2 uSpan, uWave;
uniform vec3 uTarget, uRight, uUp, uView;
uniform vec4 uMotion, uPress;
uniform vec3 uPull[5];
varying float vDepth;
#ifndef BACK_PASS
varying vec3 vWorldNormal, vRest;
#endif
float weight(vec3 p, vec3 center, vec3 width) {
vec3 q = (p - center) / width;
float w = max(0.,1.-dot(q,q));
return w*w;
}
vec3 warp(vec3 p) {
vec3 rest = p;
float upper = smoothstep(.06,2.90,p.y);
float ripple = dot(uWave,vec2(cos(5.3*p.y),sin(5.3*p.y)));
p.x *= 1. + uMotion.x * .60;
p.z *= 1. + uMotion.x * .54;
p.y = .063 + (p.y - .063) * (1. - uMotion.x * .91);
p.x += uMotion.y * upper * 1.36 + ripple * upper * .085;
p.z += uMotion.z * upper + ripple * upper * .095;
p.y += ripple * upper * .053;
float ear = smoothstep(2.69,3.26,rest.y)*smoothstep(.22,.70,abs(rest.x));
p += ear * mix(uPull[0],uPull[1],step(0.,rest.x));
p += uPull[2] * weight(rest,vec3(-.73,2.00,.71),vec3(.75,.65,.81));
p += uPull[3] * weight(rest,vec3( .73,2.00,.71),vec3(.75,.65,.81));
p += uPull[4] * smoothstep(.89,1.86,rest.x) * (.64+.36*smoothstep(.43,1.29,rest.y));
float press = uPress.w * weight(rest,uPress.xyz,vec3(.71,.78,.93));
p -= vec3(.11*rest.x,.16,1.)*press;
p.y = max(.058,p.y) + uMotion.w;
return p;
}
void main() {
vec3 warped = warp(aPosition);
vec3 p = warped - uTarget;
gl_Position = vec4(dot(p,uRight)/uSpan.x,dot(p,uUp)/uSpan.y,-dot(p,uView)/9.,1.);
vDepth = .5 + gl_Position.z * .5;
#ifndef BACK_PASS
vec3 n = aNormal;
vec3 t = normalize(cross(abs(n.y) > .93 ? vec3(1.,0.,0.) : vec3(0.,1.,0.), n));
vec3 b = cross(n,t);
vec3 wt = warp(aPosition + t * .028) - warped;
vec3 wb = warp(aPosition + b * .028) - warped;
vec3 wn = cross(wt,wb);
vWorldNormal = dot(wn,wn) > .00000001 ? normalize(wn) : n;
vRest = aPosition;
#endif
}
</script>
<script type="x-shader/x-fragment" id="depth-fragment">
precision highp float;
varying float vDepth;
void main() {
float v = clamp(vDepth,0.,.99999)*255.;
gl_FragColor = vec4(floor(v)/255.,fract(v),0.,1.);
}
</script>
<script type="x-shader/x-fragment" id="jelly-fragment">
precision highp float;
uniform sampler2D uScene, uBack;
uniform vec2 uPixels, uSpan, uLook;
uniform vec3 uRight, uUp, uView;
uniform vec4 uBubbles[12];
uniform float uSquint;
varying vec3 vWorldNormal, vRest;
varying float vDepth;
float lamp(vec3 ray, vec3 dir, vec2 size, float fade) {
vec3 x = normalize(cross(vec3(0.,1.,0.),dir));
vec3 y = cross(dir,x);
vec2 pos = abs(vec2(dot(ray,x),dot(ray,y)));
vec2 mask = 1. - smoothstep(size,size + vec2(fade),pos);
return mask.x * mask.y * smoothstep(.45,.83,dot(ray,dir));
}
float oval(vec2 p, vec2 r) {
return 1. - smoothstep(.91,1.045,length(p/r));
}
void main() {
vec3 n = normalize(vWorldNormal);
float nv = clamp(dot(n,uView),0.,1.);
vec2 uv = gl_FragCoord.xy / uPixels;
vec4 back = texture2D(uBack,uv);
float thickness = clamp((back.r + back.g/255. - vDepth)*18.,0.,2.7);
thickness = mix(.12,thickness,back.a);
vec2 tilt = vec2(dot(n,uRight),dot(n,uUp));
vec2 refraction = (-tilt*.29 + vec2(.018,-.110)) * min(thickness,1.65);
vec3 through = texture2D(uScene,clamp(uv + refraction/(2.*uSpan),.001,.999)).rgb;
vec3 absorption = exp(-vec3(.104,1.26,3.44) * (.21 + thickness*.89));
vec3 color = through*absorption + vec3(1.,.465,.102)*(1.-absorption)*.85;
vec3 key = normalize(vec3(-.65,.86,.68));
float diffuse = .5+.5*dot(n,key);
color *= vec3(.94+.075*diffuse,.819+.218*diffuse,.82+.20*diffuse);
float rim = pow(1.-nv,2.55);
color = mix(color,vec3(.907,.319,.041),rim * (.56 - .21*max(n.y,0.)));
float litInside = exp(-1.6*thickness)*max(0.,.58+dot(n,vec3(-.39,-.48,.10)));
color += vec3(.025,.145,.058)*litInside;
vec2 earMap = (vec2(abs(vRest.x),vRest.y)-vec2(.776,3.18))/vec2(.212,.298);
float innerEar = exp(-2.1*dot(earMap,earMap))*smoothstep(.20,.48,vRest.z);
color = mix(color,vec3(.842,.292,.055),innerEar*.30);
vec3 insideRay = refract(-uView,n,.83);
for (int i=0; i<12; i++) {
vec3 delta = uBubbles[i].xyz-vRest;
float stepIn = dot(delta,insideRay);
float rad = uBubbles[i].w;
float d2 = dot(delta,delta) - stepIn*stepIn;
if (stepIn > .025 && stepIn < thickness+.14 && d2 < rad*rad*1.19) {
float rr = sqrt(max(0.,d2))/rad;
vec3 offset = (stepIn*insideRay-delta)/rad;
float inner = 1.-smoothstep(.79,1.06,rr);
float boundary = smoothstep(.62,.95,rr)*(1.-smoothstep(.95,1.085,rr));
float reflection = exp(-17.*dot(offset-vec3(-.32,.32,.06),offset-vec3(-.32,.32,.06)));
float fade = exp(-stepIn*.80);
color = mix(color,vec3(.99,.66,.27),inner*.22*fade);
color = mix(color,vec3(.66,.235,.036),boundary*.43*fade);
color += vec3(.37,.49,.49)*(reflection*.91+boundary*max(0.,offset.y)*.23)*fade;
}
}
vec3 ray = reflect(-uView,n);
float box = lamp(ray,normalize(vec3(-.79,.75,.72)),vec2(.133,.325),.065);
float bloom = lamp(ray,normalize(vec3(-.74,.80,.72)),vec2(.265,.40),.215);
float fill = lamp(ray,normalize(vec3(.90,.42,.28)),vec2(.056,.30),.11);
float top = pow(max(0.,dot(ray,normalize(vec3(.12,.98,-.48)))),15.);
float spec = clamp(box*.78+bloom*.19+fill*.61+top*.40,0.,.91);
color = mix(color,vec3(1.,.955,.819),spec);
color += vec3(.038,.025,.015)*spec;
color = mix(color,vec3(1.,.814,.493),rim * .18 * smoothstep(-.12,.76,n.y));
float front = smoothstep(.47,.71,vRest.z);
float x = vRest.x;
float y = vRest.y;
if (front > .01 && y > 1.73 && y < 2.64 && abs(x) < .91) {
vec2 c = vec2((x < 0. ? -.445 : .445)+uLook.x*.068,2.315+uLook.y*.058);
vec2 e = vec2(x,y)-c;
e.y -= .095 * e.x * sign(x);
e.y -= uSquint*.046*(1.-clamp(e.x*e.x/.023,0.,1.));
vec2 scale = vec2(.140,mix(.188,.018,uSquint));
float eye = oval(e,scale);
float warm = smoothstep(.055,-.112,e.y);
vec3 eyeInk = mix(vec3(.157,.065,.026),vec3(.406,.162,.045),warm*.75);
float highlight = oval(e-vec2(-.039,.060),vec2(.036,.045))*(1.-uSquint);
float dotHighlight = oval(e-vec2(.045,-.059),vec2(.015,.018))*(1.-uSquint);
eyeInk = mix(eyeInk,vec3(1.,.955,.816),.93*highlight + .59*dotHighlight);
color = mix(color,vec3(.570,.189,.061),oval(e,scale+vec2(.009,.009))*.41*front);
color = mix(color,eyeInk,eye*front);
vec2 nose = vec2(x,y-2.031);
float noseD = max(abs(nose.x)-(.057+nose.y*.66),max(nose.y-.035,-nose.y-.061));
float noseMask = 1.-smoothstep(-.006,.012,noseD);
vec3 noseInk = mix(vec3(.532,.137,.043),vec3(.997,.610,.330),oval(nose-vec2(-.014,.011),vec2(.044,.017))*.64);
color = mix(color,noseInk,noseMask*front);
float yy = 1.916-.056*sin(clamp(abs(x)/.172,0.,1.)*3.14159)+.017*abs(x)/.172;
float smile = (1.-smoothstep(.008,.019,abs(y-yy)))*(1.-smoothstep(.156,.177,abs(x)));
float stem = (1.-smoothstep(.008,.015,abs(x)))*smoothstep(1.912,1.935,y)*(1.-smoothstep(1.975,1.998,y));
color = mix(color,vec3(.427,.131,.030),max(smile,stem)*.86*front);
vec2 freckles = vec2(abs(x),y);
float dots = oval(freckles-vec2(.535,1.975),vec2(.013,.015))
+ oval(freckles-vec2(.619,1.955),vec2(.017,.018))
+ oval(freckles-vec2(.687,2.001),vec2(.012,.014));
color = mix(color,vec3(.72,.284,.081),dots*front*.64);
}
if (y < .51 && vRest.z > .78) {
float toe = min(abs(abs(x)-.348),abs(abs(x)-.507));
toe += .042*abs(y-.25);
float groove = (1.-smoothstep(.004,.022,toe))*smoothstep(.14,.29,y)*(1.-smoothstep(.32,.47,y));
color = mix(color,vec3(.795,.351,.078),groove*.31*smoothstep(.81,1.09,vRest.z));
}
float grain = fract(sin(dot(gl_FragCoord.xy,vec2(16.423,73.769)))*41358.415);
gl_FragColor = vec4(color + (grain-.5)*.008,1.);
}
</script>
<script type="x-shader/x-fragment" id="copy-fragment">
precision highp float;
varying vec2 vUV;
uniform sampler2D uScene;
void main() { gl_FragColor = texture2D(uScene,vUV); }
</script>
<script>
"use strict";
const get = id => document.getElementById(id);
const stage = get("stage");
const slider = get("firmness");
const statusText = get("status");
const soundButton = get("sound");
const demoHand = get("demoHand");
const reducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const clamp = (x, lo, hi) => Math.min(hi, Math.max(lo, x));
const smooth = x => { const t = clamp(x, 0, 1); return t*t*(3-2*t); };
const dot = (a,b) => a[0]*b[0]+a[1]*b[1]+a[2]*b[2];
const tau = Math.PI*2;
const yaw = .16, pitch = .303;
const camera = {
right: [Math.cos(yaw),0,-Math.sin(yaw)],
up: [-Math.sin(yaw)*Math.sin(pitch),Math.cos(pitch),-Math.cos(yaw)*Math.sin(pitch)],
view: [Math.sin(yaw)*Math.cos(pitch),Math.sin(pitch),Math.cos(yaw)*Math.cos(pitch)],
target: [.22,1.52,.04],
span: [2.88,2.18],
width: 1,
height: 1
};
const bubbleData = [
-.52,2.69,.52,.061, .25,2.75,.58,.039, .69,2.63,.54,.046, -.74,1.72,.63,.034,
-.60,1.40,.54,.052, -.30,1.24,.53,.081, .30,1.60,.38,.032, .60,1.28,.55,.066,
.17,.89,.61,.070, -.65,.59,.66,.041, 1.94,1.14,-.16,.052, 1.78,1.59,-.10,.036
];
const zones = {
earL: { kind:"ear", center:[-.77,3.21,.24], radius:[.36,.49], slot:0 },
earR: { kind:"ear", center:[ .77,3.21,.24], radius:[.36,.49], slot:1 },
tail: { kind:"tail", center:[1.96,1.12,-.20], radius:[.43,.64], slot:4 },
cheekL:{ kind:"cheek", center:[-.76,2.00,.81], radius:[.43,.38], slot:2 },
cheekR:{ kind:"cheek", center:[ .76,2.00,.81], radius:[.43,.38], slot:3 },
head: { kind:"head", center:[0,2.69,.75], radius:[.91,.49] },
face: { kind:"poke", center:[0,2.24,.94], radius:[.88,.48] },
belly: { kind:"poke", center:[0,1.13,.72], radius:[1.12,.96] },
paws: { kind:"poke", center:[0,.40,.94], radius:[1.03,.47] }
};
let time = 0;
let firmness = .48;
function project(point) {
const delta = point.map((v,i) => v-camera.target[i]);
return {
x: (1+dot(delta,camera.right)/camera.span[0])*camera.width/2,
y: (1-dot(delta,camera.up)/camera.span[1])*camera.height/2
};
}
function worldShift(dx,dy) {
const across = dx*camera.span[0]*2/camera.width;
const ascent = -dy*camera.span[1]*2/camera.height;
return camera.right.map((v,i) => across*v+ascent*camera.up[i]);
}
function findZone(point) {
const unit = camera.width/(camera.span[0]*2);
for (const zone of Object.values(zones)) {
const center = project(zone.center);
const x = (point.x-center.x)/(zone.radius[0]*unit);
const y = (point.y-center.y)/(zone.radius[1]*unit);
if (x*x+y*y < 1) return zone;
}
return null;
}
/* A single continuous surface is sampled from the ear, head, cheek, limb and tail volumes. */
function ellipsoid(x,y,z,rx,ry,rz) {
return (Math.hypot(x/rx,y/ry,z/rz)-1)*Math.min(rx,ry,rz);
}
function blend(a,b,k) {
const h = Math.max(k-Math.abs(a-b),0)/k;
return Math.min(a,b)-h*h*k*.25;
}
function tube(ax,ay,az,bx,by,bz,ra,rb,depthScale=1) {
const vx = bx-ax, vy = by-ay, vz = (bz-az)*depthScale;
const distance = Math.hypot(vx,vy,vz);
const nx = vx/distance, ny = vy/distance, nz = vz/distance;
const sine = (ra-rb)/distance, cosine = Math.sqrt(1-sine*sine);
return (x,y,z) => {
const dx=x-ax, dy=y-ay, dz=(z-az)*depthScale;
const along=dx*nx+dy*ny+dz*nz;
const side=Math.sqrt(Math.max(0,dx*dx+dy*dy+dz*dz-along*along));
const k=cosine*along-sine*side;
if (k < 0) return Math.hypot(side,along)-ra;
if (k > cosine*distance) return Math.hypot(side,along-distance)-rb;
return cosine*side+sine*along-ra;
};
}
const earVolume = tube(.615,2.72,.165,.805,3.427,.113,.383,.125,1.42);
const earHollow = tube(.699,2.966,.474,.805,3.373,.277,.209,.061,2.35);
const tailPoints = [
[.70,.51,-.43,.337], [1.07,.42,-.44,.284], [1.43,.47,-.392,.253],
[1.72,.62,-.342,.241], [1.921,.858,-.278,.227], [2.022,1.119,-.220,.223],
[2.006,1.373,-.192,.226], [1.894,1.551,-.144,.230], [1.745,1.623,-.093,.211]
];
const tailTubes = tailPoints.slice(1).map((p,i) => {
const a = tailPoints[i];
return tube(a[0],a[1],a[2],p[0],p[1],p[2],a[3],p[3]);
});
function field(x,y,z) {
const s = Math.abs(x);
let d = ellipsoid(x,y-1.085,z+.085,1.087,1.024,.873);
d = blend(d,ellipsoid(s-.736,y-.642,z+.095,.501,.567,.657),.194);
d = blend(d,ellipsoid(s-.440,y-.696,z-.481,.356,.620,.452),.174);
d = blend(d,ellipsoid(s-.432,y-.449,z-.718,.386,.417,.458),.106);
let head = ellipsoid(x,y-2.317,z-.126,1.086,.805,.846);
head = blend(head,ellipsoid(s-.697,y-2.011,z-.502,.473,.392,.480),.156);
head = blend(head,ellipsoid(s-.204,y-1.915,z-.765,.330,.223,.317),.112);
head = blend(head,earVolume(s,y,z),.157);
head = -blend(-head,earHollow(s,y,z),.055);
d = blend(d,head,.228);
if (x > .46 && y < 1.96) {
let tail = tailTubes[0](x,y,z);
for (let i=1;i<tailTubes.length;i++) tail=blend(tail,tailTubes[i](x,y,z),.067);
d=blend(d,tail,.140);
}
return -blend(-d,y-.067,.071);
}
function catMesh() {
const step = .067;
const nx = 62, ny = 59, nz = 42, layer = nx*ny, count = layer*nz;
const start = [-1.57,-.13,-1.38];
const samples = new Float32Array(count);
const mesh = [], triangles = [], edges = new Map();
for (let z=0;z<nz;z++) {
for (let y=0;y<ny;y++) {
for (let x=0;x<nx;x++) samples[z*layer+y*nx+x]=field(start[0]+x*step,start[1]+y*step,start[2]+z*step);
}
}
function coordinate(index) {
return [start[0]+(index%nx)*step,start[1]+(Math.floor(index/nx)%ny)*step,start[2]+Math.floor(index/layer)*step];
}
function crossing(a,b) {
const key = Math.min(a,b)*count+Math.max(a,b);
const cached = edges.get(key);
if (cached !== undefined) return cached;
const p = coordinate(a), q = coordinate(b);
const f = samples[a]/(samples[a]-samples[b]);
const x=p[0]+(q[0]-p[0])*f, y=p[1]+(q[1]-p[1])*f, z=p[2]+(q[2]-p[2])*f, e=.005;
const gx=field(x+e,y,z)-field(x-e,y,z);
const gy=field(x,y+e,z)-field(x,y-e,z);
const gz=field(x,y,z+e)-field(x,y,z-e);
const length=Math.hypot(gx,gy,gz)||1;
const id=mesh.length/6;
mesh.push(x,y,z,gx/length,gy/length,gz/length);
edges.set(key,id);
return id;
}
function triangle(a,b,c) {
const i=a*6,j=b*6,k=c*6;
const ux=mesh[j]-mesh[i], uy=mesh[j+1]-mesh[i+1], uz=mesh[j+2]-mesh[i+2];
const vx=mesh[k]-mesh[i], vy=mesh[k+1]-mesh[i+1], vz=mesh[k+2]-mesh[i+2];
const orientation=(uy*vz-uz*vy)*(mesh[i+3]+mesh[j+3]+mesh[k+3])
+(uz*vx-ux*vz)*(mesh[i+4]+mesh[j+4]+mesh[k+4])
+(ux*vy-uy*vx)*(mesh[i+5]+mesh[j+5]+mesh[k+5]);
if (orientation < 0) triangles.push(a,c,b);
else triangles.push(a,b,c);
}
const tetra = [[0,5,1,6],[0,1,2,6],[0,2,3,6],[0,3,7,6],[0,7,4,6],[0,4,5,6]];
for (let z=0;z<nz-1;z++) {
for (let y=0;y<ny-1;y++) {
for (let x=0;x<nx-1;x++) {
const a=z*layer+y*nx+x, b=a+layer;
const corners=[a,a+1,a+nx+1,a+nx,b,b+1,b+nx+1,b+nx];
const mask=corners.reduce((m,i,k) => m | ((samples[i]<0 ? 1 : 0)<<k),0);
if (mask===0 || mask===255) continue;
for (const t of tetra) {
const inside=[], outside=[];
for (const i of t) (samples[corners[i]]<0 ? inside : outside).push(corners[i]);
if (inside.length===1 || inside.length===3) {
const lone=inside.length===1 ? inside : outside;
const others=inside.length===1 ? outside : inside;
triangle(crossing(lone[0],others[0]),crossing(lone[0],others[1]),crossing(lone[0],others[2]));
} else if (inside.length===2) {
const p=crossing(inside[0],outside[0]), q=crossing(inside[0],outside[1]);
const r=crossing(inside[1],outside[0]), s=crossing(inside[1],outside[1]);
triangle(p,q,s);
triangle(p,s,r);
}
}
}
}
}
if (mesh.length/6>65535) throw new Error("Jelly geometry exceeds the index limit.");
return [new Float32Array(mesh),new Uint16Array(triangles)];
}
function plateMesh() {
const profile = [
[0,.062],[.80,.062],[1.23,.062],[1.36,.066],[1.49,.084],[1.62,.119],
[1.74,.166],[1.84,.199],[1.94,.220],[2.011,.215],[2.063,.196],[2.090,.167],
[2.091,.129],[2.072,.093],[2.036,.064],[1.97,.038],[1.85,.015],[1.65,-.013],
[1.38,-.056],[1.26,-.075],[1.222,-.100],[1.212,-.130],[1.169,-.140],[1.110,-.130],[1.065,-.107],[0,-.102]
];
const vertices=[],indices=[], ring=104;
for (let j=0;j<profile.length;j++) {
const [r,h]=profile[j];
const prev=profile[Math.max(0,j-1)], next=profile[Math.min(profile.length-1,j+1)];
const dy=next[1]-prev[1], dr=next[0]-prev[0], normal=Math.hypot(dy,dr)||1;
for (let i=0;i<=ring;i++) {
const angle=i*tau/ring, c=Math.cos(angle), s=Math.sin(angle);
vertices.push(.22+r*c,h,.025+r*s,-dy*c/normal,dr/normal,-dy*s/normal);
if (j>0 && i>0) {
const k=j*(ring+1)+i;
indices.push(k-ring-2,k-ring-1,k-1,k-ring-1,k,k-1);
}
}
}
return [new Float32Array(vertices),new Uint16Array(indices)];
}
function makeWebGL(canvas) {
const gl = canvas.getContext("webgl",{alpha:false,antialias:true,depth:true});
if (!gl) return null;
function shader(type,source) {
const s=gl.createShader(type);
gl.shaderSource(s,source);
gl.compileShader(s);
if (!gl.getShaderParameter(s,gl.COMPILE_STATUS)) throw new Error(gl.getShaderInfoLog(s));
return s;
}
function program(vertex,fragment,prefix="") {
const vs=shader(gl.VERTEX_SHADER,prefix+get(vertex).textContent);
const fs=shader(gl.FRAGMENT_SHADER,get(fragment).textContent);
const p=gl.createProgram();
gl.attachShader(p,vs);
gl.attachShader(p,fs);
gl.bindAttribLocation(p,0,"aPosition");
gl.bindAttribLocation(p,1,"aNormal");
gl.linkProgram(p);
gl.deleteShader(vs);
gl.deleteShader(fs);
if (!gl.getProgramParameter(p,gl.LINK_STATUS)) throw new Error(gl.getProgramInfoLog(p));
const uniforms={};
for (let i=0;i<gl.getProgramParameter(p,gl.ACTIVE_UNIFORMS);i++) {
const name=gl.getActiveUniform(p,i).name;
uniforms[name.replace(/\[0\]$/,"")]=gl.getUniformLocation(p,name);
}
return {p,u:uniforms};
}
const studio=program("quad-vertex","studio-fragment");
const plate=program("plate-vertex","plate-fragment");
const depth=program("jelly-vertex","depth-fragment","#define BACK_PASS\n");
const cat=program("jelly-vertex","jelly-fragment");
const copy=program("quad-vertex","copy-fragment");
function buffer(target,values) {
const b=gl.createBuffer();
gl.bindBuffer(target,b);
gl.bufferData(target,values,gl.STATIC_DRAW);
return b;
}
function geometry([verts,inds]) {
return {verts:buffer(gl.ARRAY_BUFFER,verts),inds:buffer(gl.ELEMENT_ARRAY_BUFFER,inds),size:inds.length};
}
const quad=buffer(gl.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,1,1]));
const dish=geometry(plateMesh()), jelly=geometry(catMesh());
function makeTarget(linear) {
const texture=gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D,texture);
gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,linear?gl.LINEAR:gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,linear?gl.LINEAR:gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,gl.CLAMP_TO_EDGE);
return { texture, framebuffer:gl.createFramebuffer(), depth:gl.createRenderbuffer() };
}
const scene=makeTarget(true), back=makeTarget(false);
const pulls=new Float32Array(15);
let pixelWidth=0, pixelHeight=0;
function allocate(target,w,h) {
gl.bindTexture(gl.TEXTURE_2D,target.texture);
gl.texImage2D(gl.TEXTURE_2D,0,gl.RGBA,w,h,0,gl.RGBA,gl.UNSIGNED_BYTE,null);
gl.bindRenderbuffer(gl.RENDERBUFFER,target.depth);
gl.renderbufferStorage(gl.RENDERBUFFER,gl.DEPTH_COMPONENT16,w,h);
gl.bindFramebuffer(gl.FRAMEBUFFER,target.framebuffer);
gl.framebufferTexture2D(gl.FRAMEBUFFER,gl.COLOR_ATTACHMENT0,gl.TEXTURE_2D,target.texture,0);
gl.framebufferRenderbuffer(gl.FRAMEBUFFER,gl.DEPTH_ATTACHMENT,gl.RENDERBUFFER,target.depth);
if (gl.checkFramebufferStatus(gl.FRAMEBUFFER)!==gl.FRAMEBUFFER_COMPLETE) throw new Error("Jelly render target is unavailable.");
}
function use(pass) {
gl.useProgram(pass.p);
const u=pass.u;
if (u.uSpan) gl.uniform2fv(u.uSpan,camera.span);
if (u.uTarget) gl.uniform3fv(u.uTarget,camera.target);
if (u.uRight) gl.uniform3fv(u.uRight,camera.right);
if (u.uUp) gl.uniform3fv(u.uUp,camera.up);
if (u.uView) gl.uniform3fv(u.uView,camera.view);
return u;
}
function fullscreen() {
gl.bindBuffer(gl.ARRAY_BUFFER,quad);
gl.enableVertexAttribArray(0);
gl.disableVertexAttribArray(1);
gl.vertexAttribPointer(0,2,gl.FLOAT,false,0,0);
gl.drawArrays(gl.TRIANGLE_STRIP,0,4);
}
function draw(model) {
gl.bindBuffer(gl.ARRAY_BUFFER,model.verts);
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER,model.inds);
gl.enableVertexAttribArray(0);
gl.enableVertexAttribArray(1);
gl.vertexAttribPointer(0,3,gl.FLOAT,false,24,0);
gl.vertexAttribPointer(1,3,gl.FLOAT,false,24,12);
gl.drawElements(gl.TRIANGLES,model.size,gl.UNSIGNED_SHORT,0);
}
function motion(pass,s) {
const u=use(pass);
gl.uniform4f(u.uMotion,s.squash,s.rockX,s.rockZ,s.height);
gl.uniform2fv(u.uWave,s.wave);
gl.uniform4f(u.uPress,s.pressPoint[0],s.pressPoint[1],s.pressPoint[2],s.press);
gl.uniform3fv(u.uPull,pulls);
return u;
}
function bind(unit,target) {
gl.activeTexture(gl.TEXTURE0+unit);
gl.bindTexture(gl.TEXTURE_2D,target.texture);
}
return {
resize(w,h) {
if (w===pixelWidth && h===pixelHeight) return;
pixelWidth=w;
pixelHeight=h;
canvas.width=w;
canvas.height=h;
gl.activeTexture(gl.TEXTURE0);
allocate(scene,w,h);
allocate(back,w,h);
gl.bindFramebuffer(gl.FRAMEBUFFER,null);
gl.viewport(0,0,w,h);
},
draw(s) {
for (let i=0;i<5;i++) for (let j=0;j<3;j++) pulls[i*3+j]=s.pulls[i][j].value;
gl.disable(gl.CULL_FACE);
gl.clearColor(0,0,0,0);
gl.bindFramebuffer(gl.FRAMEBUFFER,scene.framebuffer);
gl.clear(gl.DEPTH_BUFFER_BIT);
gl.disable(gl.DEPTH_TEST);
use(studio);
fullscreen();
gl.enable(gl.DEPTH_TEST);
const plateUniforms=use(plate);
gl.uniform1f(plateUniforms.uHeight,s.height);
draw(dish);
gl.bindFramebuffer(gl.FRAMEBUFFER,back.framebuffer);
gl.clear(gl.COLOR_BUFFER_BIT|gl.DEPTH_BUFFER_BIT);
gl.enable(gl.CULL_FACE);
gl.cullFace(gl.FRONT);
motion(depth,s);
draw(jelly);
gl.bindFramebuffer(gl.FRAMEBUFFER,null);
gl.clear(gl.DEPTH_BUFFER_BIT);
gl.disable(gl.CULL_FACE);
gl.disable(gl.DEPTH_TEST);
bind(0,scene);
gl.uniform1i(use(copy).uScene,0);
fullscreen();
gl.enable(gl.DEPTH_TEST);
gl.colorMask(false,false,false,false);
gl.uniform1f(use(plate).uHeight,s.height);
draw(dish);
gl.colorMask(true,true,true,true);
gl.enable(gl.CULL_FACE);
gl.cullFace(gl.BACK);
bind(1,back);
const u=motion(cat,s);
gl.uniform1i(u.uScene,0);
gl.uniform1i(u.uBack,1);
gl.uniform2f(u.uPixels,pixelWidth,pixelHeight);
gl.uniform2fv(u.uLook,s.look);
gl.uniform1f(u.uSquint,s.squint);
gl.uniform4fv(u.uBubbles,bubbleData);
draw(jelly);
}
};
}
/* The same controls and springs also drive a drawn renderer for browsers without WebGL. */
function makePainter(canvas) {
const c=canvas.getContext("2d");
const ellipse=(x,y,rx,ry,fill) => {
c.beginPath();
c.ellipse(x,y,rx,ry,0,0,tau);
c.fillStyle=fill;
c.fill();
};
function gradient(x,y,inner,X,Y,outer,stops) {
const paint=c.createRadialGradient(x,y,inner,X,Y,outer);
stops.forEach(([at,color])=>paint.addColorStop(at,color));
return paint;
}
return {
resize(w,h) { canvas.width=w; canvas.height=h; },
draw(s) {
const w=camera.width,h=camera.height,unit=w/(2*camera.span[0]);
c.setTransform(canvas.width/w,0,0,canvas.height/h,0,0);
c.fillStyle=gradient(w*.42,h*.34,0,w*.46,h*.42,w*.76,[[0,"#fff5e5"],[1,"#e9cdb4"]]);
c.fillRect(0,0,w,h);
const plate=project([.22,.065,.025]);
c.save();
c.translate(plate.x,plate.y);
c.scale(unit,unit);
ellipse(.20,.14,2.25,.77,gradient(.18,.12,0,.19,.13,2.25,[[0,"#8c4a3250"],[.72,"#8c4a323d"],[1,"#8c4a3200"]]));
ellipse(0,.071,2.094,.635,"#cbad91");
const glaze=c.createLinearGradient(0,-.7,0,.67);
glaze.addColorStop(0,"#faecd9");
glaze.addColorStop(.65,"#fff8eb");
glaze.addColorStop(1,"#e6cfb7");
ellipse(0,0,2.094,.624,glaze);
c.beginPath(); c.ellipse(0,0,1.91,.532,0,0,tau);
c.strokeStyle="#b68e6a55"; c.lineWidth=.018; c.stroke();
ellipse(-.13,.045,1.34,.36/(1+s.height*.2),gradient(-.24,.04,0,-.13,.04,1.36,[[0,"#c36a35"+(s.height>.2?"24":"61")],[1,"#c36a3500"]]));
c.restore();
const origin=project([0,.065+s.height,.18]);
const wobble=s.wave[0]*.06;
const pull=s.pulls.map(v=>v.map(n=>n.value));
c.save();
c.translate(origin.x,origin.y);
c.transform(unit*(1+s.squash*.6),0,-unit*(s.rockX*.29+wobble),unit*(.948-s.squash*.85),0,0);
function tailPath() {
c.beginPath(); c.moveTo(.67,-.40);
c.bezierCurveTo(1.11,-.18,1.57+pull[4][0]*.43,-.34,1.84+pull[4][0]*.69,-.69-pull[4][1]*.5);
c.bezierCurveTo(2.17+pull[4][0],-1.11-pull[4][1],2.02+pull[4][0],-1.66-pull[4][1],1.73+pull[4][0],-1.61-pull[4][1]);
}
c.lineCap="round";
tailPath(); c.lineWidth=.476; c.strokeStyle="#c45313"; c.stroke();
const tailGlaze=c.createLinearGradient(1.4,-1.28,2.12,-1.12);
tailGlaze.addColorStop(0,"#e96410"); tailGlaze.addColorStop(.53,"#ffb33a"); tailGlaze.addColorStop(1,"#f07d12");
tailPath(); c.lineWidth=.423; c.strokeStyle=tailGlaze; c.stroke();
c.save(); c.translate(-.064,-.081); tailPath(); c.lineWidth=.048; c.strokeStyle="#ffe3a575"; c.stroke(); c.restore();
const left=pull[0],right=pull[1],cheekL=pull[2],cheekR=pull[3];
function outline() {
c.beginPath();
c.moveTo(0,-2.91);
c.bezierCurveTo(.25,-2.91,.40,-2.96,.52+right[0]*.35,-3.06-right[1]*.36);
c.bezierCurveTo(.65+right[0],-3.26-right[1],.75+right[0],-3.50-right[1],.89+right[0],-3.42-right[1]);
c.bezierCurveTo(1.04+right[0]*.6,-3.35-right[1]*.72,1.06,-2.71,1.05,-2.54);
c.bezierCurveTo(1.20+cheekR[0],-2.21-cheekR[1],1.24+cheekR[0],-1.77-cheekR[1],.93,-1.58);
c.bezierCurveTo(1.06,-1.24,1.38,-.58,1.12,-.24);
c.bezierCurveTo(.94,.055,.48,.022,0,.027);
c.bezierCurveTo(-.53,.022,-1.02,.063,-1.15,-.23);
c.bezierCurveTo(-1.36,-.66,-1.05,-1.24,-.94,-1.58);
c.bezierCurveTo(-1.25+cheekL[0],-1.73-cheekL[1],-1.21+cheekL[0],-2.20-cheekL[1],-1.05,-2.54);
c.bezierCurveTo(-1.07,-2.78,-1.08+left[0]*.64,-3.37-left[1]*.76,-.88+left[0],-3.44-left[1]);
c.bezierCurveTo(-.74+left[0],-3.47-left[1],-.64+left[0],-3.23-left[1],-.52+left[0]*.35,-3.06-left[1]*.36);
c.bezierCurveTo(-.40,-2.96,-.25,-2.91,0,-2.91);
c.closePath();
}
outline();
c.fillStyle=gradient(-.46,-2.62,.16,.04,-1.84,2.05,[[0,"#ffd371e0"],[.39,"#ff9b2df1"],[.76,"#f47a11ed"],[1,"#d84b06f5"]]);
c.fill(); c.lineWidth=.026; c.strokeStyle="#c65319ad"; c.stroke();
c.save(); outline(); c.clip();
ellipse(-.70+left[0]*.7,-3.02-left[1]*.68,.19,.35,"#d451175d");
ellipse(.71+right[0]*.7,-3.02-right[1]*.68,.19,.35,"#d451175d");
ellipse(-.58,-2.64,.56,.31,gradient(-.68,-2.67,.02,-.57,-2.65,.55,[[0,"#fff4ceb0"],[1,"#fff4ce00"]]));
ellipse(.83,-1.98,.37,.69,gradient(.87,-2.01,.03,.80,-1.96,.58,[[0,"#fff1b568"],[1,"#fff2b600"]]));
ellipse(-.50,-1.08,.57,.67,gradient(-.63,-.89,.05,-.47,-1.03,.68,[[0,"#ffedac7f"],[1,"#ffefbe00"]]));
ellipse(0,-.72,.99,.78,gradient(.09,-.60,.1,0,-.72,.97,[[0,"#ffb5368b"],[1,"#ffb23b00"]]));
for (const side of [-1,1]) {
const x=side*.46;
ellipse(x,-.30,.44,.34,gradient(x-.13,-.42,.03,x,-.29,.43,[[0,"#ffd269"],[.71,"#f88a20"],[1,"#de590b55"]]));
c.strokeStyle="#a641143a"; c.lineWidth=.021;
for (const toe of [-.094,.096]) {
c.beginPath(); c.moveTo(x+toe,-.085); c.quadraticCurveTo(x+toe+.013,-.142,x+toe,-.227); c.stroke();
}
}
for (let i=0;i<bubbleData.length;i+=4) {
const [x,y,z,r]=bubbleData.slice(i,i+4);
if (x>1.3) continue;
const py=-y+z*.21;
ellipse(x,py,r,r,gradient(x-r*.29,py-r*.31,0,x,py,r,[[0,"#fff7cecf"],[.38,"#ffcb6570"],[.77,"#e37a1f58"],[1,"#a8482d80"]]));
ellipse(x-r*.27,py-r*.28,r*.23,r*.21,"#fff2b5cf");
}
c.restore();
const pinch=s.press*.18;
for (const side of [-1,1]) {
const x=side*.445+s.look[0]*.068, y=-2.16-s.look[1]*.057+pinch;
const tall=.176*(1-s.squint)+.021;
ellipse(x,y,.137,tall,gradient(x-.035,y-.042,0,x,y,.192,[[0,"#30150b"],[.69,"#48200e"],[1,"#833e13"]]));
if (s.squint<.64) {
ellipse(x-.040,y-.048,.034,.042*(1-s.squint),"#fff0c9");
ellipse(x+.036,y+.052,.014,.016,"#ffc774");
}
}
c.beginPath(); c.moveTo(-.076,-1.95+pinch); c.quadraticCurveTo(0,-1.99+pinch,.076,-1.95+pinch);
c.quadraticCurveTo(.04,-1.86+pinch,0,-1.857+pinch); c.quadraticCurveTo(-.046,-1.865+pinch,-.076,-1.95+pinch);
c.fillStyle="#a94316"; c.fill();
c.lineWidth=.023; c.strokeStyle="#7d3218"; c.lineCap="round";
c.beginPath(); c.moveTo(-.164,-1.813+pinch); c.quadraticCurveTo(-.089,-1.72+pinch,0,-1.822+pinch);
c.quadraticCurveTo(.089,-1.72+pinch,.164,-1.813+pinch); c.moveTo(0,-1.822+pinch); c.lineTo(0,-1.873+pinch); c.stroke();
c.restore();
}
};
}
let soundOn = true, audio = null, master, noise, purrLevel;
let purrPlaying = false;
function wakeAudio() {
if (!soundOn) return;
const Audio = window.AudioContext || window.webkitAudioContext;
if (!Audio) return;
try {
if (!audio) {
audio=new Audio();
master=audio.createGain();
master.gain.value=.40;
master.connect(audio.destination);
noise=audio.createBuffer(1,Math.ceil(audio.sampleRate*.47),audio.sampleRate);
const data=noise.getChannelData(0);
for (let i=0;i<data.length;i++) data[i]=Math.random()*2-1;
}
if (audio.state==="suspended") audio.resume().catch(()=>{});
} catch (_) { /* The visuals remain available when sound cannot start. */ }
}
function plip(kind) {
if (!soundOn || !audio || !master || !noise) return;
const land=kind==="land", release=kind==="release";
const start=audio.currentTime+.009;
const length=land?.285:release?.17:.124;
const base=land?119:release?435:345;
const osc=audio.createOscillator();
const tone=audio.createGain();
const liquid=audio.createBufferSource();
const filter=audio.createBiquadFilter();
const splash=audio.createGain();
osc.frequency.setValueAtTime(base*(.90+firmness*.24),start);
osc.frequency.exponentialRampToValueAtTime(base*(land?.48:release?1.43:.47),start+length*.61);
tone.gain.setValueAtTime(.001,start);
tone.gain.exponentialRampToValueAtTime(land?.46:.22,start+.013);
tone.gain.exponentialRampToValueAtTime(.001,start+length);
osc.connect(tone);
tone.connect(master);
osc.start(start);
osc.stop(start+length+.022);
liquid.buffer=noise;
filter.type="bandpass";
filter.Q.value=land?2.1:4.6;
filter.frequency.setValueAtTime(land?595:1760,start);
filter.frequency.exponentialRampToValueAtTime(land?145:375,start+length*.86);
splash.gain.setValueAtTime(.001,start);
splash.gain.exponentialRampToValueAtTime(land?.30:.21,start+.019);
splash.gain.exponentialRampToValueAtTime(.001,start+length);
liquid.connect(filter);
filter.connect(splash);
splash.connect(master);
liquid.start(start,Math.random()*.15);
liquid.stop(start+length);
}
function setPurr(active) {
active=Boolean(active && soundOn && audio && master && noise);
if (active===purrPlaying) return;
purrPlaying=active;
if (!purrLevel) {
purrLevel=audio.createGain();
purrLevel.gain.value=0;
const tremolo=audio.createGain(), beat=audio.createOscillator(), depth=audio.createGain();
tremolo.gain.value=.62;
beat.frequency.value=25;
depth.gain.value=.39;
beat.connect(depth);
depth.connect(tremolo.gain);
tremolo.connect(purrLevel);
purrLevel.connect(master);
beat.start();
for (const [frequency,amp] of [[32,.16],[86,.146],[126,.071]]) {
const osc=audio.createOscillator(), level=audio.createGain();
osc.frequency.value=frequency;
level.gain.value=amp;
osc.connect(level); level.connect(tremolo); osc.start();
}
const rumble=audio.createBufferSource(), velvet=audio.createBiquadFilter(), level=audio.createGain();
rumble.buffer=noise; rumble.loop=true; velvet.type="lowpass"; velvet.frequency.value=310; level.gain.value=.39;
rumble.connect(velvet); velvet.connect(level); level.connect(tremolo); rumble.start();
}
purrLevel.gain.setTargetAtTime(active?.72:0,audio.currentTime,active?.085:.14);
}
soundButton.addEventListener("click",() => {
soundOn=!soundOn;
soundButton.setAttribute("aria-pressed",String(soundOn));
get("soundLabel").textContent=soundOn?"Sound on":"Sound off";
if (soundOn) wakeAudio();
if (master) master.gain.setTargetAtTime(soundOn?.40:0,audio.currentTime,.04);
if (!soundOn) setPurr(false);
});
/* Texture changes the deformation range, spring stiffness and rebound. */
const spring=()=>({value:0,velocity:0,target:0});
const squash=spring(), rockX=spring(), rockZ=spring(), press=spring();
const pulls=Array.from({length:5},()=>[spring(),spring(),spring()]);
const springs=[squash,rockX,rockZ,press,...pulls.flat()];
const pose={
squash:0, rockX:0, rockZ:0, height:0, wave:[0,0], look:[0,0], squint:0,
press:0, pressPoint:[0,1.34,.94], pulls
};
let activePointer=null, gesture=null, focus=null, waveAt=-9, waveStrength=0;
let dropStart=null, landed=false, purrBlend=0;
let note="", noteEnds=0;
function setTexture(value) {
const amount=Math.round(clamp(value,0,100));
firmness=amount/100;
slider.value=amount;
slider.style.setProperty("--mix",amount+"%");
const title=amount<=30?"Pudding":amount>=70?"Gummy":"Bouncy";
get("textureValue").value=title;
slider.setAttribute("aria-valuetext",title+", "+amount+" percent firm");
}
function noteFor(text,seconds) { note=text; noteEnds=time+seconds; }
function ripple(strength) { waveAt=time; waveStrength=strength; }
function pokeStart(point,zone=findZone(point)) {
focus=point;
if (!zone || pose.height>.32) return false;
const projected=project(zone.center);
const offset=worldShift(point.x-projected.x,point.y-projected.y);
pose.pressPoint=zone.center.map((v,i)=>v+offset[i]*.70);
gesture={zone,start:point,point,travel:0,movedAt:-9,began:time,rubbing:false,stretch:0};
press.velocity+=zone.kind==="poke"?2.7:1.05;
squash.velocity+=(zone.kind==="poke"?.73:.31)*(1-firmness*.52);
rockX.velocity+=(point.x-camera.width*.5)/camera.width*.47;
ripple(.35*(1-firmness*.45));
plip("poke");
return true;
}
function pokeMove(point) {
focus=point;
if (!gesture) return;
const distance=Math.hypot(point.x-gesture.point.x,point.y-gesture.point.y);
if (distance>.65) {
gesture.travel+=distance;
gesture.movedAt=time;
}
gesture.point=point;
}
function pokeEnd() {
if (!gesture) return;
if (gesture.stretch>.115) plip("release");
if (gesture.stretch>.08 || gesture.zone.kind==="poke") {
ripple((.32+gesture.stretch*.53)*(1-firmness*.37));
rockX.velocity+=(gesture.point.x-gesture.start.x)/camera.width*.85;
squash.velocity-=.34;
}
noteFor(gesture.rubbing?"That felt good":"Wobbling",gesture.rubbing?.85:.69);
gesture=null;
stage.classList.remove("grabbing");
}
function startDrop() {
if (gesture) pokeEnd();
dropStart=time;
landed=false;
pose.height=4.7;
noteFor("Incoming!",.73);
}
function resetCat() {
activePointer=null;
gesture=null;
focus=null;
dropStart=null;
waveStrength=0;
purrBlend=0;
noteEnds=0;
pose.height=0;
pose.look.fill(0);
for (const state of springs) {
state.value=0; state.target=0; state.velocity=0;
}
setPurr(false);
stage.classList.remove("grabbing","purring");
setTexture(48);
}
function animateDrop() {
if (dropStart===null) return;
const seconds=time-dropStart;
const fall=.72;
if (seconds<fall) {
pose.height=4.7*(1-(seconds/fall)**2);
return;
}
if (!landed) {
landed=true;
squash.value=.205+(1-firmness)*.126;
squash.velocity=.35;
rockX.velocity+=1.88-firmness*.63;
rockZ.velocity+=.68;
ripple(1.12-firmness*.42);
noteFor("Big wobble!",1.27);
plip("land");
}
const bounce=clamp((seconds-fall)/.30,0,1);
pose.height=4*bounce*(1-bounce)*(.075+firmness*.11);
if (seconds>1.82) dropStart=null;
}
function setTargets() {
for (const state of springs) state.target=0;
if (!gesture) return false;
const g=gesture, softness=1-firmness;
const delta=worldShift(g.point.x-g.start.x,g.point.y-g.start.y);
const age=time-g.began;
const flex=.46+softness*.68;
let rubbing=false;
if (g.zone.slot!==undefined) {
const springSet=pulls[g.zone.slot];
const magnitude=Math.hypot(...delta);
const limit=.39+softness*.59;
const scale=flex*limit/(limit+magnitude*.56);
springSet[0].target=delta[0]*scale;
springSet[1].target=delta[1]*scale;
springSet[2].target=delta[2]*scale;
if (g.zone.kind==="cheek") {
const pinch=(.082+.14*softness)*smooth(age/.16)*Math.exp(-magnitude*7);
springSet[0].target-=Math.sign(g.zone.center[0])*pinch;
springSet[2].target-=pinch*.52;
}
g.stretch=magnitude*scale;
press.target=(.047+softness*.055)*Math.exp(-magnitude*4);
squash.target=.016*(1+softness);
rockX.target=delta[0]*.077*scale;
} else if (g.zone.kind==="head") {
rubbing=g.travel>13 && time-g.movedAt<.31;
if (rubbing) g.rubbing=true;
press.target=(rubbing?.045:.095)*flex;
rockX.target=clamp(delta[0]*.07,-.055,.055);
} else {
press.target=(.18+.17*softness)*smooth(age/.085);
squash.target=(.029+.056*softness)*smooth(age/.27);
rockX.target=clamp(delta[0]*.18,-.16,.16);
rockZ.target=clamp(delta[1]*.11,-.14,.14);
}
return rubbing;
}
function advance(dt) {
animateDrop();
const rubbing=setTargets();
const stiffness=105+firmness*234, damping=4.4+firmness*6.6;
const steps=Math.max(1,Math.ceil(dt*130)), tick=dt/steps;
for (let i=0;i<steps;i++) {
for (const state of springs) {
state.velocity+=(state.target-state.value)*stiffness*tick;
state.velocity*=Math.exp(-damping*tick);
state.value+=state.velocity*tick;
}
}
purrBlend+=(Number(rubbing)-purrBlend)*(1-Math.exp(-dt*(rubbing?10:5)));
const blink=.17-Math.abs(((time+.05)%5.91)-5.37);
pose.squint=Math.max(purrBlend*.96,blink>0?smooth(blink/.17):0);
pose.squash=clamp(squash.value+(reducedMotion?0:Math.sin(time*2.13)*.0049),-.125,.37);
pose.rockX=rockX.value;
pose.rockZ=rockZ.value;
pose.press=press.value;
const waveAge=time-waveAt, decay=waveStrength*Math.exp(-waveAge*(2.9+firmness*2.7));
const wavePhase=waveAge*(17+firmness*17);
pose.wave[0]=Math.sin(wavePhase)*decay;
pose.wave[1]=Math.cos(wavePhase)*decay;
const eyes=project([0,2.27,.91]);
const aim=focus ? [
clamp((focus.x-eyes.x)/(camera.width*.28),-1,1),
clamp((eyes.y-focus.y)/(camera.height*.29),-1,1)
]:[0,0];
for (let i=0;i<2;i++) pose.look[i]+=(aim[i]-pose.look[i])*(1-Math.exp(-dt*15));
const kind=gesture?.zone.kind;
let status="Ready to play";
if (rubbing) status="Purring";
else if (kind==="ear") status="Stretching an ear";
else if (kind==="tail") status="Stretching the tail";
else if (kind==="cheek") status=gesture.stretch>.10?"Stretching a cheek":"Squeezing";
else if (kind==="head") status="Rub to make it purr";
else if (kind==="poke") status=time-gesture.began>.25?"Squeezing":"Belly poke";
else if (time<noteEnds) status=note;
if (statusText.textContent!==status) statusText.textContent=status;
stage.classList.toggle("purring",rubbing);
setPurr(rubbing);
}
let demo=window.location.hash==="#demo", demoTime=0, demoGesture=null;
const choreography=[
{at:1.03,end:1.65,zone:zones.belly,style:"press"},
{at:2.51,end:3.94,zone:zones.earL,style:"tug",x:-.75,y:.40},
{at:4.78,end:6.03,zone:zones.cheekR,style:"tug",x:.62,y:.03},
{at:6.94,end:8.17,zone:zones.tail,style:"tug",x:.63,y:.24},
{at:9.02,end:11.78,zone:zones.head,style:"rub"},
{at:16.94,end:17.55,zone:zones.belly,style:"press"}
];
function stopDemo() {
if (!demo) return;
demo=false;
if (demoGesture) pokeEnd();
demoGesture=null;
focus=null;
demoHand.classList.remove("visible","down");
}
function playDemo(dt) {
const old=demoTime;
demoTime+=dt;
if (demoTime>=20) {
demoTime%=20;
setTexture(48);
}
const crosses=t=>old<t && demoTime>=t;
if (crosses(12.02)) { setTexture(7); noteFor("Soft pudding",1.02); }
if (crosses(13.20)) startDrop();
if (crosses(15.92)) { setTexture(94); noteFor("Firm gummy",.93); }
if (crosses(18.59)) setTexture(48);
const action=choreography.find(a=>demoTime>=a.at-.38 && demoTime<a.end+.10);
const isDown=Boolean(action && demoTime>=action.at && demoTime<action.end);
if (demoGesture && (!isDown || demoGesture!==action)) {
pokeEnd();
demoGesture=null;
}
demoHand.classList.toggle("visible",Boolean(action));
demoHand.classList.toggle("down",isDown);
if (!action) { focus=null; return; }
const origin=project(action.zone.center);
const unit=camera.width/(2*camera.span[0]);
const age=Math.max(0,demoTime-action.at);
const phase=clamp(age/(action.end-action.at),0,1);
let x=origin.x,y=origin.y;
if (action.style==="tug") {
const f=smooth(phase*1.85);
x+=action.x*f*unit; y-=action.y*f*unit;
}
if (action.style==="rub") {
x+=Math.sin(age*8.2)*.39*unit*smooth(age*6);
y+=Math.sin(age*12.1)*.066*unit*smooth(age*6);
}
if (demoTime<action.at) { x+=.23*unit*(1-smooth((demoTime-action.at+.38)/.38)); y+=unit*.23*(1-smooth((demoTime-action.at+.38)/.38)); }
demoHand.style.transform="translate("+x+"px,"+y+"px)";
focus={x,y};
if (isDown) {
if (demoGesture!==action && pokeStart(origin,action.zone)) demoGesture=action;
if (demoGesture===action) pokeMove({x,y});
}
}
document.addEventListener("pointerdown",stopDemo,{capture:true});
slider.addEventListener("input",() => {
stopDemo();
setTexture(Number(slider.value));
});
get("drop").addEventListener("click",() => { stopDemo(); wakeAudio(); startDrop(); });
get("reset").addEventListener("click",() => { stopDemo(); resetCat(); });
function pointerPosition(event) {
const box=stage.getBoundingClientRect();
return {x:event.clientX-box.left-stage.clientLeft,y:event.clientY-box.top-stage.clientTop};
}
stage.addEventListener("pointerdown",event=>{
if (event.target.closest("button") || activePointer!==null || event.button>0) return;
wakeAudio();
if (!pokeStart(pointerPosition(event))) return;
activePointer=event.pointerId;
stage.setPointerCapture(event.pointerId);
stage.classList.add("grabbing");
event.preventDefault();
});
stage.addEventListener("pointermove",event=>{
if (demo || (activePointer!==null && event.pointerId!==activePointer)) return;
pokeMove(pointerPosition(event));
});
function releasePointer(event) {
if (event.pointerId!==activePointer) return;
activePointer=null;
pokeEnd();
if (event.pointerType!=="mouse") focus=null;
}
stage.addEventListener("pointerup",releasePointer);
stage.addEventListener("pointercancel",releasePointer);
stage.addEventListener("lostpointercapture",releasePointer);
stage.addEventListener("pointerleave",()=>{ if (activePointer===null && !demo) focus=null; });
setTexture(48);
const glCanvas=get("glCanvas"), paintCanvas=get("paintCanvas");
let renderer=null, usingGL=false, measuredWidth=0, measuredHeight=0;
function usePainter() {
glCanvas.hidden=true;
paintCanvas.hidden=false;
usingGL=false;
renderer=makePainter(paintCanvas);
measuredWidth=0;
}
try { renderer=makeWebGL(glCanvas); usingGL=Boolean(renderer); }
catch (_) { renderer=null; }
if (!renderer) usePainter();
glCanvas.addEventListener("webglcontextlost",event=>{ event.preventDefault(); if (usingGL) usePainter(); });
function fit() {
const w=Math.max(1,stage.clientWidth),h=Math.max(1,stage.clientHeight);
if (w===measuredWidth && h===measuredHeight) return;
measuredWidth=w;
measuredHeight=h;
camera.width=w;
camera.height=h;
const ratio=w/h;
camera.span[1]=Math.max(4.36,4.73/ratio)/2;
camera.span[0]=camera.span[1]*ratio;
const scale=Math.min(window.devicePixelRatio||1,1.55,Math.sqrt(465000/(w*h)));
const pixels=[Math.max(1,Math.round(w*scale)),Math.max(1,Math.round(h*scale))];
try { renderer.resize(...pixels); }
catch (error) {
if (!usingGL) throw error;
usePainter();
renderer.resize(...pixels);
}
}
let last=performance.now();
function frame(now) {
const dt=clamp((now-last)/1000,0,.059);
last=now;
time+=dt;
fit();
if (demo) playDemo(dt);
advance(dt);
renderer.draw(pose);
requestAnimationFrame(frame);
}
requestAnimationFrame(frame);
</script>
</body>
</html>
