index.html · HTML + CSS + Canvas JS406 lines
<!doctype html>
<html lang="fa" dir="rtl">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>ژست | کتوشلوار — دمو پیستاکد</title>
<!-- Design & code © 1405 pistacode.ir — all rights reserved. -->
<style>
@font-face{font-family:Vz;src:url("vazirmatn.woff2") format("woff2");font-weight:100 900}
:root{--bg:#120d0a;--ink:#f4ead9;--mute:#a8998a;--gold:#e0b46a;--pista:#a6e24d;--pista2:#5fbf4a;--card:#1d1612;--line:#33281f}
*{box-sizing:border-box;margin:0;padding:0}
html,body{height:100%;background:#000;overflow:hidden}
body{font-family:Vz,sans-serif;color:var(--ink);-webkit-tap-highlight-color:transparent}
#fit{position:absolute;left:50%;top:50%;width:1080px;height:1920px;transform-origin:0 0}
#app{position:absolute;inset:0;background:var(--bg);overflow:hidden}
.bar{position:absolute;top:0;left:0;right:0;height:84px;background:#0a0706;display:flex;align-items:center;justify-content:center;direction:ltr}
.url{width:760px;height:52px;border-radius:26px;background:#1c1512;color:#cdbfae;font-size:25px;display:flex;align-items:center;justify-content:center;gap:12px;letter-spacing:.3px}
.url i{width:14px;height:14px;border-radius:50%;background:var(--pista);display:block}
header{position:absolute;top:84px;left:0;right:0;height:112px;display:flex;align-items:center;justify-content:space-between;padding:0 48px;border-bottom:1px solid var(--line)}
.logo{font-weight:900;font-size:58px;letter-spacing:-1px;display:flex;align-items:baseline;gap:14px}
.logo small{font-weight:500;font-size:22px;color:var(--gold);letter-spacing:6px;direction:ltr}
.nav{display:flex;gap:34px;align-items:center;color:var(--mute);font-size:27px;font-weight:500}
.nav b{color:var(--ink);font-weight:700}
.ico{width:58px;height:58px;border-radius:50%;border:1.5px solid var(--line);display:grid;place-items:center;position:relative}
.ico svg{width:28px;height:28px;stroke:var(--ink);fill:none;stroke-width:2}
.ico em{position:absolute;top:-6px;left:-6px;background:var(--gold);color:#1a120a;font-style:normal;font-size:19px;font-weight:800;width:28px;height:28px;border-radius:50%;display:grid;place-items:center}
#stage{position:absolute;top:196px;left:0;width:1080px;height:1100px;display:block}
.tag{position:absolute;top:226px;right:48px;background:rgba(18,13,10,.72);border:1px solid rgba(224,180,106,.5);color:var(--gold);font-size:25px;font-weight:600;padding:10px 24px;border-radius:40px}
.copy{position:absolute;top:1330px;left:0;right:0;text-align:center;padding:0 60px}
.copy h1{font-size:74px;font-weight:900;line-height:1.25;letter-spacing:-1.5px}
.copy h1 span{color:var(--gold)}
.copy p{margin-top:12px;font-size:31px;color:var(--mute);font-weight:400}
#cta{position:absolute;top:1566px;left:50%;width:560px;height:118px;margin-left:-280px;border:0;border-radius:60px;font-family:inherit;font-size:40px;font-weight:800;color:#1a120a;background:linear-gradient(180deg,#f0c97f,#d9a650);box-shadow:0 14px 40px rgba(224,180,106,.28),inset 0 2px 0 rgba(255,255,255,.45);cursor:pointer;display:flex;align-items:center;justify-content:center;gap:18px;will-change:transform}
#cta svg{width:42px;height:42px;fill:none;stroke:#1a120a;stroke-width:2.6;stroke-linecap:round;stroke-linejoin:round}
#ring{position:absolute;top:1566px;left:50%;width:560px;height:118px;margin-left:-280px;border-radius:60px;border:4px solid var(--gold);opacity:0;pointer-events:none}
.cards{position:absolute;top:1736px;left:36px;right:36px;display:flex;gap:22px}
.card{flex:1;height:230px;background:var(--card);border:1px solid var(--line);border-radius:28px;padding:22px 24px;display:flex;flex-direction:column;gap:8px}
.card i{display:block;width:54px;height:54px;border-radius:16px}
.card b{font-size:28px;font-weight:700;margin-top:6px}
.card s{text-decoration:none;font-size:25px;color:var(--gold);font-weight:600}
#cursor{position:absolute;left:0;top:0;width:64px;height:64px;pointer-events:none;display:none;z-index:9;filter:drop-shadow(0 4px 8px rgba(0,0,0,.6))}
#rip{position:absolute;left:0;top:0;width:120px;height:120px;margin:-60px 0 0 -60px;border-radius:50%;border:5px solid #fff;opacity:0;pointer-events:none;z-index:8}
#end{position:absolute;inset:0;background:linear-gradient(180deg,rgba(8,12,7,0) 0,rgba(8,12,7,.93) 34%,#080c07 100%);display:flex;flex-direction:column;align-items:center;justify-content:flex-end;padding-bottom:230px;opacity:0;pointer-events:none;z-index:10}
#end .mk{width:150px;height:150px;border-radius:38px;background:linear-gradient(145deg,var(--pista),var(--pista2));display:grid;place-items:center;font:900 100px/1 Vz;color:#0c1408;direction:ltr;box-shadow:0 20px 60px rgba(168,224,95,.3)}
#end h2{margin-top:44px;font-size:68px;font-weight:900;letter-spacing:-1px;text-align:center;line-height:1.35}
#end h2 span{color:var(--pista)}
#end p{margin-top:20px;font-size:36px;color:#c9d6bd}
#end .u{margin-top:46px;direction:ltr;font-size:44px;font-weight:800;color:#0c1408;background:var(--pista);padding:18px 54px;border-radius:60px;text-decoration:none}
#again{margin-top:26px;background:none;border:2px solid rgba(238,234,219,.35);color:#eeeadb;font:600 32px Vz;padding:14px 44px;border-radius:60px;cursor:pointer;display:none}
#wm{position:absolute;left:44px;top:1236px;direction:ltr;font-size:23px;font-weight:700;color:rgba(244,234,217,.55);z-index:3}
#wm b{color:var(--pista)}
#gate{position:absolute;inset:0;z-index:20;background:rgba(8,6,5,.78);backdrop-filter:blur(10px);-webkit-backdrop-filter:blur(10px);display:none;flex-direction:column;align-items:center;justify-content:center;gap:34px;text-align:center}
#gate h3{font-size:64px;font-weight:900;letter-spacing:-1px}
#gate p{font-size:32px;color:var(--mute)}
#enter{margin-top:20px;border:0;border-radius:70px;padding:30px 80px;font:800 44px Vz;color:#1a120a;background:linear-gradient(180deg,#f0c97f,#d9a650);cursor:pointer;display:flex;gap:18px;align-items:center;box-shadow:0 14px 50px rgba(224,180,106,.35)}
#enter svg{width:46px;height:46px;fill:none;stroke:#1a120a;stroke-width:2.4;stroke-linecap:round;stroke-linejoin:round}
</style>
</head>
<body>
<div id="fit"><div id="app">
<div class="bar"><div class="url"><i></i>pistacode.ir/demo/suit-shop</div></div>
<header>
<div class="logo">ژست <small>ZHEST</small></div>
<div class="nav"><b>کتوشلوار</b><span>پیراهن</span><span>کراوات</span>
<div class="ico"><svg viewBox="0 0 24 24"><path d="M6 8h12l-1 12H7L6 8zM9 8V6a3 3 0 016 0v2"/></svg><em>۲</em></div></div>
</header>
<canvas id="stage" width="1080" height="1100"></canvas>
<div class="tag">کالکشن پاییز ۱۴۰۵</div>
<div id="wm">design & code: <b>pistacode</b></div>
<div class="copy"><h1>کتوشلواری که <span>خودش میرقصه</span></h1><p>دوخت سفارشی · پارچهی ایتالیایی · ارسال به سراسر ایران</p></div>
<div id="ring"></div>
<button id="cta"><span>مشاهدهی کالکشن</span></button>
<div class="cards">
<div class="card"><i style="background:#2b3550"></i><b>سرمهای کلاسیک</b><s>۸٬۹۰۰٬۰۰۰ تومان</s></div>
<div class="card"><i style="background:#5a2230"></i><b>زرشکی مجلسی</b><s>۹٬۶۰۰٬۰۰۰ تومان</s></div>
<div class="card"><i style="background:#3d4a34"></i><b>زیتونی اسپرت</b><s>۷٬۸۰۰٬۰۰۰ تومان</s></div>
</div>
<svg id="cursor" viewBox="0 0 32 32"><path d="M6 3l19 11-8.5 2.2L21 25l-4 2-4.4-8.6L6 24z" fill="#fff" stroke="#111" stroke-width="1.6" stroke-linejoin="round"/></svg>
<div id="rip"></div>
<div id="end"><div class="mk">P_</div><h2>سایت فروشگاهیت رو<br><span>زنده</span> میسازیم</h2><p>طراحی سایت · اپلیکیشن · ربات تلگرام</p><a class="u" href="https://pistacode.ir/" target="_top">pistacode.ir</a><button id="again">دوباره ببین</button></div>
<div id="gate"><h3>به فروشگاه «ژست» خوش اومدی</h3><p>این دمو صدا داره؛ صدای دستگاهت رو باز کن</p>
<button id="enter"><svg viewBox="0 0 24 24"><path d="M4 9v6h4l5 4V5L8 9H4zM16.5 8.5a5 5 0 010 7M19 6a8.5 8.5 0 010 12"/></svg>ورود با صدا</button></div>
</div></div>
<script>const ENV=[ /* … منحنی بلندی صدای آهنگ، ۲۸۰۰ نمونه … */ ];</script>
<script>
"use strict";
/* ---------- timeline (v = show time, src = song time) ---------- */
const P=0.433, D=2.75, CLICK=14.3, END=30.84;
const KN=[10.60,10.84,11.08,11.29,11.47,11.65], KNOCKS=KN.concat(KN.map(k=>k+1.85));
const ANCH=[0.03,5.03,7.71,13.09,24.88];
function src(v){ if(v<11.95) return v; if(v<12.35) return -1; if(v<13.8) return v-1.85; if(v<11.95+D) return -1; return v-D; }
function envAt(s){ if(s<0) return 0; const i=Math.max(0,Math.min(ENV.length-1,Math.round(s*100))); return ENV[i]; }
function energy(v){ const s=src(v); if(s<0||(s>10.2&&s<13.0)) return 0; let a=0,n=0; for(let k=-8;k<=14;k++){a+=envAt(s+k/100);n++} return Math.min(1,Math.pow(a/n,0.6)*1.35); }
function accent(v){ const s=src(v); if(s<0||(s>10.2&&s<13.0)) return 0; return envAt(s); }
function beat(v){ const s=src(v)<0?(v<13?10.3:11.95):src(v); let a=ANCH[0],base=0; for(let i=0;i<ANCH.length;i++){ if(s>=ANCH[i]){a=ANCH[i];base=i*64;} } return base+(s-a)/P; }
/* ---------- helpers ---------- */
const cv=document.getElementById('stage'); let g=cv.getContext('2d');
const back=document.createElement('canvas'); back.width=1080; back.height=1100; const bg2=back.getContext('2d');
const TAU=Math.PI*2, sin=Math.sin, cos=Math.cos;
const clamp=(x,a=0,b=1)=>Math.max(a,Math.min(b,x)), lerp=(a,b,t)=>a+(b-a)*t;
const ss=(a,b,x)=>{const t=clamp((x-a)/(b-a));return t*t*(3-2*t)};
const eo=t=>1-Math.pow(1-clamp(t),3);
function hash(n){ n=Math.sin(n*127.1+311.7)*43758.5453; return n-Math.floor(n); }
const SH={}; function shade(hex,k){ const key=hex+k; if(SH[key]) return SH[key]; const n=parseInt(hex.slice(1),16); let r=n>>16,gg=n>>8&255,b=n&255; const f=c=>Math.round(clamp(k>0?c+(255-c)*k:c*(1+k),0,255)); return SH[key]=`rgb(${f(r)},${f(gg)},${f(b)})`; }
function knockPulse(v){ let p=0; for(const k of KNOCKS){ if(v>=k) p+=Math.exp(-(v-k)/0.085); } return Math.min(1.3,p); }
let QUALITY=2; // 2 = bloom + reflections + depth blur, 1 = reflections, 0 = plain
/* ---------- room ---------- */
const FLOOR=745, DOOR={x:448,y:262,w:184,h:483};
function room(v,E,A,open){
let w=g.createLinearGradient(0,0,0,FLOOR); w.addColorStop(0,'#170d09'); w.addColorStop(.5,'#3b2116'); w.addColorStop(1,'#27140d');
g.fillStyle=w; g.fillRect(-60,-60,1200,FLOOR+60);
// wallpaper stripes + wainscot
for(let i=0;i<46;i++){ g.fillStyle=i%2?'rgba(255,214,150,.022)':'rgba(0,0,0,.05)'; g.fillRect(i*24-12,0,24,560); }
g.fillStyle='#2a160e'; g.fillRect(-60,560,1200,185);
g.fillStyle='rgba(224,180,106,.22)'; g.fillRect(-60,556,1200,5);
g.strokeStyle='rgba(224,180,106,.09)'; g.lineWidth=3;
for(let i=0;i<7;i++){ const x=-20+i*166; if(x>300&&x<640) continue; g.strokeRect(x+16,586,134,120); }
g.fillStyle='#160b07'; g.fillRect(-60,722,1200,23);
// sconces
for(const x of [250,830]){ const f=.75+.25*sin(v*7+x)+.4*A, sg=g.createRadialGradient(x,330,4,x,330,230); sg.addColorStop(0,`rgba(255,200,120,${.5*f})`); sg.addColorStop(1,'rgba(255,200,120,0)'); g.fillStyle=sg; g.fillRect(x-230,100,460,460);
g.fillStyle='#caa055'; g.fillRect(x-4,330,8,46); g.beginPath(); g.ellipse(x,378,20,6,0,0,TAU); g.fill();
g.fillStyle='#fff1cf'; g.beginPath(); g.moveTo(x-17,330); g.lineTo(x+17,330); g.lineTo(x+11,296); g.lineTo(x-11,296); g.closePath(); g.fill(); }
// chandelier
const cg=g.createRadialGradient(540,60,10,540,60,640); cg.addColorStop(0,`rgba(255,196,110,${.36+.32*A})`); cg.addColorStop(1,'rgba(255,196,110,0)');
g.fillStyle=cg; g.fillRect(-60,-60,1200,FLOOR+60);
g.strokeStyle='#b88f48'; g.lineWidth=4; g.beginPath(); g.moveTo(540,-60); g.lineTo(540,58); g.stroke();
for(let i=-3;i<=3;i++){ if(!i) continue; const x=540+i*38, y=70+Math.abs(i)*9; g.beginPath(); g.moveTo(540,58); g.quadraticCurveTo(540+i*22,96,x,y); g.stroke();
g.fillStyle=`rgba(255,236,190,${.8+.2*hash(i+Math.floor(v*9))})`; g.beginPath(); g.arc(x,y-8,7,0,TAU); g.fill();
g.fillStyle='rgba(255,255,255,.55)'; g.beginPath(); g.moveTo(x,y+4); g.lineTo(x+4,y+14); g.lineTo(x,y+26); g.lineTo(x-4,y+14); g.fill(); }
// door
const kp=knockPulse(v), jx=open>0?0:sin(v*90)*3.2*kp, d=DOOR;
g.fillStyle='rgba(0,0,0,.35)'; g.fillRect(d.x-34,d.y-34,d.w+68,d.h+34);
g.fillStyle='#d9c7a3'; g.fillRect(d.x-22,d.y-24,d.w+44,d.h+24);
g.fillStyle='#efe1c0'; g.fillRect(d.x-22,d.y-24,d.w+44,7); g.fillStyle='#b9a47c'; g.fillRect(d.x-8,d.y-8,d.w+16,8);
const ig=g.createLinearGradient(0,d.y,0,d.y+d.h); ig.addColorStop(0,'#fff0c6'); ig.addColorStop(1,'#f2b862');
g.fillStyle=open>0?ig:'#120a07'; g.fillRect(d.x,d.y,d.w,d.h);
return ()=>{ const wv=d.w*cos(open*1.38);
g.save(); g.translate(d.x+jx,d.y);
const lg=g.createLinearGradient(0,0,wv,0); lg.addColorStop(0,'#d2bd93'); lg.addColorStop(.5,open>0?'#b39d73':'#cbb589'); lg.addColorStop(1,open>0?'#8f7a55':'#bfa97d');
g.fillStyle=lg; g.fillRect(0,0,wv,d.h);
if(wv>30){ const m=wv*0.14; for(const y of [34,258]){ g.fillStyle='rgba(60,40,18,.16)'; g.fillRect(m,y,wv-2*m,190); g.strokeStyle='rgba(255,246,220,.5)'; g.lineWidth=2; g.strokeRect(m+3,y+3,wv-2*m,190); g.strokeStyle='rgba(80,56,28,.6)'; g.lineWidth=3; g.strokeRect(m,y,wv-2*m,190); } }
g.fillStyle='#8a6a2e'; g.beginPath(); g.arc(wv*.9,250,8,0,TAU); g.fill(); g.fillStyle='#e7c77d'; g.beginPath(); g.arc(wv*.9-2,248,3,0,TAU); g.fill();
if(open>0){ g.fillStyle='#7d6a48'; g.fillRect(wv,0,7*sin(open*1.38),d.h); }
g.restore();
if(kp>0.05&&open<=0){ g.strokeStyle=`rgba(255,230,170,${.5*kp})`; g.lineWidth=5; g.strokeRect(d.x-6-kp*10,d.y-6-kp*10,d.w+12+kp*20,d.h+12+kp*20); }
};
}
function floor(v,E,A,open){
const f=g.createLinearGradient(0,FLOOR,0,1100); f.addColorStop(0,'#2a170e'); f.addColorStop(.35,'#1c0f09'); f.addColorStop(1,'#0c0705');
g.fillStyle=f; g.fillRect(-60,FLOOR,1200,420);
g.lineWidth=2;
for(let i=-14;i<=14;i++){ g.strokeStyle=`rgba(255,200,120,${i%2?.05:.03})`; g.beginPath(); g.moveTo(540+i*42,FLOOR); g.lineTo(540+i*150,1160); g.stroke(); }
for(let r=0;r<7;r++){ const y=FLOOR+12+r*r*8.5; g.strokeStyle='rgba(0,0,0,.22)'; for(let i=-14;i<=14;i++){ if((i+r)%3) continue; const k=(y-FLOOR)/355; const x=540+i*lerp(42,150,k)+lerp(21,75,k); g.beginPath(); g.moveTo(x-lerp(20,70,k),y); g.lineTo(x+lerp(20,70,k),y); g.stroke(); } }
// glossy reflection of the lit wall + door
const gl=g.createLinearGradient(0,FLOOR,0,FLOOR+170); gl.addColorStop(0,`rgba(255,190,110,${.13+.12*A})`); gl.addColorStop(1,'rgba(255,190,110,0)'); g.fillStyle=gl; g.fillRect(-60,FLOOR,1200,170);
const d=DOOR, dg=g.createLinearGradient(0,FLOOR,0,FLOOR+260); dg.addColorStop(0,open>0?`rgba(255,226,160,${.5*open})`:'rgba(217,199,163,.16)'); dg.addColorStop(1,'rgba(255,226,160,0)');
g.fillStyle=dg; g.beginPath(); g.moveTo(d.x,FLOOR); g.lineTo(d.x+d.w,FLOOR); g.lineTo(d.x+d.w+26,FLOOR+260); g.lineTo(d.x-26,FLOOR+260); g.fill();
if(open>0){ const lg=g.createLinearGradient(0,FLOOR,0,1100); lg.addColorStop(0,`rgba(255,210,130,${.42*open})`); lg.addColorStop(1,'rgba(255,210,130,0)');
g.fillStyle=lg; g.beginPath(); g.moveTo(d.x,FLOOR); g.lineTo(d.x+d.w,FLOOR); g.lineTo(d.x+d.w+250,1160); g.lineTo(d.x-250,1160); g.fill(); }
}
function tinsel(v){
for(const side of [0,1]){ for(let i=0;i<26;i++){ const x=(side?1080-8:8)+(side?-1:1)*i*7.5, len=560+hash(i+side*50)*190, sw=sin(v*1.3+i*.5)*5;
g.strokeStyle=`rgba(190,200,210,${.20+.25*hash(i*3+side)})`; g.lineWidth=3; g.beginPath(); g.moveTo(x,-40); g.quadraticCurveTo(x+sw,len/2,x+sw*1.6,len); g.stroke();
for(let k=0;k<5;k++){ const h=hash(i*13+k*7+side*99+Math.floor(v*10+hash(i+k)*10)); if(h>.72){ const y=hash(i*5+k+Math.floor(v*10))*len; g.fillStyle=`rgba(255,255,255,${h})`; g.fillRect(x+sw*y/len-2,y,5,12); } }
}}
}
function atmosphere(v,E,A){
g.save(); g.globalCompositeOperation='lighter';
for(let i=-1;i<=1;i++){ const a=i*.42+sin(v*.6+i)*.06, lg=g.createLinearGradient(540,40,540+sin(a)*900,40+cos(a)*900); lg.addColorStop(0,`rgba(255,205,130,${.045+.06*A})`); lg.addColorStop(1,'rgba(255,205,130,0)');
g.fillStyle=lg; g.beginPath(); g.moveTo(540,40); g.lineTo(540+sin(a-.2)*1000,40+cos(a-.2)*1000); g.lineTo(540+sin(a+.2)*1000,40+cos(a+.2)*1000); g.fill(); }
for(let i=0;i<46;i++){ const x=(hash(i)*1080+sin(v*.3+i)*30+v*6*(hash(i+7)-.5))%1080, y=(hash(i+3)*900-v*9*(.3+hash(i+9))+9000)%900, r=2+hash(i+5)*5, a=(.10+.25*hash(i+11))*(.5+.5*sin(v*1.7+i*2));
g.fillStyle=`rgba(255,220,160,${a})`; g.beginPath(); g.arc(x,y,r,0,TAU); g.fill(); }
g.restore();
}
/* ---------- the empty suit ---------- */
const LX=.42, LY=-.9; // light direction
function limb(ax,ay,bx,by,wa,wb,col){
const a=Math.atan2(by-ay,bx-ax); let nx=-sin(a), ny=cos(a); if(nx*LX+ny*LY<0){nx=-nx;ny=-ny;}
const mx=(ax+bx)/2,my=(ay+by)/2,w=Math.max(wa,wb), gr=g.createLinearGradient(mx-nx*w,my-ny*w,mx+nx*w,my+ny*w);
gr.addColorStop(0,shade(col,-.5)); gr.addColorStop(.38,col); gr.addColorStop(.74,shade(col,.17)); gr.addColorStop(1,shade(col,-.08));
g.fillStyle=gr; g.beginPath();
g.moveTo(ax+nx*wa,ay+ny*wa); g.lineTo(bx+nx*wb,by+ny*wb); g.lineTo(bx-nx*wb,by-ny*wb); g.lineTo(ax-nx*wa,ay-ny*wa); g.closePath(); g.fill();
g.beginPath(); g.arc(ax,ay,wa,0,TAU); g.fill();
}
function folds(jx,jy,ax,ay,bx,by,w){ // creases on the inside of a bent elbow / knee
const d1=Math.atan2(ay-jy,ax-jx), d2=Math.atan2(by-jy,bx-jx); let df=Math.abs(d1-d2); if(df>Math.PI) df=TAU-df; const bend=clamp((Math.PI-df)/1.6); if(bend<.08) return;
const mx=cos(d1)+cos(d2), my=sin(d1)+sin(d2), m=Math.atan2(my,mx);
g.lineCap='round';
for(let i=0;i<3;i++){ g.strokeStyle=`rgba(0,0,0,${(.30-.07*i)*bend})`; g.lineWidth=w*.11; g.beginPath(); g.arc(jx-cos(m)*w*.15,jy-sin(m)*w*.15,w*(.5+.24*i),m-.75+.1*i,m+.75-.1*i); g.stroke(); }
g.strokeStyle=`rgba(255,255,255,${.10*bend})`; g.lineWidth=w*.08; g.beginPath(); g.arc(jx,jy,w*.86,m+Math.PI-.6,m+Math.PI+.6); g.stroke();
}
function hole(x,y,ang,rw,cuff){ // open end of a sleeve / trouser leg
g.save(); g.translate(x,y); g.rotate(ang);
if(cuff){ g.fillStyle='#f6f2ea'; g.beginPath(); g.ellipse(0,8,rw*.86,rw*.42,0,0,TAU); g.fill(); g.fillRect(-rw*.86,-2,rw*1.72,10);
g.fillStyle='rgba(0,0,0,.18)'; g.fillRect(-rw*.86,-2,rw*1.72,3); }
g.fillStyle='#050403'; g.beginPath(); g.ellipse(0,cuff?9:1,rw*(cuff?.7:.92),rw*.36,0,0,TAU); g.fill();
if(cuff){ g.fillStyle='rgba(0,0,0,.6)'; for(let i=0;i<3;i++){ g.beginPath(); g.arc(rw*.78,-8-i*7,2,0,TAU); g.fill(); } }
g.restore();
}
function jacketPath(sh,flare,hem){
g.beginPath(); g.moveTo(-18,-182); g.bezierCurveTo(-40,-180,-sh+4,-178,-sh-2,-160); g.quadraticCurveTo(-sh-6,-118,-50+hem*.25,-70);
g.quadraticCurveTo(-53+hem*.6,-10,-59-flare+hem,40); g.quadraticCurveTo(hem,54,59+flare+hem,40); g.quadraticCurveTo(53+hem*.6,-10,50+hem*.25,-70);
g.quadraticCurveTo(sh+6,-118,sh+2,-160); g.bezierCurveTo(sh-4,-178,40,-180,18,-182); g.closePath();
}
function drawBody(S,p){
const s=p.s, col=S.col, hi=shade(col,.16), lo=shade(col,-.32), fy=p.floor-(p.hop||0)*s;
const hx=p.x+p.sway*s, hy=fy-(240-p.dip)*s, L=121*s;
for(const sd of [-1,1]){
const lift=(sd<0?p.liftL:p.liftR)||0, fx=p.x+sd*(40+lift*.25)*s+p.sway*.22*s, ffy=fy-16*s-lift*s;
const jx=hx+sd*24*s, jy=hy, dx=fx-jx, dy=ffy-jy, d=Math.min(Math.hypot(dx,dy),2*L-1), base=Math.atan2(dy,dx), a=Math.acos(d/(2*L));
const kx=jx+L*cos(base-sd*a), ky=jy+L*sin(base-sd*a), c=sd*(p.twist>=0?1:-1)<0?lo:col;
limb(jx,jy,kx,ky,31*s,25*s,c); limb(kx,ky,fx,ffy,25*s,20*s,c);
folds(kx,ky,jx,jy,fx,ffy,25*s);
g.strokeStyle='rgba(255,255,255,.09)'; g.lineWidth=1.6*s; g.beginPath(); g.moveTo(jx+sd*2*s,jy+26*s); g.lineTo(kx,ky); g.lineTo(fx,ffy-4*s); g.stroke();
g.strokeStyle='rgba(0,0,0,.25)'; g.lineWidth=3*s; g.beginPath(); g.arc(fx,ffy-12*s,19*s,.25,Math.PI-.25); g.stroke(); // break of the trouser on the shoe
hole(fx,ffy+1*s,Math.atan2(ffy-ky,fx-kx)-Math.PI/2,20*s,false);
g.save(); g.translate(fx+sd*5*s,ffy+19*s); g.scale(sd,1);
const sg=g.createLinearGradient(0,-12*s,0,12*s); sg.addColorStop(0,'#2a2522'); sg.addColorStop(1,'#050404'); g.fillStyle=sg;
g.beginPath(); g.moveTo(-17*s,-8*s); g.quadraticCurveTo(8*s,-13*s,34*s,-2*s); g.quadraticCurveTo(42*s,5*s,36*s,10*s); g.lineTo(-18*s,10*s); g.quadraticCurveTo(-22*s,0,-17*s,-8*s); g.fill();
g.fillStyle='#000'; g.fillRect(-19*s,8*s,56*s,4*s); g.fillRect(-19*s,6*s,12*s,7*s);
g.fillStyle='rgba(255,255,255,.35)'; g.beginPath(); g.ellipse(24*s,-1*s,9*s,2.6*s,.25,0,TAU); g.fill();
g.fillStyle='#000'; g.beginPath(); g.ellipse(-4*s,-7*s,13*s,4.5*s,0,0,TAU); g.fill(); g.restore();
}
g.save(); g.translate(hx,hy); g.rotate(p.lean); g.scale(s,s*(1-p.dip*.0011));
const tw=p.twist*13, sh=64-Math.abs(p.twist)*5, hem=clamp(p.hem||0,-16,16), flare=6+Math.abs(hem)*.5+p.dip*.22;
const arm=(sd,a,c,bk)=>{ const sx=sd*(sh-9), sy=-148, ex=sx+sd*sin(a)*94, ey=sy+cos(a)*94, wx=ex+sd*sin(a+c)*88, wy=ey+cos(a+c)*88, cc=bk?lo:col;
limb(sx,sy,ex,ey,24,21,cc); limb(ex,ey,wx,wy,21,17,cc); folds(ex,ey,sx,sy,wx,wy,21);
hole(wx,wy,Math.atan2(wy-ey,wx-ex)-Math.PI/2,17,true);
if(!bk){ g.fillStyle=shade(col,.1); g.beginPath(); g.ellipse(sd*(sh-12),-164,26,15,sd*.35,Math.PI,TAU); g.fill(); } };
const bs=p.twist>=0?-1:1;
arm(bs,bs<0?p.aL:p.aR,bs<0?p.cL:p.cR,true);
const jg=g.createLinearGradient(-70,0,70,0); jg.addColorStop(0,shade(col,-.42)); jg.addColorStop(.4,col); jg.addColorStop(.74,hi); jg.addColorStop(1,shade(col,-.12));
g.fillStyle=jg; jacketPath(sh,flare,hem); g.fill();
g.save(); jacketPath(sh,flare,hem); g.clip();
if(S.stripe){ g.strokeStyle='rgba(255,255,255,.11)'; g.lineWidth=1; for(let x=-80;x<=80;x+=9){ g.beginPath(); g.moveTo(x+tw*.4,-190); g.lineTo(x+hem,60); g.stroke(); } }
const vg=g.createLinearGradient(0,-185,0,50); vg.addColorStop(0,'rgba(255,240,210,.10)'); vg.addColorStop(.45,'rgba(0,0,0,0)'); vg.addColorStop(1,'rgba(0,0,0,.34)'); g.fillStyle=vg; g.fillRect(-90,-190,180,250);
g.strokeStyle='rgba(0,0,0,.20)'; g.lineWidth=5; g.lineCap='round'; // pull creases toward the button
for(const sd of [-1,1]){ g.beginPath(); g.moveTo(tw*.8+sd*6,-44); g.quadraticCurveTo(sd*30,-52,sd*50,-72); g.stroke(); g.beginPath(); g.moveTo(tw*.8+sd*6,-36); g.quadraticCurveTo(sd*32,-20,sd*54,-14); g.stroke(); }
g.restore();
// shirt + tie
g.fillStyle='#f6f2ea'; g.beginPath(); g.moveTo(-17+tw*.3,-181); g.lineTo(17+tw*.3,-181); g.lineTo(tw,-64); g.closePath(); g.fill();
g.fillStyle='rgba(0,0,0,.12)'; g.beginPath(); g.moveTo(-17+tw*.3,-181); g.lineTo(-6+tw*.3,-181); g.lineTo(tw-2,-70); g.closePath(); g.fill();
g.save(); g.translate(tw*.5,-171); g.rotate(clamp(p.tie||0,-.5,.5)); const tg=g.createLinearGradient(-11,0,11,0); tg.addColorStop(0,shade(S.tie,-.35)); tg.addColorStop(.6,S.tie); tg.addColorStop(1,shade(S.tie,.2)); g.fillStyle=tg;
g.beginPath(); g.moveTo(-7,0); g.lineTo(7,0); g.lineTo(5,11); g.lineTo(11,80); g.lineTo(0,96); g.lineTo(-11,80); g.lineTo(-5,11); g.closePath(); g.fill();
g.strokeStyle='rgba(0,0,0,.3)'; g.lineWidth=1.5; g.beginPath(); g.moveTo(-5,11); g.lineTo(5,11); g.stroke(); g.restore();
// lapels with a soft shadow under them
g.fillStyle='rgba(0,0,0,.28)'; g.beginPath(); g.moveTo(-18+tw*.3,-180); g.lineTo(-37,-146); g.lineTo(-22,-132); g.lineTo(tw-3,-58); g.closePath(); g.fill();
g.beginPath(); g.moveTo(18+tw*.3,-180); g.lineTo(37,-146); g.lineTo(22,-132); g.lineTo(tw+3,-58); g.closePath(); g.fill();
g.fillStyle=hi; g.beginPath(); g.moveTo(-18+tw*.3,-183); g.lineTo(-35,-151); g.lineTo(-23,-139); g.lineTo(tw-3,-64); g.lineTo(tw-1,-82); g.closePath(); g.fill();
g.fillStyle=shade(col,.07); g.beginPath(); g.moveTo(18+tw*.3,-183); g.lineTo(35,-151); g.lineTo(23,-139); g.lineTo(tw+3,-64); g.lineTo(tw+1,-82); g.closePath(); g.fill();
g.strokeStyle='rgba(0,0,0,.4)'; g.lineWidth=1.5; g.beginPath(); g.moveTo(tw,-64); g.quadraticCurveTo(tw*.7+hem*.4,-10,tw*.4+hem-2,44); g.stroke();
for(const y of [-46,-16]){ g.fillStyle='rgba(0,0,0,.6)'; g.beginPath(); g.arc(tw*.8+4+hem*.2,y,4,0,TAU); g.fill(); g.fillStyle='rgba(255,255,255,.25)'; g.beginPath(); g.arc(tw*.8+3+hem*.2,y-1,1.4,0,TAU); g.fill(); }
g.fillStyle=S.sq; g.beginPath(); g.moveTo(26,-122); g.lineTo(33,-135); g.lineTo(38,-125); g.lineTo(44,-134); g.lineTo(47,-121); g.closePath(); g.fill();
g.strokeStyle='rgba(0,0,0,.32)'; g.lineWidth=2; g.beginPath(); g.moveTo(24,-120); g.lineTo(48,-120); g.moveTo(-52+hem*.5,-6); g.lineTo(-24+hem*.5,-4); g.moveTo(24+hem*.5,-4); g.lineTo(52+hem*.5,-6); g.stroke();
// collar + the empty neck
g.fillStyle='#e9e3d6'; g.beginPath(); g.ellipse(tw*.3,-186,21,9.5,0,0,TAU); g.fill();
const ng=g.createRadialGradient(tw*.3,-183,2,tw*.3,-185,18); ng.addColorStop(0,'#000'); ng.addColorStop(1,'#1a1410'); g.fillStyle=ng; g.beginPath(); g.ellipse(tw*.3,-185,17,6.8,0,0,TAU); g.fill();
g.fillStyle='#fffdf7'; g.beginPath(); g.moveTo(-21+tw*.3,-186); g.lineTo(-4+tw*.4,-165); g.lineTo(-23+tw*.3,-158); g.closePath(); g.fill();
g.beginPath(); g.moveTo(21+tw*.3,-186); g.lineTo(4+tw*.4,-165); g.lineTo(23+tw*.3,-158); g.closePath(); g.fill();
g.strokeStyle='rgba(0,0,0,.18)'; g.lineWidth=1.5; g.beginPath(); g.moveTo(-4+tw*.4,-165); g.lineTo(-23+tw*.3,-158); g.moveTo(4+tw*.4,-165); g.lineTo(23+tw*.3,-158); g.stroke();
arm(-bs,bs<0?p.aR:p.aL,bs<0?p.cR:p.cL,false);
g.restore();
}
function drawSuit(S,p){
g.save(); g.globalAlpha=p.alpha==null?1:p.alpha;
const sh=g.createRadialGradient(p.x,p.floor+8*p.s,4,p.x,p.floor+8*p.s,125*p.s); sh.addColorStop(0,'rgba(0,0,0,.6)'); sh.addColorStop(1,'rgba(0,0,0,0)');
g.save(); g.translate(0,(p.floor+8*p.s)*(1-.17)); g.scale(1,.17); g.fillStyle=sh; g.beginPath(); g.arc(p.x,p.floor+8*p.s,125*p.s,0,TAU); g.fill(); g.restore();
if(QUALITY>0&&p.floor>FLOOR+20){ g.save(); g.globalAlpha*=.13; g.translate(0,2*(p.floor+12*p.s)); g.scale(1,-1); drawBody(S,p); g.restore(); }
drawBody(S,p); g.restore();
}
/* ---------- choreography ---------- */
const hold=x=>Math.tanh(1.9*x)/Math.tanh(1.9); // hit a pose and hold it, like a person does
function move(st,b){ const pu=Math.pow(.5-.5*cos(TAU*b),1.5), sw=hold(sin(Math.PI*b)), f=hold(sin(TAU*b)), f2=sin(TAU*b+1);
switch(st){
case 0: return {aL:.5+.15*sw,cL:1.45,aR:2.1+.6*pu,cR:.8-.65*pu,lean:.06*sw,sway:22*sw,twist:.45*sw,lL:0,lR:24*pu};
case 1: return {aL:2.55+.3*sw,cL:.4+.25*pu,aR:2.55-.3*sw,cR:.4+.25*pu,lean:.12*sw,sway:32*sw,twist:.25*sw,lL:14*clamp(-sw),lR:14*clamp(sw)};
case 2: return {aL:1.42+.3*f,cL:1.25+.38*f2,aR:1.42-.3*f,cR:1.25-.38*f2,lean:.05*f,sway:16*sw,twist:.9*f,lL:16*clamp(f),lR:16*clamp(-f)};
case 3: return {aL:.6+.6*sw,cL:1.5,aR:.6-.6*sw,cR:1.5,lean:.05*sw,sway:36*sw,twist:1*sw,lL:30*clamp(sw)*pu,lR:30*clamp(-sw)*pu};
default:return {aL:.4+.2*pu,cL:.25,aR:lerp(1.0,2.5,.5+.5*sw),cR:.14,lean:-.11*sw,sway:-28*sw,twist:-.6*sw,lL:0,lR:18*pu};
}
}
const K=['aL','cL','aR','cR','lean','sway','twist','lL','lR'];
function mix(a,b,t){ const o={}; for(const k of K) o[k]=lerp(a[k],b[k],t); return o; }
function seqPose(S,b){ const seg=Math.floor(b/4), q=b-seg*4, st=i=>S.seq[((i%S.seq.length)+S.seq.length)%S.seq.length];
return mix(move(st(seg-1),b),move(st(seg),b),ss(0,.8,q)); }
function dancePose(S,b){ // overlapping action: hips lead, shoulders follow, forearms trail
const h=seqPose(S,b), a=seqPose(S,b-.07), f=seqPose(S,b-.15);
return {aL:a.aL,aR:a.aR,cL:f.cL,cR:f.cR,lean:a.lean,sway:h.sway,twist:h.twist,lL:h.lL,lR:h.lR}; }
const SUITS=[
{x:185,floor:835,s:.74,col:'#2b3550',tie:'#b03a3a',sq:'#f3efe6',seq:[2,1,3,0,4],n:1.3,stripe:1},
{x:895,floor:835,s:.74,col:'#5a2230',tie:'#e0b46a',sq:'#f3efe6',seq:[1,3,2,4,0],n:2.9},
{x:290,floor:1052,s:1.02,col:'#3a3b42',tie:'#e0b46a',sq:'#b03a3a',seq:[3,0,2,1,4],n:4.1,stripe:1},
{x:800,floor:1052,s:1.02,col:'#3d4a34',tie:'#1c1c1c',sq:'#e0b46a',seq:[0,2,4,3,1],n:5.7},
];
const GUEST={col:'#1a1a1f',tie:'#a6e24d',sq:'#a6e24d',seq:[1,3,0,2,4],n:7.3};
const REST={aL:.14,cL:.12,aR:.14,cR:.12,lean:0,sway:0,twist:0,lL:0,lR:0};
function crowdCore(S,v){
const E=energy(v), b=beat(v)-hash(S.n)*.06, d=dancePose(S,b), amp=.25+.75*E, listen=ss(10.25,10.6,v)*(1-ss(CLICK+1.35,CLICK+1.6,v));
let p=mix(REST,d,amp); const toDoor=(540-S.x)/360;
p=mix(p,{aL:.18,cL:.1,aR:.18,cR:.1,lean:toDoor*.09,sway:toDoor*10,twist:toDoor*.9,lL:0,lR:0},listen);
// small human imperfections
p.aL+=.05*sin(v*.9+S.n); p.aR+=.05*sin(v*1.1+S.n*2); p.lean+=.012*sin(v*.7+S.n*3)-p.sway*.0012;
const dip=(8+19*E)*Math.pow(.5-.5*cos(TAU*b),1.3)*amp*(1-listen)+(5+1.5*sin(v*2+S.n))*listen;
const kp=knockPulse(v), t0=13.05+D, drop=ss(t0-.05,t0+.12,v)*(1-ss(t0+.5,t0+1.2,v));
p.aL=lerp(p.aL,2.75,drop); p.aR=lerp(p.aR,2.75,drop); p.cL=lerp(p.cL,.15,drop); p.cR=lerp(p.cR,.15,drop);
return {x:S.x,floor:S.floor,s:S.s,dip,sway:p.sway,lean:p.lean,twist:p.twist,aL:p.aL,cL:p.cL,aR:p.aR,cR:p.cR,liftL:p.lL*amp,liftR:p.lR*amp,hop:listen*kp*9+drop*38*sin(Math.PI*clamp((v-t0)/.5))};
}
function guestCore(S,v){
const E=energy(v), b=beat(v), t0=CLICK+.25, m=13.05+D, walk=ss(m,m+1.7,v), dance=ss(m+1.4,m+2.2,v);
const fl=lerp(748,1075,eo(walk)), s=lerp(.6,1.14,eo(walk));
const wave=ss(t0+.2,t0+.5,v)*(1-ss(m-.3,m-.1,v)), spread=ss(m-.26,m-.02,v)*(1-ss(m+.5,m+1.3,v));
let p=Object.assign({},REST);
p.aR=lerp(p.aR,2.5,wave); p.cR=lerp(p.cR,.28,wave); p.lean=lerp(0,.06,wave); p.twist=.25*wave;
p.aL=lerp(p.aL,1.62,spread); p.aR=lerp(p.aR,1.62,spread); p.cL=lerp(p.cL,.05,spread); p.cR=lerp(p.cR,.05,spread);
const strut=walk*(1-dance), wb=hold(sin(Math.PI*b));
p.sway+=18*wb*strut; p.lean+=.06*wb*strut; p.twist+=.6*wb*strut; p.lL+=26*clamp(wb)*strut; p.lR+=26*clamp(-wb)*strut;
p=mix(p,dancePose(GUEST,b),dance*(.3+.7*E));
const dip=(7+20*E)*Math.pow(.5-.5*cos(TAU*b),1.3)*walk+3*(1-walk);
return {x:540,floor:fl,s,dip,sway:p.sway,lean:p.lean,twist:p.twist,aL:p.aL,cL:p.cL,aR:p.aR,cR:p.cR,liftL:p.lL,liftR:p.lR,hop:0,alpha:ss(CLICK+.12,CLICK+.5,v)};
}
function withCloth(core,S,v){ // tie and jacket hem swing behind the body
const p=core(S,v), q=core(S,v-.09), r=core(S,v-.18);
const vel=(p.sway-q.sway)+(p.lean-q.lean)*160, vel2=(q.sway-r.sway)+(q.lean-r.lean)*160;
p.hem=-(vel*.55+vel2*.45)*.9; p.tie=-p.lean*.9-(vel*.4+vel2*.6)*.022; return p; }
/* ---------- frame ---------- */
const $=id=>document.getElementById(id), cta=$('cta'), ring=$('ring'), cur=$('cursor'), rip=$('rip'), end=$('end');
const DOORI='<svg viewBox="0 0 24 24"><path d="M5 21V4a1 1 0 011-1h9l4 2v16M3 21h18M14 12h.01"/></svg>';
const FILM=/film/.test(location.search); let lastLabel='', liveEnd=0, liveWait=0;
function label(h){ if(h!==lastLabel){ lastLabel=h; cta.innerHTML=h; } }
const grain=document.createElement('canvas'); grain.width=540; grain.height=550; (function(){ const c=grain.getContext('2d'), im=c.createImageData(540,550); for(let i=0;i<im.data.length;i+=4){ const n=hash(i*.37)*255; im.data[i]=im.data[i+1]=im.data[i+2]=n; im.data[i+3]=15; } c.putImageData(im,0,0); })();
function render(v){
const E=energy(v), A=accent(v), open=eo((v-CLICK-.02)/.5)*(v>=CLICK?1:0);
const listen=ss(10.3,11.2,v)*(1-ss(CLICK+.9,CLICK+2.2,v));
g.setTransform(1,0,0,1,0,0); g.clearRect(0,0,1080,1100);
// hand-held camera: breathes with the music, pushes in on the door while everyone listens
const z=1.02+.012*A+.075*listen, cx=540, cy=lerp(600,470,listen), shx=sin(v*1.7)*5+sin(v*23)*2.2*A, shy=cos(v*1.3)*4+cos(v*19)*2.2*A;
g.translate(cx+shx,cy+shy); g.scale(z,z); g.rotate(sin(v*.9)*.004); g.translate(-cx,-cy);
const leaf=room(v,E,A,open); tinsel(v); floor(v,E,A,open);
const list=SUITS.map(S=>({S,p:withCloth(crowdCore,S,v)}));
const gp=withCloth(guestCore,GUEST,v), guestIn=v>=CLICK+.1;
if(guestIn&&gp.floor<760){ g.save(); g.beginPath(); g.rect(DOOR.x,DOOR.y-40,DOOR.w+(gp.floor>749?400:0),DOOR.h+60+(gp.floor>749?400:0)); g.clip(); drawSuit(GUEST,gp); g.restore(); }
leaf();
if(guestIn&&gp.floor>=760) list.push({S:GUEST,p:gp});
list.sort((a,c)=>a.p.floor-c.p.floor);
const far=list.filter(o=>o.p.floor<900), near=list.filter(o=>o.p.floor>=900);
if(QUALITY>1){ // back row slightly out of focus
const m=g.getTransform(), o=g; bg2.setTransform(1,0,0,1,0,0); bg2.clearRect(0,0,1080,1100); bg2.setTransform(m); g=bg2; far.forEach(o2=>drawSuit(o2.S,o2.p)); g=o;
g.save(); g.setTransform(1,0,0,1,0,0); g.filter='blur(1.6px) brightness(.86)'; g.drawImage(back,0,0); g.restore();
} else far.forEach(o=>drawSuit(o.S,o.p));
atmosphere(v,E,A);
near.forEach(o=>drawSuit(o.S,o.p));
KNOCKS.forEach((k,i)=>{ const u=(v-k)/.55; if(u>=0&&u<1&&v<CLICK){ g.save(); g.globalAlpha=1-u; g.fillStyle='#ffe2a8'; g.font='900 60px Vz'; g.textAlign='center'; g.fillText('تق',(i%2?672:408)+(i%3)*10,330+(i%3)*70-u*46); g.restore(); } });
g.setTransform(1,0,0,1,0,0);
g.fillStyle=`rgba(255,190,110,${.09*A})`; g.fillRect(0,0,1080,1100);
if(QUALITY>1){ g.save(); g.globalCompositeOperation='lighter'; g.globalAlpha=.22; g.filter='blur(18px)'; g.drawImage(cv,0,0); g.restore(); }
const vg=g.createRadialGradient(540,540,360,540,560,860); vg.addColorStop(0,'rgba(0,0,0,0)'); vg.addColorStop(1,'rgba(0,0,0,.66)'); g.fillStyle=vg; g.fillRect(0,0,1080,1100);
const dim=ss(10.1,10.6,v)*(1-ss(CLICK,CLICK+.5,v)); g.fillStyle=`rgba(4,3,6,${.30*dim})`; g.fillRect(0,0,1080,1100);
const fr=Math.floor(v*30); g.save(); g.globalCompositeOperation='overlay'; g.drawImage(grain,-hash(fr)*60,-hash(fr+9)*60,1188,1210); g.restore();
/* --- UI --- */
const kp=knockPulse(v), waiting=v>=10.55&&v<CLICK, press=v>=CLICK-.07&&v<CLICK+.1;
if(v<10.55||v>CLICK+2.6) label('<span>مشاهدهی کالکشن</span>'); else if(v<CLICK) label(DOORI+'<span>در میزنن… باز کن</span>'); else label('<span>بفرما تو!</span>');
const hover=FILM&&v>CLICK-.45&&v<CLICK+.6;
const sc=(waiting?1+.17*kp+(v>11.9?.025*sin(v*9):0)+(FILM?0:.04*sin(liveWait*4.5)*Math.min(1,liveWait)):1)*(press?.93:1)*(hover&&!press?1.04:1);
cta.style.transform=`scale(${sc.toFixed(4)})`; cta.style.filter=hover?'brightness(1.1)':'';
ring.style.opacity=waiting?(.75*kp).toFixed(3):0; ring.style.transform=`scale(${(1.1+.22*kp).toFixed(3)})`;
let e=liveEnd;
if(FILM){
const t=eo((v-11.9)/1.85), ox=880, oy=1870, tx=600, ty=1640, wob=sin(t*Math.PI)*90, out=ss(CLICK+.9,CLICK+2.2,v);
const x=lerp(lerp(ox,tx,t)-wob,930,out), y=lerp(lerp(oy,ty,t),1980,out);
cur.style.display=v>11.85&&v<CLICK+2.3?'block':'none';
cur.style.transform=`translate(${x.toFixed(1)}px,${y.toFixed(1)}px) scale(${press?.86:1})`;
const r=(v-CLICK)/.5; rip.style.opacity=r>=0&&r<1?(1-r).toFixed(3):0; rip.style.transform=`translate(${tx+8}px,${ty+8}px) scale(${(.3+r*1.6).toFixed(3)})`;
e=ss(END-3.0,END-2.3,v);
}
end.style.opacity=e.toFixed(3); end.style.transform=`translateY(${((1-e)*90).toFixed(1)}px)`; end.style.pointerEvents=e>.9&&!FILM?'auto':'none';
}
window.__render=render; window.__END=END;
/* ---------- live site: the song plays, stops at the knock, waits for the visitor ---------- */
function fit(){ const k=Math.min(innerWidth/1080,innerHeight/1920); $('fit').style.transform=`scale(${k}) translate(-50%,-50%)`; }
addEventListener('resize',fit); fit();
if(FILM){ document.fonts.ready.then(()=>{ render(0); window.__ready=true; }); }
else{
const au=new Audio('vay.mp3'); au.preload='auto';
const MUSIC=.6, KNOCK=1; let state='gate', v=5.05, t0=0, tw=0, last=performance.now(), slow=0, frames=0, ok=true;
au.addEventListener('error',()=>{ok=false});
const gate=$('gate'), again=$('again'); gate.style.display='flex'; again.style.display='block';
const play=(t,vol)=>{ try{ au.currentTime=t; au.volume=vol; const pr=au.play(); if(pr) pr.catch(()=>{ok=false}); }catch(e){ ok=false; } };
function start(){ gate.style.display='none'; liveEnd=0; state='s1'; v=0; t0=performance.now(); play(0,MUSIC); }
$('enter').addEventListener('click',start); again.addEventListener('click',start);
cta.addEventListener('click',()=>{ if((state==='wait'||state==='s1')&&v>=10.55){ au.pause(); liveWait=0; state='open'; t0=performance.now(); v=CLICK; } });
function loop(n){ const dt=Math.min(.05,(n-last)/1000); last=n;
if(frames<90){ frames++; if(dt>.03) slow++; if(frames===90&&slow>30){ QUALITY=slow>60?0:1; } }
if(state==='gate'){ v+=dt; if(v>9.6) v=5.05; }
else if(state==='s1'){ v=ok?au.currentTime:(n-t0)/1000; if(v>=10.5) au.volume=KNOCK; if(v>=11.93){ au.pause(); state='wait'; tw=n; v=11.95; } }
else if(state==='wait'){ liveWait=(n-tw)/1000; } // silent until the visitor opens the door
else if(state==='open'){ v=CLICK+(n-t0)/1000; if(v>=11.95+D){ play(11.95,.8); state='s3'; t0=n; } }
else if(state==='s3'){ v=ok&&!au.paused?au.currentTime+D:11.95+D+(n-t0)/1000; if(au.currentTime>=13) au.volume=MUSIC;
if(v>=END-2.9||au.ended){ state='end'; t0=n; } }
else if(state==='end'){ v=Math.min(END-.05,v+dt); liveEnd=ss(0,.7,(n-t0)/1000); }
render(v); requestAnimationFrame(loop); }
requestAnimationFrame(loop);
}
</script>
</body>
</html>
طراحی و کدنویسی: پیستاکد. کد فقط برای مشاهده نمایش داده شده و همهی حقوق آن محفوظ است.