Back to the app
The code
Jelly Cat by Claude Haiku 5.5
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,maximum-scale=1,user-scalable=no">
<title>Jelly Cat</title>
<style>
:root { --bg: #fff4e0; --ink: #6b3a10; --btn: #ff9a3c; --btn-ink: #fff; }
@media (prefers-color-scheme: dark) {
:root:not([data-theme="light"]) { --bg: #2a1d12; --ink: #ffe6c2; --btn: #ff9a3c; --btn-ink: #2a1d12; }
}
:root[data-theme="dark"] { --bg: #2a1d12; --ink: #ffe6c2; --btn: #ff9a3c; --btn-ink: #2a1d12; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); overflow: hidden;
font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; touch-action: none; user-select: none; -webkit-user-select: none; }
#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#ui { position: fixed; left: 0; right: 0; bottom: 0; padding: 14px 16px 18px; display: flex; flex-direction: column; gap: 12px; align-items: center; pointer-events: none; }
#ui > * { pointer-events: auto; }
button { font: inherit; font-size: 20px; font-weight: 700; min-height: 56px; padding: 0 28px; border: 0; border-radius: 28px;
background: var(--btn); color: var(--btn-ink); cursor: pointer; box-shadow: 0 6px 0 rgba(0,0,0,.18); }
button:active { transform: translateY(3px); box-shadow: 0 3px 0 rgba(0,0,0,.18); }
.row { display: flex; align-items: center; gap: 10px; width: min(92vw, 420px); font-size: 17px; }
.row label { white-space: nowrap; }
input[type=range] { flex: 1; height: 44px; accent-color: var(--btn); }
#hint { font-size: 15px; opacity: .75; text-align: center; margin: 0; }
</style>
</head>
<body>
<canvas id="c"></canvas>
<div id="ui">
<p id="hint">Poke, squeeze, pull the ears, cheeks or tail. Rub the head to purr.</p>
<div class="row">
<label for="firm">Pudding</label>
<input id="firm" type="range" min="0" max="100" value="35">
<label for="firm2">Gummy</label>
</div>
<button id="drop" type="button">Drop it!</button>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<script>
(function () {
"use strict";
// ---------- helpers ----------
var DEMO = (location.hash === "#demo");
function safeGet(k) { try { return localStorage.getItem(k); } catch (e) { return null; } }
function safeSet(k, v) { try { localStorage.setItem(k, v); } catch (e) {} }
// ---------- audio: small wet sounds made in code ----------
var actx = null;
function audio() {
if (!actx) { try { actx = new (window.AudioContext || window.webkitAudioContext)(); } catch (e) { actx = null; } }
if (actx && actx.state === "suspended") { try { actx.resume(); } catch (e) {} }
return actx;
}
function blip(freq, dur, vol, slide) {
var a = audio(); if (!a) return;
try {
var o = a.createOscillator(), g = a.createGain(), t = a.currentTime;
o.type = "sine";
o.frequency.setValueAtTime(freq, t);
if (slide) o.frequency.exponentialRampToValueAtTime(Math.max(40, freq * slide), t + dur);
g.gain.setValueAtTime(0.0001, t);
g.gain.exponentialRampToValueAtTime(vol, t + 0.01);
g.gain.exponentialRampToValueAtTime(0.0001, t + dur);
o.connect(g); g.connect(a.destination); o.start(t); o.stop(t + dur + 0.02);
} catch (e) {}
}
function wet(strength) {
// a short "bloop": a damped sine plus a noise pop
var s = Math.min(1, Math.max(0.2, strength || 0.5));
blip(260 + 180 * Math.random(), 0.16, 0.10 * s, 0.45);
var a = audio(); if (!a) return;
try {
var len = Math.floor(a.sampleRate * 0.04), buf = a.createBuffer(1, len, a.sampleRate), d = buf.getChannelData(0);
for (var i = 0; i < len; i++) d[i] = (Math.random() * 2 - 1) * Math.pow(1 - i / len, 3);
var src = a.createBufferSource(), g = a.createGain(); src.buffer = buf; g.gain.value = 0.25 * s;
src.connect(g); g.connect(a.destination); src.start();
} catch (e) {}
}
function purr() {
var a = audio(); if (!a) return;
try {
var o = a.createOscillator(), l = a.createOscillator(), lg = a.createGain(), g = a.createGain(), t = a.currentTime;
o.type = "sawtooth"; o.frequency.value = 30; l.frequency.value = 22; lg.gain.value = 0.6;
g.gain.setValueAtTime(0.0001, t); g.gain.exponentialRampToValueAtTime(0.05, t + 0.2); g.gain.exponentialRampToValueAtTime(0.0001, t + 1.4);
l.connect(lg); lg.connect(g.gain); o.connect(g); g.connect(a.destination);
o.start(t); l.start(t); o.stop(t + 1.5); l.stop(t + 1.5);
} catch (e) {}
}
// ---------- three.js scene ----------
var canvas = document.getElementById("c");
var renderer, scene, camera, cat, plate, raycaster, pointer = new (window.THREE ? THREE.Vector2 : Object)();
var jelly = { mat: null, geo: null, base: null, pos: null, vel: null };
var soft = 0.35; // 0 = firm gummy, 1 = soft pudding
var firmInput = document.getElementById("firm");
soft = 1 - (parseFloat(firmInput.value) || 35) / 100;
function init() {
renderer = new THREE.WebGLRenderer({ canvas: canvas, antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
scene = new THREE.Scene();
scene.background = new THREE.Color(getComputedStyle(document.documentElement).getPropertyValue("--bg").trim() || "#fff4e0");
camera = new THREE.PerspectiveCamera(40, 1, 0.1, 100);
camera.position.set(0, 1.6, 7.2);
camera.lookAt(0, 0.9, 0);
scene.add(new THREE.AmbientLight(0xffe2b8, 0.7));
var key = new THREE.DirectionalLight(0xffffff, 0.9); key.position.set(3, 6, 5); scene.add(key);
var rim = new THREE.PointLight(0xffb060, 1.2, 20); rim.position.set(-3, 2, -2); scene.add(rim);
// plate
var pg = new THREE.CylinderGeometry(2.2, 2.4, 0.22, 48);
var pm = new THREE.MeshStandardMaterial({ color: 0xf8f4ee, roughness: 0.35, metalness: 0.0 });
plate = new THREE.Mesh(pg, pm); plate.position.y = -0.1; plate.receiveShadow = true; scene.add(plate);
// jelly cat body: a deformable sphere-based mesh (vertices move with a soft spring model)
buildCat();
raycaster = new THREE.Raycaster();
resize();
window.addEventListener("resize", resize);
}
function resize() {
var w = window.innerWidth, h = window.innerHeight;
renderer.setSize(w, h, false);
camera.aspect = w / h;
camera.position.z = w / h < 0.8 ? 9.5 : 7.2;
camera.updateProjectionMatrix();
}
// Build a chubby seated cat from a deformable sphere: body, head, ears, tail, cheeks.
// Each control point has a rest position and a velocity; the mesh is re-shaped every frame.
var parts = {};
function buildCat() {
jelly.mat = new THREE.MeshPhysicalMaterial({
color: 0xff8a2a, transmission: 0.82, thickness: 1.2, roughness: 0.12, metalness: 0,
ior: 1.33, clearcoat: 1, clearcoatRoughness: 0.08, transparent: true, opacity: 0.94,
emissive: 0xff7a1a, emissiveIntensity: 0.18
});
// Base: a fat sphere for body, then a sphere for head, plus small ear cones and a tail tube.
var body = new THREE.SphereGeometry(1.35, 48, 36);
var head = new THREE.SphereGeometry(0.95, 40, 30);
var ear = new THREE.ConeGeometry(0.34, 0.6, 24);
var tail = new THREE.TubeGeometry(new THREE.CatmullRomCurve3([
new THREE.Vector3(0.9, -0.9, 0), new THREE.Vector3(1.6, -0.6, 0.2),
new THREE.Vector3(2.0, 0.0, 0.2), new THREE.Vector3(1.9, 0.5, 0.2)
]), 24, 0.22, 16, false);
var group = new THREE.Group(); scene.add(group); cat = group;
parts.body = new THREE.Mesh(body, jelly.mat); parts.body.scale.set(1.0, 1.15, 0.95); parts.body.position.y = 0.95;
parts.head = new THREE.Mesh(head, jelly.mat); parts.head.position.set(0, 2.35, 0.1);
parts.earL = new THREE.Mesh(ear, jelly.mat); parts.earL.position.set(-0.55, 3.1, 0.05); parts.earL.rotation.z = 0.35;
parts.earR = new THREE.Mesh(ear, jelly.mat); parts.earR.position.set(0.55, 3.1, 0.05); parts.earR.rotation.z = -0.35;
parts.tail = new THREE.Mesh(tail, jelly.mat); parts.tail.position.set(0, 0, 0);
parts.cheekL = new THREE.Mesh(new THREE.SphereGeometry(0.28, 20, 16), jelly.mat); parts.cheekL.position.set(-0.55, 2.1, 0.7);
parts.cheekR = new THREE.Mesh(new THREE.SphereGeometry(0.28, 20, 16), jelly.mat); parts.cheekR.position.set(0.55, 2.1, 0.7);
// eyes: dark glossy dots that follow the finger
var eyeMat = new THREE.MeshStandardMaterial({ color: 0x2a1408, roughness: 0.2 });
parts.eyeL = new THREE.Mesh(new THREE.SphereGeometry(0.1, 16, 12), eyeMat); parts.eyeL.position.set(-0.32, 2.45, 0.86);
parts.eyeR = new THREE.Mesh(new THREE.SphereGeometry(0.1, 16, 12), eyeMat); parts.eyeR.position.set(0.32, 2.45, 0.86);
// bubbles: tiny spheres inside the jelly
parts.bubbles = [];
var bg = new THREE.SphereGeometry(0.05, 10, 8);
var bm = new THREE.MeshStandardMaterial({ color: 0xffffff, transparent: true, opacity: 0.55 });
for (var i = 0; i < 9; i++) {
var b = new THREE.Mesh(bg, bm);
b.position.set((Math.random() - 0.5) * 1.6, 0.6 + Math.random() * 1.6, (Math.random() - 0.5) * 0.9);
group.add(b); parts.bubbles.push(b);
}
Object.keys(parts).forEach(function (k) { if (k !== "bubbles") group.add(parts[k]); });
group.position.y = 0.05;
// spring state for the whole body: a few anchor points that wobble
jelly.anchors = [];
group.updateMatrixWorld(true);
}
// ---------- physics: squish spring for the cat as a whole ----------
var state = { y: 0, vy: 0, sx: 1, sy: 1, sz: 1, vsx: 0, vsy: 0, vsz: 0 };
var grab = null; // { part, startPoint, pulled }
var targets = { ear: 0, cheek: 0, tail: 0 };
function stiffness() { return 2.2 + (1 - soft) * 7.5; } // gummy stiffer
function damping() { return 0.9 + (1 - soft) * 2.0; }
function step(dt) {
var k = stiffness(), c = damping();
// cat-level spring towards scale 1
var ax = -k * (state.sx - 1) - c * state.vsx;
var ay = -k * (state.sy - 1) - c * state.vsy;
var az = -k * (state.sz - 1) - c * state.vsz;
state.vsx += ax * dt; state.sx += state.vsx * dt;
state.vsy += ay * dt; state.sy += state.vsy * dt;
state.vsz += az * dt; state.sz += state.vsz * dt;
// vertical bounce
var gy = -k * state.y - c * state.vy;
state.vy += gy * dt; state.y += state.vy * dt;
if (state.y < -0.6) { state.y = -0.6; state.vy = Math.abs(state.vy) * 0.2; }
// parts follow the body
var sx = state.sx, sy = state.sy, sz = state.sz;
cat.scale.set(sx, sy, sz);
cat.position.y = 0.05 + state.y;
// ears / cheeks / tail get their own springy wobble
jitter(parts.earL, targets.ear, dt, -1);
jitter(parts.earR, targets.ear, dt, 1);
jitter(parts.cheekL, targets.cheek, dt, -1);
jitter(parts.cheekR, targets.cheek, dt, 1);
jitter(parts.tail, targets.tail, dt, 0);
}
var wob = {};
function jitter(mesh, amount, dt, side) {
if (!mesh) return;
var key = mesh.uuid;
var s = wob[key] || (wob[key] = { p: 0, v: 0 });
var k = 60, c = 5;
s.v += (-k * s.p - c * s.v + amount * side * 12) * dt;
s.p += s.v * dt;
mesh.rotation.z = s.p * 0.5 * side;
mesh.position.y += 0; // position kept by parent
}
// ---------- mouse / touch interaction ----------
function toNdc(clientX, clientY) {
var r = canvas.getBoundingClientRect();
return { x: ((clientX - r.left) / r.width) * 2 - 1, y: -((clientY - r.top) / r.height) * 2 + 1 };
}
function hitPart(clientX, clientY) {
var p = toNdc(clientX, clientY);
raycaster.setFromCamera(p, camera);
var list = [parts.body, parts.head, parts.earL, parts.earR, parts.cheekL, parts.cheekR, parts.tail];
var hits = raycaster.intersectObjects(list, false);
return hits.length ? { name: nameOf(hits[0].object), point: hits[0].point } : null;
}
function nameOf(obj) {
for (var k in parts) if (parts[k] === obj) return k;
return "body";
}
var pressing = null; // { name, x0, y0, t0 }
var purrTimer = 0;
var lastFinger = null;
function pressStart(x, y) {
audio();
var h = hitPart(x, y);
if (!h) return;
pressing = { name: h.name, x0: x, y0: y, t0: performance.now(), dragged: 0 };
wet(0.7);
// squish whichever part was touched
if (h.name === "body" || h.name === "head") { state.vsy -= 1.6; state.vsx += 0.4; }
if (h.name === "earL" || h.name === "earR") targets.ear = 1;
if (h.name === "cheekL" || h.name === "cheekR") targets.cheek = 1;
if (h.name === "tail") targets.tail = 1;
lastFinger = { x: x, y: y };
}
function pressMove(x, y) {
if (!pressing) return;
var dx = x - (lastFinger ? lastFinger.x : x), dy = y - (lastFinger ? lastFinger.y : y);
lastFinger = { x: x, y: y };
pressing.dragged += Math.abs(dx) + Math.abs(dy);
// dragging the touched part pulls it: displacement feeds the spring
var amt = 0.004 * (1 - soft * 0.3);
if (pressing.name === "earL" || pressing.name === "earR") { state.sx += dx * amt; state.sy -= dy * amt * 0.2; }
else if (pressing.name === "tail") { state.sx += dx * amt * 0.5; }
else { state.sx += dx * amt * 0.6; state.sy -= dy * amt * 0.8; state.sz += dy * amt * 0.2; }
// eyes follow the finger
lookAt(x, y);
// rub the head: purr
if (pressing.name === "head" && Math.abs(dx) + Math.abs(dy) > 6) {
if (performance.now() - purrTimer > 1400) { purrTimer = performance.now(); purr(); }
state.sy += 0.001 * (Math.random() - 0.5);
}
// squints when rubbed: scale eyes
if (pressing.name === "head") squint = Math.min(1, squint + 0.04); // grows while rubbing
}
function pressEnd() {
if (!pressing) return;
var held = performance.now() - pressing.t0;
if (pressing.name === "tail") targets.tail = 0;
if (pressing.name === "earL" || pressing.name === "earR") targets.ear = 0;
if (pressing.name === "cheekL" || pressing.name === "cheekR") targets.cheek = 0;
// release: wobble back into shape
state.vsx += (1 - state.sx) * 0.0;
state.vsy += 1.2 * (held > 300 ? 1 : 0.4);
if (pressing.dragged > 20 && held < 600) wet(0.5);
pressing = null;
lastFinger = null;
squint = Math.max(0, squint - 0.05);
}
// eyes / squint
var eyeTarget = { x: 0, y: 0 }, squint = 0;
function lookAt(x, y) {
var p = toNdc(x, y);
eyeTarget.x = p.x * 0.12; eyeTarget.y = p.y * 0.08;
}
function updateEyes(dt) {
if (!parts.eyeL) return;
var k = Math.min(1, dt * 10);
parts.eyeL.position.x += (-0.32 + eyeTarget.x - parts.eyeL.position.x) * k;
parts.eyeR.position.x += (0.32 + eyeTarget.x - parts.eyeR.position.x) * k;
parts.eyeL.position.y += (2.45 + eyeTarget.y - parts.eyeL.position.y) * k;
parts.eyeR.position.y += (2.45 + eyeTarget.y - parts.eyeR.position.y) * k;
var sq = 1 - 0.7 * squint;
parts.eyeL.scale.set(1, sq, 1); parts.eyeR.scale.set(1, sq, 1);
}
// pointer events cover mouse and touch (one finger)
canvas.addEventListener("pointerdown", function (e) {
if (DEMO && demoActive) stopDemo();
canvas.setPointerCapture && canvas.setPointerCapture(e.pointerId);
pressStart(e.clientX, e.clientY);
});
canvas.addEventListener("pointermove", function (e) {
if (DEMO && demoActive) return;
pressMove(e.clientX, e.clientY);
if (!pressing) lookAt(e.clientX, e.clientY);
});
canvas.addEventListener("pointerup", function (e) { pressEnd(); });
canvas.addEventListener("pointercancel", function (e) { pressEnd(); });
canvas.addEventListener("contextmenu", function (e) { e.preventDefault(); });
// ---------- controls ----------
firmInput.addEventListener("input", function () {
soft = 1 - (parseFloat(firmInput.value) || 0) / 100;
safeSet("jelly-cat-firm", firmInput.value);
});
var savedFirm = safeGet("jelly-cat-firm");
if (savedFirm !== null) { firmInput.value = savedFirm; soft = 1 - (parseFloat(savedFirm) || 35) / 100; }
var dropBtn = document.getElementById("drop");
var dropping = null; // { y, vy }
dropBtn.addEventListener("click", function () {
if (DEMO && demoActive) stopDemo();
audio();
dropping = { y: 6.0, vy: 0 };
state.y = 6.0; state.vy = 0; // start high, fall with gravity
});
// ---------- demo mode (#demo): ~20s hands-free loop ----------
var demoActive = DEMO, demoT = 0;
function stopDemo() { demoActive = false; }
function runDemo(dt) {
demoT += dt;
var t = demoT;
if (t > 20) demoT = 0;
// scripted pokes, a squeeze, an ear pull, a purr, a drop
if (Math.abs(t - 2) < dt) { state.vsy -= 1.6; wet(0.8); }
if (Math.abs(t - 5) < dt) { state.vsx += 0.5; state.vsy -= 0.8; wet(0.6); }
if (Math.abs(t - 8) < dt) { targets.ear = 1; wet(0.5); }
if (Math.abs(t - 10) < dt) { targets.ear = 0; targets.cheek = 1; purr(); }
if (Math.abs(t - 13) < dt) { targets.cheek = 0; state.vsy += 1.0; }
if (Math.abs(t - 16) < dt) { dropping = { y: 6.0, vy: 0 }; state.y = 6.0; state.vy = 0; }
eyeTarget.x = Math.sin(t * 0.9) * 0.1; eyeTarget.y = Math.cos(t * 0.7) * 0.05;
}
// ---------- main loop ----------
var last = performance.now();
var t0 = last;
function frame(now) {
var dt = Math.min(0.033, (now - last) / 1000);
last = now;
// drop from above with gravity, land with a big wobble
if (dropping) {
dropping.vy -= 22 * dt;
dropping.y += dropping.vy * dt;
state.y = dropping.y;
if (dropping.y <= 0) {
state.y = 0; dropping = null;
state.vy = -3.2; state.vsy = -1.4; state.vsx = 0.8;
wet(1.0);
}
}
if (demoActive) runDemo(dt);
step(dt);
updateEyes(dt);
if (squint > 0) squint = Math.max(0, squint - dt * 0.4);
renderer.render(scene, camera);
requestAnimationFrame(frame);
}
try {
init();
requestAnimationFrame(frame);
} catch (err) {
document.getElementById("hint").textContent = "Could not start 3D view on this device.";
}
})();
</script>
</body>
</html>
