Skip to content
VibeCodeBench
Back to the app

The code

Pelican on a Bike by Claude Opus 5.5

Exactly as the AI wrote it. Shown as text, so nothing runs on this page.

Try 1 · index.html

worksshown34.7 KB · 609 lines · no libraries
Download
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
<title>Pelican Promenade</title>
<style>
:root{--ink:#22313f;--panel:rgba(255,255,255,.9);--accent:#e4572e}
*{box-sizing:border-box}
html,body{margin:0;height:100%;overflow:hidden;background:#bfe6f7;font-family:system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;color:var(--ink);-webkit-tap-highlight-color:transparent;user-select:none;-webkit-user-select:none}
#scene{position:fixed;inset:0;width:100%;height:100%;display:block;touch-action:manipulation;cursor:pointer}
.panel{background:var(--panel);border-radius:16px;box-shadow:0 4px 14px rgba(0,0,0,.15)}
#top{position:fixed;top:0;left:0;right:0;display:flex;flex-wrap:wrap;gap:8px;justify-content:space-between;align-items:flex-start;padding:calc(10px + env(safe-area-inset-top)) 12px 0;pointer-events:none}
.badge{padding:8px 14px;font-weight:800;font-size:16px;letter-spacing:.2px}
.badge span{color:var(--accent)}
#hint{padding:8px 14px;font-size:14px;font-weight:600;transition:opacity .6s}
#hint.gone{opacity:0}
#demoTag{display:none;padding:8px 14px;font-size:13px;font-weight:700;background:#22313f;color:#fff}
#hud{position:fixed;left:0;right:0;bottom:0;display:flex;flex-wrap:wrap;justify-content:center;align-items:center;gap:8px 10px;padding:10px 12px calc(10px + env(safe-area-inset-bottom));pointer-events:none}
#hud>*{pointer-events:auto}
.speed{display:flex;align-items:center;gap:10px;padding:4px 14px;min-height:52px;flex:1 1 250px;max-width:420px}
.speed label{font-weight:800;font-size:15px}
#speedVal{min-width:4.4em;text-align:right;font-variant-numeric:tabular-nums;font-size:14px;font-weight:600}
input[type=range]{flex:1;min-width:80px;height:44px;-webkit-appearance:none;appearance:none;background:transparent;margin:0;cursor:pointer;touch-action:none}
input[type=range]::-webkit-slider-runnable-track{height:10px;border-radius:5px;background:linear-gradient(90deg,#7cc8e8,#e4572e)}
input[type=range]::-webkit-slider-thumb{-webkit-appearance:none;width:28px;height:28px;border-radius:50%;background:#fff;border:3px solid var(--ink);margin-top:-9px;box-shadow:0 2px 4px rgba(0,0,0,.3)}
input[type=range]::-moz-range-track{height:10px;border-radius:5px;background:linear-gradient(90deg,#7cc8e8,#e4572e)}
input[type=range]::-moz-range-thumb{width:22px;height:22px;border-radius:50%;background:#fff;border:3px solid var(--ink)}
input[type=range]:focus-visible{outline:3px solid #1d6fa3;outline-offset:2px;border-radius:8px}
.btns{display:flex;gap:8px;flex-wrap:wrap;justify-content:center}
button{min-width:48px;min-height:48px;border:0;border-radius:14px;padding:0 12px;font-family:inherit;font-weight:700;font-size:14px;color:var(--ink);background:var(--panel);box-shadow:0 4px 14px rgba(0,0,0,.15);cursor:pointer;display:inline-flex;align-items:center;justify-content:center;gap:6px;touch-action:manipulation}
button svg{width:20px;height:20px;flex:none}
button:active{transform:scale(.94)}
button:focus-visible{outline:3px solid #1d6fa3;outline-offset:2px}
button.on{background:#ffe1d6}
@media (max-width:400px){button .t{display:none}button{padding:0;width:52px}}
#ptr{position:fixed;left:0;top:0;z-index:30;pointer-events:none;display:none;transform:translate(-100px,-100px);filter:drop-shadow(0 2px 3px rgba(0,0,0,.4))}
#ptr svg{display:block;transition:transform .12s}
#ptr.press svg{transform:scale(.82)}
#ripple{position:fixed;left:0;top:0;width:44px;height:44px;margin:-22px 0 0 -22px;border-radius:50%;border:3px solid #fff;z-index:29;pointer-events:none;opacity:0}
#ripple.go{animation:rip .5s ease-out}
@keyframes rip{from{opacity:.95;transform:scale(.3)}to{opacity:0;transform:scale(1.5)}}
.bob{animation:bob 2.8s ease-in-out infinite alternate;transform-box:fill-box;transform-origin:50% 100%}
@keyframes bob{from{transform:translateY(-1.5px) rotate(-3deg)}to{transform:translateY(1.5px) rotate(3deg)}}
.lowq .hq{display:none}
.lowq .bob{animation:none}
</style>
</head>
<body>
<svg id="scene" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 800 500" preserveAspectRatio="xMidYMid meet" aria-label="A pelican riding a bicycle along a seaside promenade">
<defs>
 <linearGradient id="skyG" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stop-color="#63bff0"/><stop offset=".7" stop-color="#bfe6f7"/><stop offset="1" stop-color="#ffe9c9"/></linearGradient>
 <linearGradient id="seaG" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stop-color="#6cc3dc"/><stop offset="1" stop-color="#2479a8"/></linearGradient>
 <radialGradient id="sunG"><stop offset=".45" stop-color="#fff3b0"/><stop offset="1" stop-color="#fff3b0" stop-opacity="0"/></radialGradient>
</defs>
<g id="bg"></g>
<g id="L_clouds"></g>
<g id="seaStatic"></g>
<g id="L_far"></g>
<g id="L_waves"></g>
<g id="L_boats"></g>
<g id="wallStatic"></g>
<g id="L_wall"></g>
<g id="groundStatic"></g>
<g id="L_ground"></g>
<g id="bike">
 <ellipse cx="2" cy="1" rx="112" ry="6" fill="#000" opacity=".16"/>
 <g id="wheelR"></g>
 <g id="wheelF"></g>
 <line id="crankFar" stroke="#3a3a3a" stroke-width="4" stroke-linecap="round"/>
 <rect id="pedalFar" width="16" height="4" rx="1.5" fill="#2a2a2a"/>
 <g id="legFar"><path class="t" fill="none" stroke="#d6dbe1" stroke-width="10" stroke-linecap="round"/><path class="s" fill="none" stroke="#cf721f" stroke-width="5" stroke-linecap="round"/><path class="f" fill="#cf721f" stroke="#9c5214" stroke-width="1.2" stroke-linejoin="round"/></g>
 <path d="M-78 -46 L0 -40 L-20 -112 Z M-20 -112 L61 -108 M0 -40 L65 -95" fill="none" stroke="#a63a1c" stroke-width="7.5" stroke-linejoin="round" stroke-linecap="round"/>
 <path d="M66 -94 Q 74 -64 82 -46" fill="none" stroke="#a63a1c" stroke-width="6.5" stroke-linecap="round"/>
 <path d="M60 -114 L67 -90" stroke="#a63a1c" stroke-width="9.5" stroke-linecap="round"/>
 <path d="M-78 -46 L0 -40 L-20 -112 Z M-20 -112 L61 -108 M0 -40 L65 -95" fill="none" stroke="#e4572e" stroke-width="5" stroke-linejoin="round" stroke-linecap="round"/>
 <path d="M66 -94 Q 74 -64 82 -46" fill="none" stroke="#e4572e" stroke-width="4" stroke-linecap="round"/>
 <path d="M60 -114 L67 -90" stroke="#e4572e" stroke-width="7" stroke-linecap="round"/>
 <path id="chainBase" d="M0 -51 L-78 -51 A5 5 0 0 0 -78 -41 L0 -29 A11 11 0 0 0 0 -51 Z" fill="none" stroke="#3b3b3b" stroke-width="3.2"/>
 <path id="chainLinks" d="M0 -51 L-78 -51 A5 5 0 0 0 -78 -41 L0 -29 A11 11 0 0 0 0 -51 Z" fill="none" stroke="#a9b2b8" stroke-width="1.6"/>
 <g id="ring">
  <circle cx="0" cy="-40" r="11" fill="none" stroke="#555" stroke-width="3" stroke-dasharray="2 1.5"/>
  <circle cx="0" cy="-40" r="9" fill="#c9d1d6" stroke="#666" stroke-width="1"/>
  <path d="M0 -40 L0 -48 M0 -40 L7.6 -42.5 M0 -40 L4.7 -33.5 M0 -40 L-4.7 -33.5 M0 -40 L-7.6 -42.5" stroke="#777" stroke-width="2"/>
  <circle cx="0" cy="-40" r="3" fill="#555"/>
 </g>
 <line x1="-20" y1="-112" x2="-23" y2="-122" stroke="#8a8f94" stroke-width="4" stroke-linecap="round"/>
 <path d="M-41 -124 Q -24 -129 -9 -123 Q -11 -118 -24 -119 Q -37 -119 -41 -124 Z" fill="#2f2f33" stroke="#111" stroke-width="1"/>
 <g id="upper">
  <g id="wingFar"><path class="wb" fill="#cfd6dd" stroke="#8a96a0" stroke-width="1.5" stroke-linejoin="round"/><path class="wt" fill="#1f1f22"/></g>
  <path d="M-52 -156 L-84 -152 L-76 -147 L-86 -141 L-74 -139 L-80 -133 L-50 -136 Z" fill="#e9ecef" stroke="#8a96a0" stroke-width="1.5" stroke-linejoin="round"/>
  <path d="M4 -160 C 24 -178, 2 -196, 16 -210" fill="none" stroke="#8a96a0" stroke-width="19" stroke-linecap="round"/>
  <ellipse cx="-22" cy="-150" rx="40" ry="25" transform="rotate(-14 -22 -150)" fill="#fff" stroke="#8a96a0" stroke-width="2"/>
  <path d="M-44 -137 Q -22 -128 0 -139" fill="none" stroke="#e6eaee" stroke-width="3" stroke-linecap="round"/>
  <path d="M4 -160 C 24 -178, 2 -196, 16 -210" fill="none" stroke="#fff" stroke-width="15" stroke-linecap="round"/>
  <path d="M7 -176 Q 12 -184 9 -192" fill="none" stroke="#f3e3a0" stroke-width="3" stroke-linecap="round"/>
  <g id="head">
   <circle cx="18" cy="-214" r="13" fill="#fff" stroke="#8a96a0" stroke-width="2"/>
   <path d="M8 -224 Q 1 -233 10 -230 Q 6 -237 15 -232" fill="none" stroke="#f0cf5c" stroke-width="2.4" stroke-linecap="round"/>
   <path id="pouch" d="M27 -208 L91 -200 C80 -187 46 -182 26 -201 Z" fill="#f7a07a" stroke="#d9774f" stroke-width="1.5" stroke-linejoin="round"/>
   <path d="M24 -223 Q 60 -216 95 -205 Q 101 -202 96 -198 Q 93 -201 90 -201 Q 58 -208 26 -209 Z" fill="#f4b63f" stroke="#c8851a" stroke-width="1.5" stroke-linejoin="round"/>
   <path d="M30 -218 Q 60 -212 91 -203.5" fill="none" stroke="#e39a22" stroke-width="1.2"/>
   <circle cx="13" cy="-207" r="3.2" fill="#ffb3b3" opacity=".6"/>
   <circle cx="21" cy="-217" r="3.6" fill="#fff5c2" stroke="#d6b44a" stroke-width="1"/>
   <circle id="pupil" cx="21.4" cy="-217" r="2" fill="#1b1b1b"/>
   <circle cx="22.1" cy="-217.8" r=".75" fill="#fff"/>
  </g>
 </g>
 <g id="legNear"><path class="t" fill="none" stroke="#f4f6f8" stroke-width="10" stroke-linecap="round"/><path class="s" fill="none" stroke="#f08a24" stroke-width="5" stroke-linecap="round"/><path class="f" fill="#f08a24" stroke="#b9601a" stroke-width="1.2" stroke-linejoin="round"/></g>
 <line id="crankNear" stroke="#4a4a4a" stroke-width="4.5" stroke-linecap="round"/>
 <rect id="pedalNear" width="16" height="4" rx="1.5" fill="#333"/>
 <line x1="60" y1="-114" x2="57" y2="-128" stroke="#8a8f94" stroke-width="4" stroke-linecap="round"/>
 <path d="M50 -128 Q 66 -134 78 -125" fill="none" stroke="#5a5f64" stroke-width="4" stroke-linecap="round"/>
 <path d="M72 -128.5 L80 -122.5" stroke="#222" stroke-width="6.5" stroke-linecap="round"/>
 <g id="bell">
  <path d="M57 -133 Q 57 -143 63 -143 Q 69 -143 69 -133 Z" fill="#f2c14e" stroke="#b88a1f" stroke-width="1.2"/>
  <circle cx="63" cy="-144" r="1.5" fill="#b88a1f"/>
  <g id="clap"><circle cx="63" cy="-132" r="1.8" fill="#8a6a14"/></g>
 </g>
 <g id="upper2">
  <g id="wingNear"><path class="wb" fill="#fff" stroke="#8a96a0" stroke-width="1.6" stroke-linejoin="round"/><path class="wt" fill="#26262a"/><path class="wl" fill="none" stroke="#c4ccd3" stroke-width="1.3" stroke-linecap="round"/></g>
 </g>
 <g id="bubble" opacity="0">
  <rect x="8" y="-292" width="104" height="32" rx="14" fill="#fff" stroke="#22313f" stroke-width="2"/>
  <path d="M40 -261 L34 -248 L50 -261" fill="#fff" stroke="#22313f" stroke-width="2" stroke-linejoin="round"/>
  <rect x="38" y="-263" width="13" height="4" fill="#fff"/>
  <text x="60" y="-270.5" text-anchor="middle" font-size="16" font-weight="800" fill="#e4572e" font-family="system-ui,sans-serif">Ring ring!</text>
 </g>
 <g id="fx"></g>
</g>
</svg>

<div id="top">
 <div class="badge panel">Pelican <span>Promenade</span></div>
 <div id="hint" class="panel">Tap anywhere to flap!</div>
 <div id="demoTag" class="panel">DEMO &middot; tap to take over</div>
</div>

<div id="hud">
 <div class="speed panel">
  <label for="spd">Speed</label>
  <input id="spd" type="range" min="0" max="100" value="45" aria-label="Speed">
  <span id="speedVal">0 km/h</span>
 </div>
 <div class="btns">
  <button id="bBell" aria-label="Ring the bell"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M6 16V11a6 6 0 0 1 12 0v5l2 2H4z"/><path d="M10 21h4"/></svg><span class="t">Bell</span></button>
  <button id="bFlap" aria-label="Flap wings"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 15c4-1 6-5 7-10 1 5 3 8 11 9-5 2-9 2-11 6-2-3-4-4-7-5z"/></svg><span class="t">Flap</span></button>
  <button id="bMute" aria-label="Mute sound" aria-pressed="false"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 9h4l5-4v14l-5-4H4z"/><path id="muteA" d="M16.5 8.5a5 5 0 0 1 0 7M19 6a8.5 8.5 0 0 1 0 12"/><path id="muteB" d="M16 9l6 6M22 9l-6 6" style="display:none"/></svg><span class="t" id="muteTxt">Sound</span></button>
  <button id="bReset" aria-label="Restart"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 12a8 8 0 1 0 2.5-5.8"/><path d="M4 4v5h5"/></svg><span class="t">Restart</span></button>
 </div>
</div>

<div id="ptr"><svg width="30" height="30" viewBox="0 0 28 28"><path d="M3 2 L3 22 L8.5 17 L12 25 L15.5 23.5 L12 16 L19 16 Z" fill="#fff" stroke="#111" stroke-width="1.8" stroke-linejoin="round"/></svg></div>
<div id="ripple"></div>

<script>
(function(){
'use strict';
var NS='http://www.w3.org/2000/svg';
function $(id){return document.getElementById(id);}
function el(tag,attrs,parent){var e=document.createElementNS(NS,tag);if(attrs)for(var k in attrs)e.setAttribute(k,attrs[k]);if(parent)parent.appendChild(e);return e;}
function mulberry32(a){return function(){a|=0;a=a+0x6D2B79F5|0;var t=Math.imul(a^a>>>15,1|a);t=t+Math.imul(t^t>>>7,61|t)^t;return((t^t>>>14)>>>0)/4294967296;};}
function mod(a,b){return((a%b)+b)%b;}
function clamp(v,a,b){return v<a?a:v>b?b:v;}

var svg=$('scene'), spd=$('spd'), speedVal=$('speedVal');
var RW=1632;            // repeat width for scrolling layers (multiple of 32, 48, 272)
var MAXS=320;           // max speed in scene units / second
var W=800,H=500,G=430,HZ=260,bikeX=400,bikeS=1;
var layers=[];

/* ---------- Bike geometry (local coords, ground at y=0) ---------- */
var BB={x:0,y:-40}, RA={x:-78,y:-46}, FA={x:82,y:-46};
var WR=46, CR=11, SR=5, CL=17;     // wheel radius, chainring, sprocket, crank length
var HIP={x:-14,y:-130}, L1=50, L2=56;

/* ---------- Scenery ---------- */
function makeLayer(id,f,gen){
  var host=$(id); host.textContent='';
  var mover=el('g',null,host), tile=el('g',null,mover);
  gen(tile);
  var c=tile.cloneNode(true); c.setAttribute('transform','translate('+RW+' 0)'); mover.appendChild(c);
  layers.push({g:mover,f:f});
}

function build(){
  var rng=mulberry32(20250930);
  layers=[];
  var seaB=G-40;
  // sky + sun
  var bg=$('bg'); bg.textContent='';
  el('rect',{x:0,y:0,width:W,height:HZ+2,fill:'url(#skyG)'},bg);
  var sx=W*0.8, sy=Math.max(48,HZ*0.42);
  el('circle',{cx:sx,cy:sy,r:70,fill:'url(#sunG)','class':'hq'},bg);
  el('circle',{cx:sx,cy:sy,r:30,fill:'#fff1a8'},bg);

  // clouds (slowest)
  makeLayer('L_clouds',0.06,function(t){
    for(var i=0;i<7;i++){
      var x=110+i*(RW-220)/7+rng()*70, y=26+rng()*Math.max(10,HZ-110), s=0.55+rng()*0.7;
      var g=el('g',{transform:'translate('+x.toFixed(1)+' '+y.toFixed(1)+') scale('+s.toFixed(2)+')',fill:'#fff',opacity:'.93'},t);
      el('ellipse',{cx:0,cy:0,rx:62,ry:15},g);
      el('circle',{cx:-30,cy:-8,r:21},g);el('circle',{cx:0,cy:-18,r:29},g);
      el('circle',{cx:30,cy:-7,r:19},g);el('circle',{cx:14,cy:-4,r:22},g);
    }
    for(var j=0;j<4;j++){
      var bx=100+rng()*(RW-200), by=30+rng()*Math.max(10,HZ-90);
      el('path',{d:'M'+bx.toFixed(1)+' '+by.toFixed(1)+' q5 -6 10 0 q5 -6 10 0',fill:'none',stroke:'#3a4b5a','stroke-width':1.8,'stroke-linecap':'round'},t);
    }
  });

  // sea (static body)
  var ss=$('seaStatic'); ss.textContent='';
  el('rect',{x:0,y:HZ,width:W,height:seaB-HZ+2,fill:'url(#seaG)'},ss);
  el('rect',{x:sx-40,y:HZ+2,width:80,height:Math.min(60,seaB-HZ),fill:'#fff6c8',opacity:'.25','class':'hq'},ss);
  el('line',{x1:0,y1:HZ,x2:W,y2:HZ,stroke:'#e8f6fb','stroke-width':1.5},ss);

  // far islands with lighthouse
  makeLayer('L_far',0.03,function(t){
    var xs=[260,800,1260];
    for(var i=0;i<3;i++){
      var x0=xs[i]+rng()*60, w=170+rng()*140, h=16+rng()*24;
      el('path',{d:'M'+x0+' '+HZ+' C'+(x0+w*0.25)+' '+(HZ-h)+' '+(x0+w*0.6)+' '+(HZ-h*1.15)+' '+(x0+w)+' '+HZ+' Z',fill:'#88b5ae'},t);
      if(i===1){
        var lx=x0+w*0.45, ly=HZ-h*1.02;
        el('rect',{x:lx-4,y:ly-30,width:8,height:30,fill:'#fff'},t);
        el('rect',{x:lx-4,y:ly-22,width:8,height:5,fill:'#e4572e'},t);
        el('rect',{x:lx-4,y:ly-11,width:8,height:5,fill:'#e4572e'},t);
        el('rect',{x:lx-3,y:ly-36,width:6,height:6,fill:'#ffe08a'},t);
        el('path',{d:'M'+(lx-5)+' '+(ly-36)+' L'+lx+' '+(ly-41)+' L'+(lx+5)+' '+(ly-36)+' Z',fill:'#e4572e'},t);
      }
    }
  });

  // waves
  makeLayer('L_waves',0.25,function(t){
    for(var i=0;i<48;i++){
      var x=rng()*(RW-40), yy=Math.pow(rng(),1.3), y=HZ+6+yy*(seaB-HZ-12), s=0.45+yy*1.1;
      el('path',{d:'M'+x.toFixed(1)+' '+y.toFixed(1)+' q'+(5*s).toFixed(1)+' '+(-3*s).toFixed(1)+' '+(10*s).toFixed(1)+' 0 t'+(10*s).toFixed(1)+' 0',fill:'none',stroke:'#fff',opacity:'.55','stroke-width':1.4,'stroke-linecap':'round','class':i%2?'hq':''},t);
    }
  });

  // boats
  makeLayer('L_boats',0.15,function(t){
    var sails=['#ffffff','#ffd166','#ef476f','#f78c6b','#ffffff','#06d6a0'], hulls=['#2f4858','#a23b2a','#1d6fa3'];
    for(var i=0;i<6;i++){
      var x=130+i*(RW-260)/6+rng()*70, d=rng(), y=HZ+10+d*(seaB-HZ-30)*0.7, s=0.45+d*0.75;
      var g=el('g',{transform:'translate('+x.toFixed(1)+' '+y.toFixed(1)+') scale('+s.toFixed(2)+')'},t);
      var b=el('g',{'class':'bob',style:'animation-delay:'+(-rng()*3).toFixed(2)+'s'},g);
      var sc=sails[i%sails.length];
      el('line',{x1:0,y1:-4,x2:0,y2:-52,stroke:'#333','stroke-width':2},b);
      el('path',{d:'M2 -50 L2 -8 L28 -8 Z',fill:sc,stroke:'#555','stroke-width':1},b);
      el('path',{d:'M-2 -44 L-2 -8 L-20 -8 Z',fill:'#f4f4f4',stroke:'#555','stroke-width':1},b);
      el('path',{d:'M0 -52 L10 -49 L0 -46 Z',fill:'#e4572e'},b);
      el('path',{d:'M-29 -5 L29 -5 L21 6 L-21 6 Z',fill:hulls[i%3]},b);
      el('line',{x1:-26,y1:-1,x2:26,y2:-1,stroke:'#fff','stroke-width':1.5,opacity:'.6'},b);
    }
  });

  // sea wall + railing (static parts) and scrolling posts/lamps
  var ws=$('wallStatic'); ws.textContent='';
  el('rect',{x:0,y:G-40,width:W,height:15,fill:'#cdb994'},ws);
  el('line',{x1:0,y1:G-40,x2:W,y2:G-40,stroke:'#e5d6b6','stroke-width':2},ws);
  el('line',{x1:0,y1:G-66,x2:W,y2:G-66,stroke:'#f7fafc','stroke-width':3.5},ws);
  el('line',{x1:0,y1:G-54,x2:W,y2:G-54,stroke:'#e8eef2','stroke-width':2.5},ws);
  makeLayer('L_wall',0.75,function(t){
    var i,d='';
    for(i=0;i<RW;i+=64)d+='M'+i+' '+(G-38)+'v13';
    el('path',{d:d,stroke:'#b39f7a','stroke-width':1.5},t);
    d='';
    for(i=0;i<RW;i+=32)d+='M'+(i+16)+' '+(G-68)+'V'+(G-40);
    el('path',{d:d,stroke:'#f7fafc','stroke-width':4},t);
    for(i=0;i<6;i++){
      var x=i*272+136, T=G-190;
      el('rect',{x:x-6,y:G-46,width:12,height:8,rx:2,fill:'#2f4858'},t);
      el('rect',{x:x-3,y:T,width:6,height:G-44-T,fill:'#2f4858'},t);
      el('path',{d:'M'+x+' '+T+' Q'+x+' '+(T-14)+' '+(x+18)+' '+(T-12),fill:'none',stroke:'#2f4858','stroke-width':4},t);
      el('circle',{cx:x+18,cy:T+2,r:14,fill:'#ffe08a',opacity:'.35','class':'hq'},t);
      el('path',{d:'M'+(x+11)+' '+(T-12)+' L'+(x+25)+' '+(T-12)+' L'+(x+22)+' '+(T-2)+' L'+(x+14)+' '+(T-2)+' Z',fill:'#2f4858'},t);
      el('ellipse',{cx:x+18,cy:T-1,rx:5,ry:3,fill:'#ffe08a'},t);
      el('circle',{cx:x,cy:T-4,r:3,fill:'#2f4858'},t);
    }
  });

  // promenade ground
  var gs=$('groundStatic'); gs.textContent='';
  el('rect',{x:0,y:G-26,width:W,height:H-G+30,fill:'#ead7b2'},gs);
  el('line',{x1:0,y1:G-25,x2:W,y2:G-25,stroke:'#f8ecd4','stroke-width':2},gs);
  var rows=[G-26,G-8,G+14,G+42,G+80,G+130],r=G+130,step=70;
  while(r<H){r+=step;step*=1.3;rows.push(r);}
  var hd='';
  for(var k=1;k<rows.length;k++)hd+='M0 '+rows[k].toFixed(1)+'H'+W;
  el('path',{d:hd,stroke:'#d6bf97','stroke-width':1.5},gs);
  makeLayer('L_ground',1,function(t){
    var d='';
    for(var k=0;k<rows.length-1;k++){
      var y0=rows[k], y1=rows[k+1], off=(k%2)*24;
      for(var x=off;x<RW;x+=48){
        var s0=(y0-G)*0.18, s1=(y1-G)*0.18;
        d+='M'+(x-s0).toFixed(1)+' '+y0.toFixed(1)+'L'+(x-s1).toFixed(1)+' '+y1.toFixed(1);
      }
    }
    el('path',{d:d,stroke:'#d6bf97','stroke-width':1.5},t);
    // painted bike-lane dashes: they move exactly with the road surface
    var ld='';
    for(var x2=0;x2<RW;x2+=48)ld+='M'+x2+' '+(G+26)+'h24';
    el('path',{d:ld,stroke:'#fffaf0','stroke-width':4,'stroke-linecap':'round'},t);
  });
}

/* ---------- Bike parts ---------- */
function buildWheel(g,cx,cy,rear){
  el('circle',{cx:cx,cy:cy,r:43.5,fill:'none',stroke:'#2b2b2b','stroke-width':5},g);
  el('circle',{cx:cx,cy:cy,r:40,fill:'none',stroke:'#b8c4cc','stroke-width':2},g);
  var d='';
  for(var i=0;i<16;i++){
    var a=i/16*Math.PI*2, h=a+(i%2?0.35:-0.35);
    d+='M'+(cx+4.5*Math.cos(h)).toFixed(2)+' '+(cy+4.5*Math.sin(h)).toFixed(2)+'L'+(cx+39*Math.cos(a)).toFixed(2)+' '+(cy+39*Math.sin(a)).toFixed(2);
  }
  el('path',{d:d,stroke:'#98a4ab','stroke-width':1},g);
  el('rect',{x:cx+22,y:cy-2.5,width:9,height:5,rx:1.5,fill:'#ff9f1c'},g);
  el('rect',{x:cx-1.5,y:cy-44,width:3,height:5,fill:'#777'},g);
  el('circle',{cx:cx,cy:cy,r:5,fill:'#5a6068'},g);
  if(rear)el('circle',{cx:cx,cy:cy,r:SR,fill:'#8a9096',stroke:'#444','stroke-width':2,'stroke-dasharray':'1.6 1.2'},g);
  el('circle',{cx:cx,cy:cy,r:2,fill:'#ccc'},g);
}
buildWheel($('wheelR'),RA.x,RA.y,true);
buildWheel($('wheelF'),FA.x,FA.y,false);

// wing shape: shoulder at origin, tip at (91,0)
var WING_B='M-14 -6 C10 -26 48 -22 68 -11 L91 0 L80 3 L84 7 L70 7 L72 12 L58 11 C40 22 6 21 -14 9 Z';
var WING_T='M64 -12 L91 0 L80 3 L84 7 L70 7 L72 12 L58 11 Q55 0 64 -12 Z';
var WING_L='M10 -4 Q30 0 50 -2 M8 4 Q28 8 48 6';
['wingNear','wingFar'].forEach(function(id){
  var g=$(id); g.querySelector('.wb').setAttribute('d',WING_B); g.querySelector('.wt').setAttribute('d',WING_T);
  var l=g.querySelector('.wl'); if(l)l.setAttribute('d',WING_L);
});
var wingNear=$('wingNear'), wingFar=$('wingFar');
var WN={x:-8,y:-160,ang:Math.atan2(-125+160,76+8)*180/Math.PI,sc:Math.hypot(84,35)/91};
var WF={x:-2,y:-165,ang:Math.atan2(-128+165,72+2)*180/Math.PI,sc:Math.hypot(74,37)/91};

function legParts(id){var g=$(id);return{t:g.querySelector('.t'),s:g.querySelector('.s'),f:g.querySelector('.f')};}
var legN=legParts('legNear'), legF=legParts('legFar');
var crankN=$('crankNear'), crankF=$('crankFar'), pedalN=$('pedalNear'), pedalF=$('pedalFar');
var wheelR=$('wheelR'), wheelF=$('wheelF'), ring=$('ring'), chainL=$('chainLinks');
var upper=$('upper'), upper2=$('upper2'), head=$('head'), pouchEl=$('pouch'), clap=$('clap'), bubble=$('bubble'), bikeG=$('bike');

var chainLen=200;
try{chainLen=chainL.getTotalLength();}catch(e){}
var links=Math.max(1,Math.round(chainLen/4.2)), period=chainLen/links;
chainL.setAttribute('stroke-dasharray',(period*0.55).toFixed(3)+' '+(period*0.45).toFixed(3));

function f1(v){return v.toFixed(1);}
function setLeg(p,ankle){
  var dx=ankle.x-HIP.x, dy=ankle.y-HIP.y, d=Math.min(Math.hypot(dx,dy),L1+L2-0.5);
  var a=Math.atan2(dy,dx), al=Math.acos(clamp((L1*L1+d*d-L2*L2)/(2*L1*d),-1,1));
  var kx=HIP.x+L1*Math.cos(a-al), ky=HIP.y+L1*Math.sin(a-al);
  p.t.setAttribute('d','M'+HIP.x+' '+HIP.y+'L'+f1(kx)+' '+f1(ky));
  p.s.setAttribute('d','M'+f1(kx)+' '+f1(ky)+'L'+f1(ankle.x)+' '+f1(ankle.y));
  var x=ankle.x,y=ankle.y;
  // webbed foot with three toes, resting flat on the pedal
  p.f.setAttribute('d','M'+f1(x-2)+' '+f1(y-1)+'L'+f1(x+19)+' '+f1(y+3)+'L'+f1(x+15)+' '+f1(y+4.5)+'L'+f1(x+21)+' '+f1(y+6.5)+'L'+f1(x+14)+' '+f1(y+7)+'L'+f1(x+17)+' '+f1(y+9)+'L'+f1(x+1)+' '+f1(y+7)+'Z');
}

/* ---------- Feathers fx ---------- */
var fxRng=mulberry32(77), feathers=[];
for(var fi=0;fi<6;fi++){
  var fp=el('path',{d:'M-5 0 Q0 -3 5 0 Q0 3 -5 0 Z M-6 0 H6',fill:'#fff',stroke:'#9aa6ae','stroke-width':.8,opacity:0},$('fx'));
  feathers.push({el:fp,life:0,x:0,y:0,vx:0,vy:0,r:0,vr:0});
}
function spawnFeathers(){
  var n=0;
  for(var i=0;i<feathers.length&&n<3;i++){var f=feathers[i];if(f.life<=0){
    f.life=1.6;f.x=-10+fxRng()*30;f.y=-170+fxRng()*20;f.vx=-20-fxRng()*40;f.vy=-40-fxRng()*30;f.r=fxRng()*360;f.vr=(fxRng()-.5)*300;n++;}}
}

/* ---------- Audio ---------- */
var actx=null, master=null, muted=false;
try{muted=localStorage.getItem('pelicanMuted')==='1';}catch(e){}
function ensureAudio(){
  try{
    if(!actx){var AC=window.AudioContext||window.webkitAudioContext;if(!AC)return;actx=new AC();master=actx.createGain();master.gain.value=muted?0:0.7;master.connect(actx.destination);}
    if(actx.state==='suspended')actx.resume();
  }catch(e){}
}
function strike(t0){
  [[1,0.32,1.3],[2.76,0.12,0.7],[5.4,0.06,0.4],[8.9,0.025,0.22]].forEach(function(p){
    var o=actx.createOscillator(), g=actx.createGain();
    o.type='sine';o.frequency.value=1180*p[0];
    g.gain.setValueAtTime(0,t0);g.gain.linearRampToValueAtTime(p[1],t0+0.004);g.gain.exponentialRampToValueAtTime(0.0001,t0+p[2]);
    o.connect(g);g.connect(master);o.start(t0);o.stop(t0+p[2]+0.05);
  });
}
function soundBell(){if(!actx||muted)return;try{var t=actx.currentTime+0.01;strike(t);strike(t+0.17);}catch(e){}}
var noiseBuf=null;
function soundWhoosh(){
  if(!actx||muted)return;
  try{
    if(!noiseBuf){var r=mulberry32(5);noiseBuf=actx.createBuffer(1,Math.floor(actx.sampleRate*0.45),actx.sampleRate);var dd=noiseBuf.getChannelData(0);for(var i=0;i<dd.length;i++)dd[i]=r()*2-1;}
    var s=actx.createBufferSource();s.buffer=noiseBuf;
    var bp=actx.createBiquadFilter();bp.type='bandpass';bp.Q.value=1.2;
    var t=actx.currentTime;bp.frequency.setValueAtTime(500,t);bp.frequency.exponentialRampToValueAtTime(1600,t+0.2);bp.frequency.exponentialRampToValueAtTime(500,t+0.42);
    var g=actx.createGain();g.gain.setValueAtTime(0,t);g.gain.linearRampToValueAtTime(0.35,t+0.08);g.gain.exponentialRampToValueAtTime(0.001,t+0.42);
    s.connect(bp);bp.connect(g);g.connect(master);s.start(t);s.stop(t+0.45);
  }catch(e){}
}
function applyMute(){
  $('bMute').setAttribute('aria-pressed',muted?'true':'false');
  $('bMute').setAttribute('aria-label',muted?'Unmute sound':'Mute sound');
  $('bMute').classList.toggle('on',muted);
  $('muteA').style.display=muted?'none':'';$('muteB').style.display=muted?'':'none';
  $('muteTxt').textContent=muted?'Muted':'Sound';
  if(master)master.gain.value=muted?0:0.7;
}
applyMute();

/* ---------- State & actions ---------- */
var dist=0, speed=0, targetSpeed=0, flapT=-1, bellT=-1, pouch=12, pouchV=0, time=0;
function setSlider(v){v=clamp(v,0,100);spd.value=v;targetSpeed=v/100*MAXS;}
setSlider(Number(spd.value)||45);
var hintGone=false;
function hideHint(){if(!hintGone){hintGone=true;$('hint').classList.add('gone');}}
setTimeout(hideHint,7000);
function flap(){
  if(flapT>=0&&flapT<0.6)return;
  flapT=0;pouchV+=70;spawnFeathers();soundWhoosh();hideHint();
}
function ringBell(){bellT=0;pouchV+=45;soundBell();}
function restart(){
  dist=0;speed=0;setSlider(45);flapT=-1;bellT=-1;pouch=12;pouchV=0;
  feathers.forEach(function(f){f.life=0;f.el.setAttribute('opacity',0);});
}

/* ---------- Layout ---------- */
function layout(){
  var vw=window.innerWidth||800, vh=window.innerHeight||500, asp=vw/vh;
  W=clamp(500*asp,400,1400);H=W/asp;
  var scale=vh/H, hudH=$('hud').offsetHeight||80;
  G=H-hudH/scale-30;
  bikeS=clamp((G-20)/290,0.55,1);
  HZ=Math.max(50,G-170);
  bikeX=W/2+14*bikeS;
  svg.setAttribute('viewBox','0 0 '+W.toFixed(2)+' '+H.toFixed(2));
  bikeG.setAttribute('transform','translate('+f1(bikeX)+' '+f1(G)+') scale('+bikeS.toFixed(3)+')');
  build();
}
var resizePending=false;
window.addEventListener('resize',function(){if(!resizePending){resizePending=true;requestAnimationFrame(function(){resizePending=false;layout();});}});
layout();

/* ---------- Demo mode ---------- */
var demo=(location.hash==='#demo'), ptr=$('ptr'), ripple=$('ripple');
var DEMO_LEN=20, demoT=0, demoIdx=0, ptrPos={x:0,y:0}, segPos=null, segVal=45;
function sceneP(fx,fy){return function(){return{x:window.innerWidth*fx,y:window.innerHeight*fy};};}
function thumbP(){var r=spd.getBoundingClientRect();return{x:r.left+14+(Number(spd.value)/100)*(r.width-28),y:r.top+r.height/2};}
function btnP(id){return function(){var r=$(id).getBoundingClientRect();return{x:r.left+r.width/2,y:r.top+r.height/2};};}
var demoEv=[
  {t:0,pos:sceneP(.5,.38)},
  {t:1.4,pos:thumbP},
  {t:3.6,drag:92},
  {t:4.8,pos:btnP('bBell'),click:ringBell},
  {t:6.3,pos:sceneP(.55,.36),click:flap},
  {t:7.7,pos:sceneP(.38,.3),click:flap},
  {t:9.1,pos:thumbP},
  {t:11.1,drag:15},
  {t:12.6,pos:sceneP(.6,.4),click:flap},
  {t:14.0,pos:btnP('bBell'),click:ringBell},
  {t:15.4,pos:thumbP},
  {t:17.4,drag:55},
  {t:18.7,pos:sceneP(.5,.38),click:flap}
];
function doRipple(p){ripple.style.left=p.x+'px';ripple.style.top=p.y+'px';ripple.classList.remove('go');void ripple.offsetWidth;ripple.classList.add('go');}
function ease(u){return u<.5?2*u*u:1-Math.pow(-2*u+2,2)/2;}
function startDemo(){
  ptr.style.display='block';$('demoTag').style.display='block';hideHint();
  demoT=0;demoIdx=0;ptrPos=demoEv[0].pos();segPos={x:ptrPos.x,y:ptrPos.y};segVal=Number(spd.value);
}
function endDemo(){if(!demo)return;demo=false;ptr.style.display='none';ptr.classList.remove('press');$('demoTag').style.display='none';}
function demoUpdate(dt){
  demoT+=dt;
  if(demoT>=DEMO_LEN){demoT-=DEMO_LEN;demoIdx=0;segPos={x:ptrPos.x,y:ptrPos.y};segVal=Number(spd.value);}
  while(demoIdx<demoEv.length-1&&demoT>=demoEv[demoIdx+1].t){
    demoIdx++;var e=demoEv[demoIdx];
    if(e.click){e.click();doRipple(ptrPos);}
    segPos={x:ptrPos.x,y:ptrPos.y};segVal=Number(spd.value);
  }
  var a=demoEv[demoIdx], b=demoEv[demoIdx+1]||{t:DEMO_LEN,pos:demoEv[0].pos};
  var u=clamp((demoT-a.t)/(b.t-a.t),0,1), e2=ease(u);
  var pressing=false;
  if(b.drag!=null){setSlider(segVal+(b.drag-segVal)*e2);ptrPos=thumbP();pressing=true;}
  else{var p=b.pos();ptrPos={x:segPos.x+(p.x-segPos.x)*e2,y:segPos.y+(p.y-segPos.y)*e2};}
  ptr.classList.toggle('press',pressing);
  ptr.style.transform='translate('+(ptrPos.x-4).toFixed(1)+'px,'+(ptrPos.y-3).toFixed(1)+'px)';
}
if(demo)startDemo();

/* ---------- Input ---------- */
window.addEventListener('pointerdown',function(e){if(e.isTrusted){ensureAudio();endDemo();}},true);
window.addEventListener('keydown',function(e){if(e.isTrusted){ensureAudio();endDemo();}},true);
window.addEventListener('wheel',function(e){if(e.isTrusted)endDemo();},{passive:true,capture:true});
svg.addEventListener('pointerdown',function(e){e.preventDefault();flap();});
spd.addEventListener('input',function(){setSlider(Number(spd.value));});
function btn(id,fn){var b=$(id);b.addEventListener('click',fn);b.addEventListener('pointerup',function(){setTimeout(function(){b.blur();},0);});}
btn('bBell',ringBell);
btn('bFlap',flap);
btn('bMute',function(){muted=!muted;try{localStorage.setItem('pelicanMuted',muted?'1':'0');}catch(e){}applyMute();});
btn('bReset',restart);
window.addEventListener('keydown',function(e){
  var tag=e.target&&e.target.tagName;
  if(tag==='BUTTON'&&(e.key===' '||e.key==='Enter'))return;
  if(tag==='INPUT'&&/^Arrow/.test(e.key))return;
  var k=e.key;
  if(k===' '||k==='f'||k==='F'){e.preventDefault();flap();}
  else if(k==='b'||k==='B'){ringBell();}
  else if(k==='ArrowUp'||k==='ArrowRight'){e.preventDefault();setSlider(Number(spd.value)+5);}
  else if(k==='ArrowDown'||k==='ArrowLeft'){e.preventDefault();setSlider(Number(spd.value)-5);}
  else if(k==='m'||k==='M'){$('bMute').click();}
  else if(k==='r'||k==='R'){restart();}
});

/* ---------- Main loop ---------- */
var last=performance.now(), readySent=false, fpsFrames=0, fpsTime=0, fpsWarm=0, quality=1;
var DEG=180/Math.PI;
function frame(now){
  var rdt=(now-last)/1000;last=now;
  var dt=clamp(rdt,0,0.05);time+=dt;
  if(demo)demoUpdate(dt);

  // quality governor
  fpsWarm+=rdt;
  if(fpsWarm>2&&quality>0){fpsFrames++;fpsTime+=rdt;if(fpsTime>=2){if(fpsFrames/fpsTime<40){quality=0;document.documentElement.classList.add('lowq');}fpsFrames=0;fpsTime=0;}}

  speed+=(targetSpeed-speed)*Math.min(1,dt*2.2);
  if(Math.abs(speed-targetSpeed)<0.05)speed=targetSpeed;
  dist+=speed*dt;
  speedVal.textContent=Math.round(speed/10)+' km/h';

  // Drivetrain: wheel rolls without slip (arc = distance), chain links wheel & cranks
  var wheelA=dist/WR;           // radians
  var crankA=wheelA*SR/CR;      // chainring turns slower than the rear sprocket
  var wd=(mod(wheelA*DEG,360)).toFixed(2);
  wheelR.setAttribute('transform','rotate('+wd+' '+RA.x+' '+RA.y+')');
  wheelF.setAttribute('transform','rotate('+wd+' '+FA.x+' '+FA.y+')');
  ring.setAttribute('transform','rotate('+mod(crankA*DEG,360).toFixed(2)+' '+BB.x+' '+BB.y+')');
  chainL.setAttribute('stroke-dashoffset',mod(crankA*CR,chainLen).toFixed(2));

  var pn={x:BB.x+CL*Math.cos(crankA),y:BB.y+CL*Math.sin(crankA)};
  var pf={x:BB.x-CL*Math.cos(crankA),y:BB.y-CL*Math.sin(crankA)};
  crankN.setAttribute('x1',BB.x);crankN.setAttribute('y1',BB.y);crankN.setAttribute('x2',f1(pn.x));crankN.setAttribute('y2',f1(pn.y));
  crankF.setAttribute('x1',BB.x);crankF.setAttribute('y1',BB.y);crankF.setAttribute('x2',f1(pf.x));crankF.setAttribute('y2',f1(pf.y));
  pedalN.setAttribute('x',f1(pn.x-8));pedalN.setAttribute('y',f1(pn.y-2));
  pedalF.setAttribute('x',f1(pf.x-8));pedalF.setAttribute('y',f1(pf.y-2));
  setLeg(legN,{x:pn.x-6,y:pn.y-7});
  setLeg(legF,{x:pf.x-6,y:pf.y-7});

  // flap
  var wingA=0, lift=0;
  if(flapT>=0){
    flapT+=dt/0.8;
    if(flapT>=1){flapT=-1;}
    else{var s=Math.sin(Math.PI*flapT);wingA=-Math.pow(s,0.8)*72+Math.sin(Math.PI*2*flapT)*6;lift=s*4;}
  }
  var cad=Math.min(1,speed/120);
  wingA+=Math.sin(crankA*2)*0.8*cad;
  upper.setAttribute('transform','translate(0 '+f1(-lift)+')');
  upper2.setAttribute('transform','translate(0 '+f1(-lift)+')');
  wingNear.setAttribute('transform','translate('+WN.x+' '+WN.y+') rotate('+(WN.ang+wingA).toFixed(2)+') scale('+WN.sc.toFixed(3)+')');
  wingFar.setAttribute('transform','translate('+WF.x+' '+WF.y+') rotate('+(WF.ang+wingA*0.92).toFixed(2)+') scale('+WF.sc.toFixed(3)+')');

  // head bob + stretchy pouch (spring)
  var hb=Math.sin(crankA*2)*1.6*cad - lift*0.5;
  head.setAttribute('transform','rotate('+hb.toFixed(2)+' 14 -206)');
  var target=9+speed/MAXS*6;
  var acc=-60*(pouch-target)-3.5*pouchV+30*Math.sin(crankA*2)*cad;
  pouchV+=acc*dt;pouch+=pouchV*dt;
  if(pouch<2){pouch=2;pouchV=Math.abs(pouchV)*0.3;} if(pouch>30){pouch=30;pouchV=-Math.abs(pouchV)*0.3;}
  pouchEl.setAttribute('d','M27 -208 L91 -200 C80 '+f1(-199+pouch)+' 46 '+f1(-196+pouch*1.15)+' 26 -201 Z');

  // bell
  if(bellT>=0){
    bellT+=dt/1.5;
    if(bellT>=1){bellT=-1;bubble.setAttribute('opacity',0);clap.removeAttribute('transform');}
    else{
      clap.setAttribute('transform','rotate('+(Math.sin(bellT*90)*28*(1-bellT)).toFixed(1)+' 63 -141)');
      var op=bellT<0.08?bellT/0.08:bellT>0.75?(1-bellT)/0.25:1;
      bubble.setAttribute('opacity',op.toFixed(2));
      bubble.setAttribute('transform','translate(0 '+f1(-6*bellT)+')');
    }
  }

  // feathers drift back in the wind
  for(var i=0;i<feathers.length;i++){var f=feathers[i];if(f.life>0){
    f.life-=dt;f.vy+=50*dt;f.vy*=0.97;f.x+=(f.vx-speed*0.8)*dt;f.y+=f.vy*dt;f.r+=f.vr*dt;
    f.el.setAttribute('transform','translate('+f1(f.x)+' '+f1(f.y)+') rotate('+f1(f.r)+')');
    f.el.setAttribute('opacity',Math.max(0,Math.min(1,f.life/0.6)).toFixed(2));
    if(f.life<=0)f.el.setAttribute('opacity',0);
  }}

  // parallax layers
  for(var j=0;j<layers.length;j++){var L=layers[j];L.g.setAttribute('transform','translate('+(-mod(dist*L.f,RW)).toFixed(2)+' 0)');}

  if(!readySent){readySent=true;requestAnimationFrame(function(){try{parent.postMessage({vcb:'ready'},'*');}catch(e){}});}
  requestAnimationFrame(frame);
}
requestAnimationFrame(function(t){last=t;frame(t);});
})();
</script>
</body>
</html>

Try 2 · index.html

broken32.0 KB · 626 lines · no libraries
Download
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
<title>Pelican Promenade</title>
<style>
  html,body{margin:0;height:100%;overflow:hidden;background:#20374f;font-family:system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;-webkit-user-select:none;user-select:none;-webkit-tap-highlight-color:transparent}
  #app{position:fixed;inset:0;display:flex;flex-direction:column}
  #stage{flex:1;position:relative;min-height:0;background:#8fd3f4}
  #scene{position:absolute;inset:0;width:100%;height:100%;display:block;touch-action:manipulation;cursor:pointer}
  #title{position:absolute;top:10px;left:12px;padding:6px 12px;border-radius:12px;background:rgba(255,255,255,.75);color:#1c3550;font-weight:800;font-size:17px;pointer-events:none;letter-spacing:.2px}
  #hint{position:absolute;top:10px;right:12px;padding:6px 12px;border-radius:12px;background:rgba(28,53,80,.78);color:#fff;font-weight:600;font-size:14px;pointer-events:none;transition:opacity .8s}
  #hint.gone{opacity:0}
  #bar{display:flex;flex-wrap:wrap;align-items:center;gap:8px;padding:8px 12px calc(8px + env(safe-area-inset-bottom));background:#20374f;color:#fff}
  button{min-width:48px;min-height:48px;padding:0 16px;border:0;border-radius:14px;font-family:inherit;font-size:16px;font-weight:700;background:#eef3f7;color:#1c2b3a;cursor:pointer;box-shadow:0 3px 0 rgba(0,0,0,.3);touch-action:manipulation}
  button:active{transform:translateY(2px);box-shadow:0 1px 0 rgba(0,0,0,.3)}
  #bellBtn{background:#ffd166}
  #flapBtn{background:#9be3c4}
  #resetBtn{background:#f6a6a0}
  .spd{display:flex;align-items:center;gap:10px;flex:1 1 220px;min-width:180px;font-weight:700}
  .spd input{flex:1;height:44px;margin:0;accent-color:#ffb347;cursor:pointer}
  #spdv{min-width:62px;text-align:right;font-variant-numeric:tabular-nums;font-size:14px;opacity:.9}
  @media (max-width:560px){.spd{order:-1;flex-basis:100%}#bar button{flex:1 1 0;padding:0 8px}#title{font-size:15px}#hint{font-size:12px}}
  .spk{opacity:0;animation:tw 3s ease-in-out infinite}
  @keyframes tw{0%,100%{opacity:0}50%{opacity:.95}}
  svg.lowq .spk,svg.lowq .gull{display:none}
  #ptr{position:fixed;left:0;top:0;width:30px;height:30px;pointer-events:none;z-index:20;display:none;will-change:transform}
  #ptr svg{position:absolute;left:0;top:0;filter:drop-shadow(0 2px 2px rgba(0,0,0,.4))}
  #ptr::before{content:"";position:absolute;left:-16px;top:-16px;width:32px;height:32px;border-radius:50%;border:3px solid #fff;opacity:0;transform:scale(.3)}
  #ptr.press::before{animation:pr .5s ease-out}
  #ptr.drag::before{opacity:.8;transform:scale(.7);transition:all .2s}
  @keyframes pr{0%{opacity:1;transform:scale(.3)}100%{opacity:0;transform:scale(1.4)}}
</style>
</head>
<body>
<div id="app">
  <div id="stage">
    <svg id="scene" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMidYMid slice" aria-label="A pelican riding a bicycle along a seaside promenade"></svg>
    <div id="title">Pelican Promenade</div>
    <div id="hint">Tap anywhere to flap!</div>
  </div>
  <div id="bar">
    <label class="spd"><span>Speed</span><input id="speed" type="range" min="0" max="100" value="45" aria-label="Speed"><span id="spdv">0 km/h</span></label>
    <button id="bellBtn" type="button">Bell</button>
    <button id="flapBtn" type="button">Flap</button>
    <button id="muteBtn" type="button" aria-pressed="false">Sound on</button>
    <button id="resetBtn" type="button">Reset</button>
  </div>
</div>
<div id="ptr"><svg width="30" height="30" viewBox="0 0 30 30"><path d="M2,2 L2,24 L8,18 L12,27 L16,25 L12,16 L20,16 Z" fill="#fff" stroke="#1c2b3a" stroke-width="2" stroke-linejoin="round"/></svg></div>
<script>
(function(){
'use strict';
var NS='http://www.w3.org/2000/svg';
var svg=document.getElementById('scene');
function el(tag,attrs,parent){var e=document.createElementNS(NS,tag);if(attrs){for(var k in attrs)e.setAttribute(k,attrs[k]);}if(parent)parent.appendChild(e);return e;}
function mulberry32(a){return function(){a|=0;a=a+0x6D2B79F5|0;var t=Math.imul(a^a>>>15,1|a);t=t+Math.imul(t^t>>>7,61|t)^t;return((t^t>>>14)>>>0)/4294967296;};}
function mod(a,p){return((a%p)+p)%p;}
function f1(n){return n.toFixed(1);}
function lerp(a,b,t){return a+(b-a)*t;}
function easeOut(x){return 1-(1-x)*(1-x);}
function easeInOut(x){return x<.5?2*x*x:1-2*(1-x)*(1-x);}

/* ---------- defs ---------- */
var defs=el('defs',null,svg);
var gs=el('linearGradient',{id:'gSky',x1:0,y1:0,x2:0,y2:1},defs);
el('stop',{offset:0,'stop-color':'#62bdec'},gs);el('stop',{offset:.72,'stop-color':'#bde6f7'},gs);el('stop',{offset:1,'stop-color':'#ffe6c4'},gs);
var gse=el('linearGradient',{id:'gSea',x1:0,y1:0,x2:0,y2:1},defs);
el('stop',{offset:0,'stop-color':'#4aa8d2'},gse);el('stop',{offset:1,'stop-color':'#1d6a97'},gse);
var gsu=el('radialGradient',{id:'gSun'},defs);
el('stop',{offset:0,'stop-color':'#fff6c0','stop-opacity':1},gsu);el('stop',{offset:.4,'stop-color':'#ffdb73','stop-opacity':.9},gsu);el('stop',{offset:1,'stop-color':'#ffdb73','stop-opacity':0},gsu);

var bgRoot=el('g',null,svg);
var bikeG=el('g',null,svg);

/* ---------- world state ---------- */
var MAXV=340;
var W=800,H=520,gy=456,walkTop=414,horizonY=211,bx=340;
var layers=[],gulls=[],lowQ=false,frameN=0;
var dist=0,v=0,targetV=0,t=0,flapT=-1,bellT=-1;
var feathers=[],fxRng=mulberry32(77);

function makeLayer(factor,spacing,seed,builder,drift){
  var period=Math.ceil((W+80)/spacing)*spacing;
  var g=el('g',null,bgRoot),dyn=[];
  for(var c=0;c<2;c++){
    var sub=el('g',{transform:'translate('+(c*period)+',0)'},g);
    builder(sub,mulberry32(seed),period,dyn);
  }
  var L={g:g,period:period,factor:factor,drift:drift||0,dyn:dyn};
  layers.push(L);return L;
}

function buildBg(){
  while(bgRoot.firstChild)bgRoot.removeChild(bgRoot.firstChild);
  layers=[];gulls=[];
  el('rect',{x:0,y:0,width:W,height:horizonY+4,fill:'url(#gSky)'},bgRoot);
  var sx=W*0.8,sy=Math.max(80,horizonY-115);
  el('circle',{cx:sx,cy:sy,r:85,fill:'url(#gSun)'},bgRoot);
  el('circle',{cx:sx,cy:sy,r:30,fill:'#ffe07a'},bgRoot);

  // clouds (slowest)
  makeLayer(0.05,240,11,function(g,rng,period){
    for(var i=0;i<period/240;i++){
      var yMax=Math.max(70,horizonY-95);
      var x=i*240+rng()*140,y=34+rng()*(yMax-34),s=0.55+rng()*0.75;
      var c=el('g',{transform:'translate('+f1(x)+','+f1(y)+') scale('+s.toFixed(2)+')',fill:'#fff',opacity:.94},g);
      el('rect',{x:-14,y:-4,width:96,height:24,rx:12},c);
      el('circle',{cx:8,cy:0,r:18},c);el('circle',{cx:34,cy:-14,r:26},c);el('circle',{cx:60,cy:-4,r:20},c);
    }
  },6);

  // gulls
  for(var i=0;i<3;i++){
    gulls.push({e:el('path',{'class':'gull',fill:'none',stroke:'#34485c','stroke-width':1.8,'stroke-linecap':'round','stroke-linejoin':'round'},bgRoot),
      x0:i*W/3+60,y:Math.max(40,(horizonY-50)*(0.3+0.18*i)),ph:i*1.7,s:1-i*0.2});
  }

  // distant headland with lighthouse
  makeLayer(0.02,800,3,function(g,rng,period){
    var hy=function(x){return Math.max(0,Math.sin(x/period*Math.PI*4)*30+Math.sin(x/period*Math.PI*10)*9);};
    var d='M0,'+(horizonY+1);
    for(var x=0;x<=period;x+=20)d+='L'+x+','+f1(horizonY-hy(x));
    d+='L'+period+','+(horizonY+1)+'Z';
    el('path',{d:d,fill:'#8db4c7'},g);
    var lx=period/8,ly=horizonY-hy(lx)+2;
    var lh=el('g',{transform:'translate('+f1(lx)+','+f1(ly)+')'},g);
    el('path',{d:'M-6,0 L6,0 L4,-36 L-4,-36 Z',fill:'#fbfbfb'},lh);
    el('path',{d:'M-5.4,-10 L5.4,-10 L5,-17 L-5,-17 Z M-4.6,-24 L4.6,-24 L4.3,-30 L-4.3,-30 Z',fill:'#e4572e'},lh);
    el('rect',{x:-4,y:-42,width:8,height:6,fill:'#ffe07a'},lh);
    el('path',{d:'M-5,-42 L0,-47 L5,-42 Z',fill:'#e4572e'},lh);
  },0);

  // sea
  el('rect',{x:0,y:horizonY,width:W,height:walkTop-horizonY+2,fill:'url(#gSea)'},bgRoot);
  el('rect',{x:0,y:horizonY,width:W,height:2,fill:'#e2f5fc',opacity:.7},bgRoot);

  var sd=walkTop-horizonY;
  function waveRow(g,y,amp,op,period){
    var d='M0,'+f1(y);
    for(var x=0;x<period;x+=40)d+='q10,'+(-amp)+' 20,0 q10,'+amp+' 20,0';
    el('path',{d:d,fill:'none',stroke:'#e9f7ff','stroke-width':1.6,opacity:op,'stroke-linecap':'round'},g);
  }
  makeLayer(0.15,80,31,function(g,rng,period){
    waveRow(g,horizonY+sd*0.12,1.2,.3,period);waveRow(g,horizonY+sd*0.3,1.8,.35,period);
  },8);

  // boats
  makeLayer(0.12,420,21,function(g,rng,period,dyn){
    var cols=['#e4572e','#f2c14e','#4b8f8c','#6c5b7b','#ff8c61','#3d5a80'];
    for(var i=0;i<period/420;i++){
      var depth=rng(),x=i*420+40+rng()*260,y=horizonY+14+depth*Math.max(10,sd-95),s=0.4+depth*0.55;
      var outer=el('g',{transform:'translate('+f1(x)+','+f1(y)+') scale('+s.toFixed(2)+')'},g);
      var b=el('g',null,outer);
      var hull=cols[Math.floor(rng()*cols.length)],sail=rng()<0.5?'#ffffff':'#fff1d0';
      el('ellipse',{cx:0,cy:9,rx:46,ry:4,fill:'#fff',opacity:.35},outer);
      el('line',{x1:0,y1:-4,x2:0,y2:-70,stroke:'#5b4a3a','stroke-width':2.5},b);
      el('path',{d:'M3,-68 L3,-10 L38,-12 Z',fill:sail,stroke:'#c9c3b5','stroke-width':1},b);
      el('path',{d:'M-3,-60 L-3,-10 L-28,-10 Z',fill:sail,opacity:.92,stroke:'#c9c3b5','stroke-width':1},b);
      el('path',{d:'M0,-70 L12,-66 L0,-62 Z',fill:hull},b);
      el('path',{d:'M-40,-6 L40,-6 L28,8 L-30,8 Z',fill:hull,stroke:'rgba(0,0,0,.25)','stroke-width':1},b);
      el('rect',{x:-36,y:-3,width:70,height:3,fill:'#fff',opacity:.7},b);
      dyn.push({e:b,ph:rng()*6.28});
    }
  },4);

  // nearer waves + sparkles
  makeLayer(0.4,80,41,function(g,rng,period){
    waveRow(g,horizonY+sd*0.58,2.6,.42,period);waveRow(g,horizonY+sd*0.8,3.6,.5,period);
    for(var i=0;i<period/45;i++){
      var x=rng()*period,y=horizonY+8+rng()*Math.max(10,sd-50),w=3+rng()*7;
      el('line',{x1:f1(x),y1:f1(y),x2:f1(x+w),y2:f1(y),stroke:'#fff','stroke-width':1.6,'stroke-linecap':'round','class':'spk',style:'animation-delay:'+(-rng()*3).toFixed(2)+'s'},g);
    }
  },12);

  // railing posts
  makeLayer(0.8,280,51,function(g,rng,period){
    for(var x=0;x<period;x+=28)el('rect',{x:x-1.5,y:walkTop-37,width:3,height:37,fill:'#f2f6f8'},g);
  },0);
  el('rect',{x:0,y:walkTop-40,width:W,height:4.5,rx:2,fill:'#fbfdfe'},bgRoot);
  el('rect',{x:0,y:walkTop-23,width:W,height:3,fill:'#eef3f6'},bgRoot);

  // walkway base
  el('rect',{x:0,y:walkTop,width:W,height:H-walkTop,fill:'#ecd9b0'},bgRoot);
  el('rect',{x:0,y:walkTop-2,width:W,height:5,fill:'#c4ad80'},bgRoot);

  // lampposts with bunting
  makeLayer(0.8,280,61,function(g,rng,period){
    var cols=['#e4572e','#ffd166','#4ecdc4','#6c5b7b','#ff8c61'];
    for(var i=0;i<period/280;i++){
      var x=i*280+140,top=walkTop-188;
      // bunting
      var ax=x,ay=top+40,cx=x+140,cy=top+80,bx2=x+280,by=top+40;
      el('path',{d:'M'+ax+','+ay+' Q'+cx+','+cy+' '+bx2+','+by,fill:'none',stroke:'#5d6b78','stroke-width':1},g);
      for(var k=1;k<14;k++){
        var tt=k/14,t2=(k+0.55)/14;
        var px=(1-tt)*(1-tt)*ax+2*(1-tt)*tt*cx+tt*tt*bx2,py=(1-tt)*(1-tt)*ay+2*(1-tt)*tt*cy+tt*tt*by;
        var qx=(1-t2)*(1-t2)*ax+2*(1-t2)*t2*cx+t2*t2*bx2,qy=(1-t2)*(1-t2)*ay+2*(1-t2)*t2*cy+t2*t2*by;
        el('path',{d:'M'+f1(px)+','+f1(py)+' L'+f1(qx)+','+f1(qy)+' L'+f1((px+qx)/2)+','+f1((py+qy)/2+11)+' Z',fill:cols[k%cols.length]},g);
      }
      el('rect',{x:x-3,y:top,width:6,height:188+4,fill:'#2f4858'},g);
      el('rect',{x:x-8,y:walkTop-8,width:16,height:11,rx:2,fill:'#2f4858'},g);
      el('path',{d:'M'+x+','+top+' q0,-14 16,-14 q10,0 10,10',fill:'none',stroke:'#2f4858','stroke-width':4,'stroke-linecap':'round'},g);
      var lg=el('g',{transform:'translate('+(x+26)+','+(top-3)+')'},g);
      el('path',{d:'M-7,0 L7,0 L5,13 L-5,13 Z',fill:'#fff1b8',stroke:'#2f4858','stroke-width':2},lg);
      el('path',{d:'M-9,1 L0,-7 L9,1 Z',fill:'#2f4858'},lg);
    }
  },0);

  // paving stones: moves at exactly the bike speed (proves no sliding)
  makeLayer(1,48,71,function(g,rng,period){
    var r1=gy-12,r2=gy+24,d='';
    for(var x=0;x<period;x+=48){
      d+='M'+x+','+(walkTop+3)+' L'+x+','+r1;
      d+='M'+(x+24)+','+r1+' L'+(x+24)+','+r2;
      d+='M'+x+','+r2+' L'+x+','+H;
    }
    d+='M0,'+r1+' L'+period+','+r1+' M0,'+r2+' L'+period+','+r2;
    el('path',{d:d,fill:'none',stroke:'#d0b888','stroke-width':1.6},g);
    for(var i=0;i<period/60;i++){
      el('ellipse',{cx:f1(rng()*period),cy:f1(walkTop+6+rng()*(H-walkTop-10)),rx:f1(1+rng()*2.5),ry:1.2,fill:'#c9b07f'},g);
    }
  },0);

  el('ellipse',{cx:bx-2,cy:gy+1,rx:104,ry:6,fill:'rgba(60,40,10,.2)'},bgRoot);
}

/* ---------- bike + pelican ---------- */
var RH=[-68,-40],FH=[66,-40],BB=[-4,-32],ST=[-22,-100],HT=[46,-104],HB=[52,-84],GRIP=[60,-108];
var R=40,RC=12.5,RS=6,CR=17,L1=47,L2=50;
var OUT='#33384a';
var FOOT='M-3,-6 L11,-3 L14,-1 L10,-0.5 L13,0.5 L-5,0.5 Z';
var DEG=180/Math.PI;

var farWing=el('path',{fill:'#ddd6c8',stroke:OUT,'stroke-width':1.3,'stroke-linejoin':'round'},bikeG);
var farWingTip=el('path',{fill:'#2c2f3a'},bikeG);
var farThigh=el('path',{fill:'none',stroke:'#d9d2c3','stroke-width':10,'stroke-linecap':'round'},bikeG);
var farShin=el('path',{fill:'none',stroke:'#c7712f','stroke-width':4.5,'stroke-linecap':'round'},bikeG);
var farCrank=el('line',{stroke:'#4a4e57','stroke-width':4,'stroke-linecap':'round'},bikeG);
var farPedal=el('rect',{x:-7,y:-1.5,width:14,height:4,rx:1.2,fill:'#3a3d45'},bikeG);
var farFoot=el('path',{d:FOOT,fill:'#c7712f',stroke:'#8d4a1a','stroke-width':1,'stroke-linejoin':'round'},bikeG);

function wheel(sprocket){
  var g=el('g',null,bikeG);
  el('circle',{r:37.5,fill:'none',stroke:'#2a2c33','stroke-width':5},g);
  el('circle',{r:33.5,fill:'none',stroke:'#cfd5dc','stroke-width':2.4},g);
  for(var i=0;i<16;i++){
    var a=i/16*Math.PI*2,b=a+(i%2?0.35:-0.35);
    el('line',{x1:(4*Math.cos(b)).toFixed(2),y1:(4*Math.sin(b)).toFixed(2),x2:(33*Math.cos(a)).toFixed(2),y2:(33*Math.sin(a)).toFixed(2),stroke:'#9ea5b0','stroke-width':.9},g);
  }
  el('rect',{x:-1.5,y:28,width:3,height:5,fill:'#e4572e'},g);
  el('rect',{x:-6,y:-33,width:12,height:3,rx:1,fill:'#ff9f1c'},g);
  if(sprocket){
    el('circle',{r:RS,fill:'#9aa1ab',stroke:'#6d737d','stroke-width':2.2,'stroke-dasharray':'1.5 1.1'},g);
  }
  el('circle',{r:4.2,fill:'#c3c8cf',stroke:'#7a808a','stroke-width':1},g);
  return g;
}
var rearW=wheel(true),frontW=wheel(false);

var frame=el('g',{fill:'none','stroke-linecap':'round','stroke-linejoin':'round'},bikeG);
function tube(a,b,w,c){return el('line',{x1:a[0],y1:a[1],x2:b[0],y2:b[1],stroke:c||'#e4572e','stroke-width':w},frame);}
tube(BB,RH,4);tube(ST,RH,3.6);
tube([-23,-102],[-24,-106],3.5,'#8a9099');
tube(BB,ST,5);tube(ST,HT,5);tube(BB,HB,5.5);
tube(HB,HT,7,'#c4421f');
el('path',{d:'M52,-84 Q61,-60 66,-40',stroke:'#c4421f','stroke-width':4.2},frame);
tube(HT,[43,-117],4,'#8a9099');
el('path',{d:'M43,-117 Q58,-122 60,-110',stroke:'#4a4e57','stroke-width':3.5},frame);
tube([60,-111],[59.4,-103],5,'#24262c');
el('path',{d:'M-38,-106 Q-26,-111 -8,-105 L-10,-102 Q-26,-101 -36,-102 Z',fill:'#4a2f22',stroke:'#2b1a12','stroke-width':1},frame);
// basket with a fish
tube([52,-90],[58,-94],2.5,'#8a9099');
var bk=el('g',null,frame);
el('path',{d:'M70,-104 Q76,-118 71,-122 L77,-125 L76,-117 Q79,-110 75,-102 Z',fill:'#8fb3d6',stroke:'#4f6f8f','stroke-width':1},bk);
el('rect',{x:57,y:-101,width:27,height:17,rx:3,fill:'#cf9150',stroke:'#8a5a2b','stroke-width':1.4},bk);
el('path',{d:'M57,-95 L84,-95 M57,-89 L84,-89 M64,-101 L64,-84 M71,-101 L71,-84 M78,-101 L78,-84',stroke:'#9c6634','stroke-width':1},bk);
el('circle',{cx:BB[0],cy:BB[1],r:4,fill:'#6d737d'},frame);

// chainring + chain
var ringG=el('g',null,bikeG);
el('circle',{r:RC,fill:'none',stroke:'#8f96a1','stroke-width':3,'stroke-dasharray':'2 1.2'},ringG);
el('circle',{r:9,fill:'none',stroke:'#b3b9c2','stroke-width':1.5},ringG);
for(var si=0;si<5;si++){var sa=si/5*Math.PI*2;el('line',{x1:0,y1:0,x2:(9*Math.cos(sa)).toFixed(2),y2:(9*Math.sin(sa)).toFixed(2),stroke:'#b3b9c2','stroke-width':2},ringG);}
function chainD(){
  var x1=BB[0],y1=BB[1],x2=RH[0],y2=RH[1],r1=RC,r2=RS;
  var dx=x2-x1,dy=y2-y1,d=Math.hypot(dx,dy),a=Math.atan2(dy,dx),g=Math.acos((r1-r2)/d);
  var at=a+g,ab=a-g;
  function p(cx,cy,r,ang){return f1(cx+r*Math.cos(ang))+','+f1(cy+r*Math.sin(ang));}
  return 'M'+p(x1,y1,r1,at)+' L'+p(x2,y2,r2,at)+' A'+r2+','+r2+' 0 0 0 '+p(x2,y2,r2,ab)+' L'+p(x1,y1,r1,ab)+' A'+r1+','+r1+' 0 1 0 '+p(x1,y1,r1,at)+' Z';
}
var chain=el('path',{d:chainD(),fill:'none',stroke:'#3d4049','stroke-width':2.2,'stroke-dasharray':'2.4 1.6'},bikeG);
el('circle',{cx:BB[0],cy:BB[1],r:3,fill:'#6d737d'},bikeG);

// rider body
var rider=el('g',null,bikeG);
el('path',{d:'M-44,-135 L-66,-132 L-46,-121 Z',fill:'#fbf8f1',stroke:OUT,'stroke-width':1.4,'stroke-linejoin':'round'},rider);
el('ellipse',{cx:-14,cy:-128,rx:34,ry:21,transform:'rotate(-12 -14 -128)',fill:'#fbf8f1',stroke:OUT,'stroke-width':1.6},rider);
el('ellipse',{cx:9,cy:-138,rx:10,ry:8,fill:'#f6e3b0',opacity:.75},rider);
var NECK='M10,-140 C28,-152 12,-178 28,-194';
el('path',{d:NECK,fill:'none',stroke:OUT,'stroke-width':18,'stroke-linecap':'round'},rider);
el('circle',{cx:30,cy:-201,r:12,fill:'#fbf8f1',stroke:OUT,'stroke-width':1.6},rider);
el('path',{d:NECK,fill:'none',stroke:'#fbf8f1','stroke-width':15,'stroke-linecap':'round'},rider);
el('path',{d:'M22,-210 Q12,-218 6,-211 Q15,-213 20,-205 Z',fill:'#f3d77a',stroke:'#c9a94a','stroke-width':.8},rider);
el('circle',{cx:33,cy:-203,r:4.3,fill:'#f6c9a6'},rider);
var eye=el('ellipse',{cx:33,cy:-203,rx:2.6,ry:2.6,fill:'#1b1b1b'},rider);
el('circle',{cx:34,cy:-204,r:.9,fill:'#fff'},rider);
var pouch=el('path',{fill:'#f5ad86',stroke:'#c46a45','stroke-width':1.2,'stroke-linejoin':'round'},rider);
el('path',{d:'M36,-207 Q70,-198 103,-185 Q111,-182 105,-176 Q103,-180 98,-180 L40,-196 Z',fill:'#f4a83a',stroke:'#b5651d','stroke-width':1.2,'stroke-linejoin':'round'},rider);
el('path',{d:'M42,-203 Q70,-195 98,-184',fill:'none',stroke:'#d68a2a','stroke-width':1},rider);

// near leg
var nearCrank=el('line',{stroke:'#555a63','stroke-width':4.2,'stroke-linecap':'round'},bikeG);
var nearPedal=el('rect',{x:-7,y:-1.5,width:14,height:4,rx:1.2,fill:'#2e3138'},bikeG);
var nearThigh=el('path',{fill:'none',stroke:'#f3efe6','stroke-width':11,'stroke-linecap':'round'},bikeG);
var nearShin=el('path',{fill:'none',stroke:'#f08a3a','stroke-width':5,'stroke-linecap':'round'},bikeG);
var nearFoot=el('path',{d:FOOT,fill:'#f08a3a',stroke:'#a8521c','stroke-width':1,'stroke-linejoin':'round'},bikeG);

// near wing
var nearWing=el('path',{fill:'#f6f2ea',stroke:OUT,'stroke-width':1.4,'stroke-linejoin':'round'},bikeG);
var nearWingTip=el('path',{fill:'#2c2f3a'},bikeG);
var gripWrap=el('circle',{cx:GRIP[0],cy:GRIP[1]-1,r:4.4,fill:'#2c2f3a'},bikeG);

// bell + text
var bellG=el('g',null,bikeG);
el('path',{d:'M-4.5,0 Q-4.5,-8 0,-8 Q4.5,-8 4.5,0 Z',fill:'#f5c242',stroke:'#a07a1a','stroke-width':1},bellG);
el('circle',{cx:0,cy:-9,r:1.4,fill:'#a07a1a'},bellG);
var ringTxt=el('text',{x:82,y:-150,'font-size':15,'font-weight':800,fill:'#1c3550',stroke:'#fff','stroke-width':3.5,'paint-order':'stroke','text-anchor':'middle',opacity:0,'font-family':'system-ui,sans-serif'},bikeG);
ringTxt.textContent='ring ring!';
var featherG=el('g',null,bikeG);

function ik(hip,foot){
  var dx=foot[0]-hip[0],dy=foot[1]-hip[1],d=Math.hypot(dx,dy);
  d=Math.min(d,L1+L2-0.01);d=Math.max(d,Math.abs(L1-L2)+0.01);
  var a=Math.acos(Math.max(-1,Math.min(1,(L1*L1+d*d-L2*L2)/(2*L1*d))));
  var b=Math.atan2(dy,dx);
  return [hip[0]+L1*Math.cos(b-a),hip[1]+L1*Math.sin(b-a)];
}
function pt(p){return f1(p[0])+','+f1(p[1]);}
function wingD(S,ang,L,spread,m){
  var ux=Math.cos(ang),uy=Math.sin(ang),nx=uy,ny=-ux;
  function p(a,c){c*=m;return f1(S[0]+ux*a+nx*c)+','+f1(S[1]+uy*a+ny*c);}
  var k=1+spread*0.7;
  var d='M'+p(-0.15*L,2)+' Q'+p(0.45*L,13+spread*8)+' '+p(L,0);
  var pts=[[.9,-7],[.78,-14],[.62,-17],[.45,-19],[.28,-18],[.1,-15],[-.18,-8]];
  var pa=L,pc=0;
  for(var i=0;i<pts.length;i++){
    var A=pts[i][0]*L,C=pts[i][1]*k;
    d+=' Q'+p((pa+A)/2,Math.min(pc,C)-4)+' '+p(A,C);pa=A;pc=C;
  }
  d+=' Z';
  var tip='M'+p(.66*L,9)+' Q'+p(.86*L,10)+' '+p(L,0)+' Q'+p(.96*L,-6)+' '+p(.9*L,-7*k)+' Q'+p(.84*L,-16*k)+' '+p(.78*L,-14*k)+' Q'+p(.7*L,-4)+' '+p(.66*L,9)+' Z';
  return [d,tip];
}

/* ---------- layout ---------- */
function layout(){
  var r=svg.getBoundingClientRect();
  var cw=Math.max(50,r.width),ch=Math.max(50,r.height);
  var k=Math.max(480/cw,520/ch);
  W=cw*k;H=ch*k;
  svg.setAttribute('viewBox','0 0 '+W.toFixed(1)+' '+H.toFixed(1));
  gy=H-62;walkTop=gy-42;horizonY=gy-245;
  bx=Math.max(118,Math.min(W-132,W*0.44));
  buildBg();
  bikeG.setAttribute('transform','translate('+f1(bx)+','+f1(gy)+')');
}

/* ---------- controls ---------- */
var speedEl=document.getElementById('speed'),spdv=document.getElementById('spdv');
var muteBtn=document.getElementById('muteBtn'),hint=document.getElementById('hint');
function setSpeed(val){
  val=Math.max(0,Math.min(100,val));
  speedEl.value=val;targetV=val/100*MAXV;
  spdv.textContent=Math.round(val*0.3)+' km/h';
}
speedEl.addEventListener('input',function(){setSpeed(+speedEl.value);});

/* ---------- audio ---------- */
var ac=null,master=null,muted=false,noiseBuf=null;
try{muted=localStorage.getItem('pelicanPromenadeMuted')==='1';}catch(e){}
function updMute(){muteBtn.textContent=muted?'Sound off':'Sound on';muteBtn.setAttribute('aria-pressed',muted?'true':'false');}
updMute();
function unlockAudio(){
  if(!ac){
    var C=window.AudioContext||window.webkitAudioContext;if(!C)return;
    try{ac=new C();master=ac.createGain();master.gain.value=muted?0:0.6;master.connect(ac.destination);}catch(e){ac=null;return;}
  }
  if(ac.state==='suspended'){try{ac.resume();}catch(e){}}
}
function strike(t0,f){
  [[1,.32,1.1],[2.71,.14,.5],[5.1,.06,.3]].forEach(function(q){
    var o=ac.createOscillator(),g=ac.createGain();
    o.type='sine';o.frequency.value=f*q[0];
    g.gain.setValueAtTime(0.0001,t0);g.gain.exponentialRampToValueAtTime(q[1],t0+0.006);
    g.gain.exponentialRampToValueAtTime(0.0001,t0+q[2]);
    o.connect(g);g.connect(master);o.start(t0);o.stop(t0+q[2]+0.05);
  });
}
function bellSound(){
  if(!ac||muted)return;
  var t0=ac.currentTime+0.01;strike(t0,2093);strike(t0+0.19,2093);
}
function flapSound(){
  if(!ac||muted)return;
  if(!noiseBuf){
    noiseBuf=ac.createBuffer(1,Math.floor(ac.sampleRate*0.4),ac.sampleRate);
    var dd=noiseBuf.getChannelData(0),nr=mulberry32(5);
    for(var i=0;i<dd.length;i++)dd[i]=nr()*2-1;
  }
  [0,0.3].forEach(function(off,i){
    var s=ac.createBufferSource(),bp=ac.createBiquadFilter(),g=ac.createGain(),t0=ac.currentTime+off;
    s.buffer=noiseBuf;bp.type='bandpass';bp.frequency.setValueAtTime(i?500:800,t0);bp.frequency.linearRampToValueAtTime(i?900:1400,t0+0.25);bp.Q.value=1.2;
    g.gain.setValueAtTime(0.0001,t0);g.gain.linearRampToValueAtTime(0.25,t0+0.08);g.gain.exponentialRampToValueAtTime(0.0001,t0+0.3);
    s.connect(bp);bp.connect(g);g.connect(master);s.start(t0);s.stop(t0+0.35);
  });
}
function toggleMute(){
  muted=!muted;updMute();
  try{localStorage.setItem('pelicanPromenadeMuted',muted?'1':'0');}catch(e){}
  if(ac&&master){master.gain.setTargetAtTime(muted?0:0.6,ac.currentTime,0.02);}
}

/* ---------- actions ---------- */
function flap(){
  if(flapT>=0&&flapT<0.6)return;
  flapT=0;flapSound();
  for(var i=0;i<3;i++){
    var e=el('path',{d:'M0,-6 Q3.2,0 0,6 Q-3.2,0 0,-6 Z',fill:'#fff',stroke:'#9aa0aa','stroke-width':.7},featherG);
    feathers.push({e:e,x:-6+fxRng()*20,y:-136+fxRng()*10,vx:-30-fxRng()*50,vy:-50-fxRng()*40,r:fxRng()*360,vr:-200+fxRng()*400,life:0});
  }
}
function ring(){bellT=0;bellSound();}
function reset(){
  dist=0;v=0;flapT=-1;bellT=-1;setSpeed(45);
  feathers.forEach(function(f){f.e.remove();});feathers=[];
}
var hintTimer=setTimeout(function(){hint.classList.add('gone');},7000);
function hideHint(){hint.classList.add('gone');}

document.getElementById('bellBtn').addEventListener('click',function(){ring();});
document.getElementById('flapBtn').addEventListener('click',function(){flap();hideHint();});
muteBtn.addEventListener('click',toggleMute);
document.getElementById('resetBtn').addEventListener('click',reset);
svg.addEventListener('pointerdown',function(e){e.preventDefault();flap();hideHint();});

window.addEventListener('pointerdown',function(e){if(e.isTrusted){if(demo)stopDemo();unlockAudio();}},true);
window.addEventListener('wheel',function(e){if(demo&&e.isTrusted)stopDemo();},{capture:true,passive:true});
window.addEventListener('keydown',function(e){
  if(!e.isTrusted)return;
  if(demo)stopDemo();
  unlockAudio();
  var k=e.key;
  if(k===' '||k==='f'||k==='F'){if(!e.repeat)flap();e.preventDefault();}
  else if(k==='b'||k==='B'){if(!e.repeat)ring();}
  else if(k==='m'||k==='M'){if(!e.repeat)toggleMute();}
  else if(k==='r'||k==='R'){if(!e.repeat)reset();}
  else if(e.target!==speedEl&&(k==='ArrowUp'||k==='ArrowRight')){setSpeed(+speedEl.value+10);e.preventDefault();}
  else if(e.target!==speedEl&&(k==='ArrowDown'||k==='ArrowLeft')){setSpeed(+speedEl.value-10);e.preventDefault();}
},true);

/* ---------- demo mode ---------- */
var demo=false,dStep=0,dTime=0,dFrom=[0,0],ptrX=0,ptrY=0;
var ptr=document.getElementById('ptr');
function sceneP(fx,fy){return function(){var r=svg.getBoundingClientRect();return[r.left+r.width*fx,r.top+r.height*fy];};}
function btnP(id){return function(){var r=document.getElementById(id).getBoundingClientRect();return[r.left+r.width/2,r.top+r.height/2];};}
function sliderXY(val){var r=speedEl.getBoundingClientRect();return[r.left+11+(r.width-22)*val,r.top+r.height/2];}
function sliderNow(){return sliderXY(+speedEl.value/100);}
var steps=[
  {type:'move',to:sceneP(.62,.35),d:900},
  {type:'click',act:function(){flap();},d:500},
  {type:'wait',d:900},
  {type:'move',to:sliderNow,d:900},
  {type:'drag',val:.95,d:1600},
  {type:'wait',d:1200},
  {type:'move',to:btnP('bellBtn'),d:800},
  {type:'click',act:ring,d:600},
  {type:'move',to:sceneP(.5,.4),d:800},
  {type:'click',act:function(){flap();},d:900},
  {type:'click',act:function(){flap();},d:900},
  {type:'move',to:sliderNow,d:800},
  {type:'drag',val:.15,d:1600},
  {type:'wait',d:1500},
  {type:'move',to:btnP('bellBtn'),d:700},
  {type:'click',act:ring,d:700},
  {type:'move',to:sliderNow,d:700},
  {type:'drag',val:.5,d:1200},
  {type:'move',to:sceneP(.5,.3),d:800},
  {type:'click',act:function(){flap();},d:900},
  {type:'wait',d:1100}
];
function placePtr(){ptr.style.transform='translate('+ptrX.toFixed(1)+'px,'+ptrY.toFixed(1)+'px)';}
function startDemo(){
  demo=true;dStep=0;dTime=0;ptrX=innerWidth/2;ptrY=innerHeight/2;
  ptr.style.display='block';placePtr();setSpeed(45);
}
function stopDemo(){demo=false;ptr.style.display='none';ptr.classList.remove('drag','press');}
function demoUpdate(dt){
  var s=steps[dStep];
  if(dTime===0){
    dFrom=[ptrX,ptrY];
    if(s.type==='move')s._to=s.to();
    if(s.type==='drag'){s._v0=+speedEl.value/100;ptr.classList.add('drag');}
    if(s.type==='click'){ptr.classList.remove('press');void ptr.offsetWidth;ptr.classList.add('press');s.act();}
  }
  dTime+=dt*1000;
  var p=Math.min(1,dTime/s.d),e=easeInOut(p);
  if(s.type==='move'){ptrX=lerp(dFrom[0],s._to[0],e);ptrY=lerp(dFrom[1],s._to[1],e);}
  else if(s.type==='drag'){var val=lerp(s._v0,s.val,e);setSpeed(val*100);var xy=sliderXY(val);ptrX=xy[0];ptrY=xy[1];}
  placePtr();
  if(dTime>=s.d){if(s.type==='drag')ptr.classList.remove('drag');dStep=(dStep+1)%steps.length;dTime=0;}
}

/* ---------- main loop ---------- */
var last=performance.now(),fpsAcc=0,fpsN=0,readySent=false;
function setLowQ(){lowQ=true;svg.classList.add('lowq');}
function frame(now){
  var dt=(now-last)/1000;last=now;
  if(dt>0.1)dt=0.1;if(dt<0)dt=0;
  t+=dt;frameN++;
  if(t>3&&!lowQ){fpsAcc+=dt;fpsN++;if(fpsAcc>=2){if(fpsN/fpsAcc<40)setLowQ();fpsAcc=0;fpsN=0;}}
  if(demo)demoUpdate(dt);

  v+=(targetV-v)*Math.min(1,dt*2.2);
  dist+=v*dt;
  var thW=dist/R;                 // wheel angle: rolling without slipping
  var phi=thW*RS/RC+0.9;          // cranks geared to rear wheel via chain

  // scenery
  for(var i=0;i<layers.length;i++){
    var L=layers[i];
    if(lowQ&&L.factor<0.1&&frameN%3)continue;
    var off=mod(dist*L.factor+t*L.drift,L.period);
    L.g.setAttribute('transform','translate('+(-off).toFixed(2)+',0)');
    for(var j=0;j<L.dyn.length;j++){var b=L.dyn[j];b.e.setAttribute('transform','translate(0,'+f1(Math.sin(t*1.6+b.ph)*1.6)+') rotate('+f1(Math.sin(t*1.25+b.ph)*3)+')');}
  }
  if(!lowQ){
    for(var gi=0;gi<gulls.length;gi++){
      var gl=gulls[gi],gx=mod(gl.x0-dist*0.1+t*22,W+80)-40,w=Math.sin(t*6+gl.ph)*5*gl.s,gyy=gl.y+Math.sin(t*0.8+gl.ph)*6;
      gl.e.setAttribute('d','M'+f1(gx-10*gl.s)+','+f1(gyy-w)+' Q'+f1(gx-5*gl.s)+','+f1(gyy-2)+' '+f1(gx)+','+f1(gyy)+' Q'+f1(gx+5*gl.s)+','+f1(gyy-2)+' '+f1(gx+10*gl.s)+','+f1(gyy-w));
    }
  }

  // flap
  var lift=0;
  if(flapT>=0){
    flapT+=dt/0.85;
    if(flapT>=1)flapT=-1;
    else lift=flapT<0.38?easeOut(flapT/0.38):1-easeInOut((flapT-0.38)/0.62);
  }
  var ry=-lift*2.5+Math.sin(phi*2)*0.8;

  // wheels, chainring, chain
  rearW.setAttribute('transform','translate('+RH[0]+','+RH[1]+') rotate('+(mod(thW*DEG,360)).toFixed(2)+')');
  frontW.setAttribute('transform','translate('+FH[0]+','+FH[1]+') rotate('+(mod(thW*DEG,360)).toFixed(2)+')');
  ringG.setAttribute('transform','translate('+BB[0]+','+BB[1]+') rotate('+(mod(phi*DEG,360)).toFixed(2)+')');
  chain.setAttribute('stroke-dashoffset',mod(thW*RS,4).toFixed(2));

  // cranks + pedals
  var c=Math.cos(phi),s=Math.sin(phi);
  var pn=[BB[0]+CR*c,BB[1]+CR*s],pf=[BB[0]-CR*c,BB[1]-CR*s];
  nearCrank.setAttribute('x1',BB[0]);nearCrank.setAttribute('y1',BB[1]);nearCrank.setAttribute('x2',f1(pn[0]));nearCrank.setAttribute('y2',f1(pn[1]));
  farCrank.setAttribute('x1',BB[0]);farCrank.setAttribute('y1',BB[1]);farCrank.setAttribute('x2',f1(pf[0]));farCrank.setAttribute('y2',f1(pf[1]));
  nearPedal.setAttribute('transform','translate('+pt(pn)+')');
  farPedal.setAttribute('transform','translate('+pt(pf)+')');
  nearFoot.setAttribute('transform','translate('+f1(pn[0])+','+f1(pn[1]-2)+')');
  farFoot.setAttribute('transform','translate('+f1(pf[0])+','+f1(pf[1]-2)+')');

  // legs (IK from hip to ankle on pedal)
  var hn=[-12,-108+ry],an=[pn[0]-3,pn[1]-8],kn=ik(hn,an);
  nearThigh.setAttribute('d','M'+pt(hn)+' L'+pt(kn));nearShin.setAttribute('d','M'+pt(kn)+' L'+pt(an));
  var hf=[-16,-108+ry],af=[pf[0]-3,pf[1]-8],kf=ik(hf,af);
  farThigh.setAttribute('d','M'+pt(hf)+' L'+pt(kf));farShin.setAttribute('d','M'+pt(kf)+' L'+pt(af));

  // rider
  rider.setAttribute('transform','translate(0,'+ry.toFixed(2)+')');
  eye.setAttribute('ry',(t%3.9)<0.13?0.4:2.6);
  var bellWob=bellT>=0?Math.sin(bellT*40)*3*(1-bellT):0;
  var sag=Math.sin(t*7.5)*(1+v/120)+Math.sin(t*23)*lift*4+bellWob;
  pouch.setAttribute('d','M40,-197 L99,-180 Q72,'+f1(-156+sag)+' 33,-190 Z');

  // wings: tips on the grips, lifted during a flap
  var m=Math.cos(lift*Math.PI);if(Math.abs(m)<0.22)m=m<0?-0.22:0.22;
  var Sn=[2,-138+ry],aF=Math.atan2(GRIP[1]-Sn[1],GRIP[0]-Sn[0]),lF=Math.hypot(GRIP[0]-Sn[0],GRIP[1]-Sn[1]);
  var wn=wingD(Sn,lerp(aF,-1.78,lift),lerp(lF,88,lift),lift,m);
  nearWing.setAttribute('d',wn[0]);nearWingTip.setAttribute('d',wn[1]);
  var Sf=[-4,-145+ry],G2=[GRIP[0]-4,GRIP[1]-3],aF2=Math.atan2(G2[1]-Sf[1],G2[0]-Sf[0]),lF2=Math.hypot(G2[0]-Sf[0],G2[1]-Sf[1]);
  var wf=wingD(Sf,lerp(aF2,-2.0,lift),lerp(lF2,84,lift),lift,m);
  farWing.setAttribute('d',wf[0]);farWingTip.setAttribute('d',wf[1]);
  gripWrap.setAttribute('opacity',Math.max(0,1-lift*4).toFixed(2));

  // bell
  if(bellT>=0){bellT+=dt/1.3;if(bellT>=1)bellT=-1;}
  var rot=bellT>=0?Math.sin(bellT*60)*22*(1-bellT):0;
  bellG.setAttribute('transform','translate(51,-119) rotate('+f1(rot)+')');
  ringTxt.setAttribute('opacity',bellT>=0?Math.min(1,(1-bellT)*3).toFixed(2):'0');
  ringTxt.setAttribute('y',bellT>=0?f1(-150-bellT*14):'-150');

  // feathers drift in the air (world-space, so they fall behind the bike)
  for(var fi=feathers.length-1;fi>=0;fi--){
    var F=feathers[fi];F.life+=dt;
    if(F.y<-3){F.vy+=55*dt;F.vy=Math.min(F.vy,40);F.x+=(F.vx-v)*dt;F.y+=F.vy*dt;F.r+=F.vr*dt;F.vx*=0.98;}
    else{F.x-=v*dt;}
    F.e.setAttribute('transform','translate('+f1(F.x)+','+f1(F.y)+') rotate('+f1(F.r)+')');
    if(F.life>3.5||F.x<-bx-40){F.e.remove();feathers.splice(fi,1);}
  }

  if(!readySent){
    readySent=true;
    requestAnimationFrame(function(){try{parent.postMessage({vcb:'ready'},'*');}catch(e){}});
  }
  requestAnimationFrame(frame);
}

layout();
setSpeed(45);
var rsT=null;
window.addEventListener('resize',function(){clearTimeout(rsT);rsT=setTimeout(layout,60);});
window.addEventListener('orientationchange',function(){setTimeout(layout,200);});
if(/#demo$/.test(location.href))startDemo();
requestAnimationFrame(function(n){last=n;frame(n);});
})();
</script>
</body>
</html>