verlanovich

Tapvibes-Verlanovich(10)

Oct 17th, 2026
29
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 36.57 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="id">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, viewport-fit=cover">
  6. <title>tap particles — verlanovich</title>
  7. <style>
  8. * { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
  9. :root {
  10.   --bg: #cce5f6; --box: #eef7ff; --nav: #a8d4ee;
  11.   --border: #88bbdd; --blue1: #2255aa; --blue2: #1155cc;
  12.   --blue3: #5aabdd; --muted: #668899; --font: verdana, arial, sans-serif;
  13. }
  14. html { overscroll-behavior: none; overflow: hidden; height: 100%; }
  15. body {
  16.   width: 100%; height: 100%; overflow: hidden;
  17.   background: var(--bg); font-family: var(--font); font-size: 13px; color: #222;
  18.   touch-action: none; overscroll-behavior: none;
  19.   user-select: none; -webkit-user-select: none;
  20. }
  21. #pc { position: fixed; top:0; left:0; width:100%; height:100%; pointer-events:none; z-index:0; }
  22. #tap-zone { position: fixed; inset:0; z-index:1; }
  23.  
  24. /* ═══ HUD ═══ */
  25. #hud {
  26.   position: fixed; top:10px; left:10px; right:10px;
  27.   display:flex; justify-content:space-between; align-items:flex-start;
  28.   z-index:50; pointer-events:none;
  29. }
  30. #hud-left {
  31.   display:flex; align-items:center; gap:8px;
  32.   background:rgba(238,247,255,0.92); border:1px solid var(--border);
  33.   padding:6px 10px 6px 6px;
  34. }
  35. #avatar, #avatar-ph {
  36.   width:42px; height:42px; object-fit:cover;
  37.   border:1px solid var(--border); display:block; flex-shrink:0;
  38. }
  39. #avatar-ph { background:var(--nav); }
  40. #player-name { font-size:12px; font-weight:bold; color:var(--blue1); line-height:1.3; }
  41. #player-tag  { font-size:10px; color:var(--muted); }
  42. #hud-right {
  43.   text-align:right; background:rgba(238,247,255,0.92);
  44.   border:1px solid var(--border); padding:6px 10px;
  45. }
  46. #score-lbl { font-size:10px; color:var(--muted); letter-spacing:1px; }
  47. #score {
  48.   font-size:28px; font-weight:bold; color:var(--blue1);
  49.   line-height:1.1; letter-spacing:-0.5px; font-variant-numeric:tabular-nums;
  50.   transition: color 0.1s;
  51. }
  52. #score.pop { color:var(--blue2); }
  53. #score.rollover { color:#cc2200; animation: rollflash 0.6s ease; }
  54. @keyframes rollflash { 0%{color:#cc2200;transform:scale(1.3)} 100%{color:var(--blue1);transform:scale(1)} }
  55. #combo { font-size:12px; font-weight:bold; color:var(--blue2); margin-top:2px; }
  56. #combo.hidden { opacity:0; }
  57. #streak-wrap { width:72px; height:3px; background:var(--border); margin:3px 0 0 auto; }
  58. #streak-fill { height:100%; background:var(--blue1); width:0%; transition:width 0.1s; }
  59.  
  60. /* ═══ TIMER ═══ */
  61. #timer-wrap {
  62.   position:fixed; top:84px; right:10px; z-index:50; pointer-events:none;
  63.   background:rgba(238,247,255,0.92); border:1px solid var(--border);
  64.   padding:4px 8px; text-align:right;
  65. }
  66. #timer-lbl { font-size:9px; color:var(--muted); letter-spacing:1px; }
  67. #timer { font-size:16px; font-weight:bold; color:var(--blue1); font-variant-numeric:tabular-nums; line-height:1.2; }
  68. #timer.warn { color:#cc4400; }
  69.  
  70. /* ═══ PLAYER ═══ */
  71. #player {
  72.   position:fixed; bottom:0; left:0; right:0; z-index:100;
  73.   background:var(--nav); border-top:1px solid var(--border);
  74.   transition:transform 0.28s ease;
  75. }
  76. #player.collapsed { transform:translateY(calc(100% - 34px)); }
  77. #player-tab {
  78.   height:34px; display:flex; align-items:center; justify-content:space-between;
  79.   padding:0 12px; cursor:pointer; font-size:12px; font-weight:bold; color:var(--blue1);
  80.   pointer-events:all; touch-action:manipulation;
  81. }
  82. #player-body { padding:9px 12px 12px; background:var(--box); border-top:1px solid var(--border); pointer-events:all; }
  83. #track-name {
  84.   font-size:11px; font-weight:bold; color:var(--blue1);
  85.   white-space:nowrap; overflow:hidden; text-overflow:ellipsis; margin-bottom:8px;
  86. }
  87. #player-ctrls { display:flex; align-items:center; gap:5px; margin-bottom:8px; }
  88. .pctrl {
  89.   background:var(--nav); border:1px solid var(--border); color:var(--blue1);
  90.   font-family:var(--font); font-size:11px; font-weight:bold; padding:5px 10px;
  91.   cursor:pointer; touch-action:manipulation; pointer-events:all; min-height:32px;
  92. }
  93. .pctrl:active { background:var(--border); }
  94. .pctrl.on { background:var(--blue1); color:#fff; border-color:var(--blue1); }
  95. .rate-row { display:flex; align-items:center; gap:5px; margin-bottom:6px; }
  96. .rate-lbl { font-size:10px; color:var(--muted); width:36px; flex-shrink:0; }
  97. .rate-btn {
  98.   background:var(--nav); border:1px solid var(--border); color:var(--blue1);
  99.   font-family:var(--font); font-size:16px; font-weight:bold;
  100.   width:32px; height:28px; display:flex; align-items:center; justify-content:center;
  101.   cursor:pointer; flex-shrink:0; touch-action:manipulation; pointer-events:all; line-height:1; padding:0;
  102. }
  103. .rate-btn:active { background:var(--border); }
  104. .rate-val {
  105.   font-size:12px; font-weight:bold; color:var(--blue1); font-family:var(--font);
  106.   min-width:46px; text-align:center; background:var(--nav); border:1px solid var(--border); padding:2px 4px; flex-shrink:0;
  107. }
  108. #vol-row { display:flex; align-items:center; gap:6px; margin-bottom:7px; }
  109. #vol-row span { font-size:10px; color:var(--muted); }
  110. #vol-slider {
  111.   -webkit-appearance:none; flex:1; height:6px;
  112.   background:var(--nav); border:1px solid var(--border);
  113.   outline:none; cursor:pointer; touch-action:manipulation; pointer-events:all;
  114. }
  115. #vol-slider::-webkit-slider-thumb { -webkit-appearance:none; width:18px; height:18px; background:var(--blue1); }
  116. #seek-row { display:flex; align-items:center; gap:6px; margin-bottom:7px; }
  117. .ttime { font-size:10px; color:var(--muted); width:28px; flex-shrink:0; }
  118. .ttime.r { text-align:right; }
  119. #seek-track {
  120.   flex:1; height:8px; background:var(--nav); border:1px solid var(--border);
  121.   cursor:pointer; position:relative; touch-action:manipulation; pointer-events:all;
  122.   padding:6px 0; margin:-6px 0; background-clip:content-box;
  123. }
  124. #seek-done { height:8px; background:var(--blue1); width:0%; pointer-events:none; }
  125. #freq-canvas { display:block; width:100%; height:22px; margin-bottom:7px; background:var(--nav); border:1px solid var(--border); }
  126. #upload-btn {
  127.   display:block; width:100%; text-align:center; background:var(--nav); border:1px solid var(--border);
  128.   color:var(--blue2); font-family:var(--font); font-size:11px; padding:7px 0; cursor:pointer;
  129.   touch-action:manipulation; pointer-events:all; min-height:32px;
  130. }
  131. #upload-btn:active { background:var(--border); }
  132. #file-in { display:none; }
  133.  
  134. /* ═══ HINT ═══ */
  135. #hint {
  136.   position:fixed; top:50%; left:50%; transform:translate(-50%,-50%);
  137.   text-align:center; pointer-events:none; z-index:2;
  138. }
  139. #hint-main { font-size:13px; font-weight:bold; color:var(--blue1); animation:blink 2.5s ease-in-out infinite; }
  140. #hint-sub  { font-size:10px; color:var(--muted); margin-top:3px; opacity:0.5; }
  141. #hint.hide { display:none; }
  142. @keyframes blink { 0%,100%{opacity:.3} 50%{opacity:.7} }
  143.  
  144. .popup {
  145.   position:fixed; pointer-events:none; font-family:var(--font);
  146.   font-size:12px; font-weight:bold; color:var(--blue1); z-index:200;
  147.   animation:floatup 0.65s ease-out forwards;
  148. }
  149. @keyframes floatup { 0%{opacity:1;transform:translateY(0)} 100%{opacity:0;transform:translateY(-44px)} }
  150.  
  151. @media (hover:hover) {
  152.   * { cursor:none !important; }
  153.   #cursor { position:fixed; width:16px; height:16px; border-radius:50%; background:var(--blue3); pointer-events:none; z-index:9999; transform:translate(-50%,-50%); opacity:.85; mix-blend-mode:multiply; }
  154.   #cursor-ring { position:fixed; width:30px; height:30px; border-radius:50%; border:1.5px solid var(--blue1); pointer-events:none; z-index:9998; transform:translate(-50%,-50%); opacity:.5; }
  155. }
  156.  
  157. /* ═══ DARK MODE ═══ */
  158. body.dark {
  159.   --bg: #0b1624; --box: #0e1f38; --nav: #112244;
  160.   --border: #3a6a99; --blue1: #88ccee; --blue2: #aaddff;
  161.   --blue3: #55aadd; --muted: #7aaabb;
  162.   color: #d4ecfc;
  163.   background: var(--bg);
  164. }
  165. body.dark #hud-left,
  166. body.dark #hud-right  { background: rgba(11,22,36,0.93); }
  167. body.dark #timer-wrap { background: rgba(11,22,36,0.93); }
  168. body.dark #score      { color: var(--blue2); }
  169. body.dark #player-tab { color: var(--blue1); }
  170. #dark-toggle {
  171.   background: transparent; border: 1px solid var(--border);
  172.   color: var(--blue1); font-family: var(--font); font-size: 14px;
  173.   width: 28px; height: 26px; display: flex; align-items: center; justify-content: center;
  174.   cursor: pointer; flex-shrink: 0; touch-action: manipulation; pointer-events: all;
  175.   margin-left: auto; margin-right: 6px; transition: background 0.15s;
  176. }
  177. #dark-toggle:active { background: var(--border); }
  178. </style>
  179. </head>
  180. <body>
  181.  
  182. <canvas id="pc"></canvas>
  183. <div id="tap-zone"></div>
  184.  
  185. <div id="hud">
  186.   <div id="hud-left">
  187.     <div id="avatar-ph"></div>
  188.     <img id="avatar" src="https://verlanovich.neocities.org/my-pic.jpg" alt="verlanovich"
  189.      style="display:none"
  190.      onload="this.style.display='block';document.getElementById('avatar-ph').style.display='none';"
  191.      onerror="this.style.display='none';">
  192.     <div>
  193.       <div id="player-name">verlanovich</div>
  194.       <div id="player-tag">tap to vibe :)</div>
  195.     </div>
  196.   </div>
  197.   <div id="hud-right">
  198.     <div id="score-lbl">score</div>
  199.     <div id="score">000000</div>
  200.     <div id="combo" class="hidden">× 1</div>
  201.     <div id="streak-wrap"><div id="streak-fill"></div></div>
  202.   </div>
  203. </div>
  204.  
  205. <div id="timer-wrap">
  206.   <div id="timer-lbl">session</div>
  207.   <div id="timer">00:00</div>
  208. </div>
  209.  
  210. <div id="hint">
  211.   <div id="hint-main">tap anywhere :)</div>
  212.   <div id="hint-sub">verlanovich's anti-stress toy</div>
  213. </div>
  214.  
  215. <div id="player" class="collapsed">
  216.   <div id="player-tab"><div>♫ music player</div><button id="dark-toggle" title="toggle dark mode">🌙</button><span id="tab-arrow">▲</span></div>
  217.   <div id="player-body">
  218.     <div id="track-name">— no track loaded —</div>
  219.     <div id="player-ctrls">
  220.       <button class="pctrl" id="play-btn">▶ play</button>
  221.       <button class="pctrl" id="loop-btn">↺ loop</button>
  222.       <button class="pctrl" id="mute-btn">🔊</button>
  223.     </div>
  224.     <div class="rate-row">
  225.       <span class="rate-lbl">tempo</span>
  226.       <button class="rate-btn" id="tempo-dn">−</button>
  227.       <span class="rate-val" id="tempo-val">1.00x</span>
  228.       <button class="rate-btn" id="tempo-up">+</button>
  229.     </div>
  230.     <div class="rate-row">
  231.       <span class="rate-lbl">pitch</span>
  232.       <button class="rate-btn" id="pitch-dn">−</button>
  233.       <span class="rate-val" id="pitch-val">1.00x</span>
  234.       <button class="rate-btn" id="pitch-up">+</button>
  235.     </div>
  236.     <div id="vol-row"><span>vol</span><input type="range" id="vol-slider" min="0" max="1" step="0.05" value="0.8"></div>
  237.     <div id="seek-row">
  238.       <span class="ttime" id="cur-t">0:00</span>
  239.       <div id="seek-track"><div id="seek-done"></div></div>
  240.       <span class="ttime r" id="dur-t">0:00</span>
  241.     </div>
  242.     <canvas id="freq-canvas"></canvas>
  243.     <label id="upload-btn">+ load audio file<input type="file" id="file-in" accept="audio/*"></label>
  244.   </div>
  245. </div>
  246.  
  247. <div id="cursor"></div>
  248. <div id="cursor-ring"></div>
  249.  
  250. <script>
  251. 'use strict';
  252.  
  253. // ══════════════════════════════════════
  254. //  BLOCK BROWSER GESTURES
  255. // ══════════════════════════════════════
  256. document.addEventListener('touchmove', e => {
  257.   if (!e.target.closest('#player')) e.preventDefault();
  258. }, { passive: false });
  259. document.addEventListener('touchstart', e => {
  260.   if (e.touches.length > 1) e.preventDefault();
  261. }, { passive: false });
  262. document.addEventListener('contextmenu', e => e.preventDefault());
  263.  
  264. // ══════════════════════════════════════
  265. //  CANVAS
  266. // ══════════════════════════════════════
  267. const IS_MOB = 'ontouchstart' in window;
  268. const DPR    = IS_MOB ? 1 : Math.min(window.devicePixelRatio || 1, 2);
  269.  
  270. const canvas = document.getElementById('pc');
  271. const ctx    = canvas.getContext('2d', { alpha: true, desynchronized: true });
  272. const fCvs   = document.getElementById('freq-canvas');
  273. const fCtx   = fCvs.getContext('2d');
  274.  
  275. let IW = window.innerWidth, IH = window.innerHeight;
  276. function resize() {
  277.   IW = window.innerWidth; IH = window.innerHeight;
  278.   canvas.width  = IW * DPR | 0;
  279.   canvas.height = IH * DPR | 0;
  280.   canvas.style.width  = IW + 'px';
  281.   canvas.style.height = IH + 'px';
  282.   ctx.setTransform(1,0,0,1,0,0);
  283.   if (DPR !== 1) ctx.scale(DPR, DPR);
  284.   fCvs.width  = fCvs.offsetWidth  || 300;
  285.   fCvs.height = fCvs.offsetHeight || 22;
  286. }
  287. resize();
  288. window.addEventListener('resize', resize);
  289.  
  290. // ══════════════════════════════════════
  291. //  SESSION TIMER
  292. // ══════════════════════════════════════
  293. const sessionStart = Date.now();
  294. const timerEl = document.getElementById('timer');
  295. function updateTimer() {
  296.   const s = Math.floor((Date.now() - sessionStart) / 1000);
  297.   const h = Math.floor(s / 3600), m = Math.floor((s % 3600) / 60), sec = s % 60;
  298.   timerEl.textContent = h > 0
  299.     ? h + ':' + (m+'').padStart(2,'0') + ':' + (sec+'').padStart(2,'0')
  300.     : (m+'').padStart(2,'0') + ':' + (sec+'').padStart(2,'0');
  301.   timerEl.classList.toggle('warn', s >= 1800);
  302. }
  303. setInterval(updateTimer, 1000);
  304.  
  305. // ══════════════════════════════════════
  306. //  OBJECT POOL
  307. // ══════════════════════════════════════
  308. const POOL_SZ = 500;
  309. const pool = [];
  310. for (let i = 0; i < POOL_SZ; i++)
  311.  pool.push({ alive:false, x:0,y:0, vx:0,vy:0, r:0, life:0, decay:0, ci:0, grav:0 });
  312.  
  313. let ph = 0;
  314. const active = [];
  315.  
  316. // Light mode: slightly brighter medium blues
  317. const COLORS = ['#3377dd','#4488ee','#2266cc','#55aaee','#2277dd','#4499ee','#3388ee','#2288dd'];
  318. const COLORS_DARK = ['#c8e8ff','#88ccee','#5599cc','#aaddff','#ddf2ff','#66bbee','#4488cc','#bbddf8'];
  319. const CLEN = COLORS.length;
  320. const isDark = () => document.body.classList.contains('dark');
  321. const getColors = () => isDark() ? COLORS_DARK : COLORS;
  322.  
  323. // type: 'burst' | 'drop' | 'splash' | 'drip'
  324. function acquire(x, y, type) {
  325.   let t = POOL_SZ;
  326.   while (pool[ph].alive && --t > 0) ph = (ph + 1) % POOL_SZ;
  327.   if (!t) return null;
  328.  
  329.   const p = pool[ph];
  330.   ph = (ph + 1) % POOL_SZ;
  331.   p.alive = true;
  332.   p.x = x; p.y = y;
  333.   p.ci = Math.random() * CLEN | 0;
  334.  
  335.   if (type === 'burst') {
  336.     // Big tap explosion particle
  337.     const a = Math.random() * 6.2832;
  338.     const s = 1.4 + Math.random() * 4;
  339.     p.vx   = Math.cos(a) * s;
  340.     p.vy   = Math.sin(a) * s - 1.1;
  341.     p.r    = 2.5 + Math.random() * 3.5;
  342.     p.life = 1;
  343.     p.decay = 0.02 + Math.random() * 0.018;
  344.     p.grav  = 0.07;
  345.  
  346.   } else if (type === 'drop') {
  347.     // Water drop along drag path — falls downward with small sideways drift
  348.     p.vx   = (Math.random() - 0.5) * 1.2;
  349.     p.vy   = -0.5 - Math.random() * 1.5; // starts slightly upward then falls
  350.     p.r    = 2 + Math.random() * 2.5;
  351.     p.life = 1;
  352.     p.decay = 0.022 + Math.random() * 0.016;
  353.     p.grav  = 0.12; // heavier gravity = falls fast like water
  354.  
  355.   } else if (type === 'splash') {
  356.     // Tiny splash bursting outward at low angle, then drops
  357.     const a = Math.PI + (Math.random() - 0.5) * Math.PI; // mostly sideways
  358.     const s = 0.8 + Math.random() * 2.5;
  359.     p.vx   = Math.cos(a) * s;
  360.     p.vy   = -0.8 - Math.random() * 1.5;
  361.     p.r    = 1.2 + Math.random() * 1.8;
  362.     p.life = 1;
  363.     p.decay = 0.03 + Math.random() * 0.025;
  364.     p.grav  = 0.10;
  365.  
  366.   } else if (type === 'drip') {
  367.     // Drip: falls nearly straight down, elongated feel
  368.     p.vx   = (Math.random() - 0.5) * 0.4;
  369.     p.vy   = 0.5 + Math.random() * 1.5; // starts already falling
  370.     p.r    = 1.5 + Math.random() * 2;
  371.     p.life = 1;
  372.     p.decay = 0.025 + Math.random() * 0.018;
  373.     p.grav  = 0.14; // heaviest — drips fast
  374.   }
  375.  
  376.   active.push(p);
  377.   return p;
  378. }
  379.  
  380. // ══════════════════════════════════════
  381. //  RINGS — separate arrays, never cross-delete
  382. // ══════════════════════════════════════
  383. const tapRings    = [];
  384. const dragRipples = [];
  385.  
  386. function spawnTapRing(x, y, comboN) {
  387.   if (tapRings.length >= 8) tapRings.shift();
  388.   tapRings.push({ x, y, r:0, tr: 60 + comboN * 6, life:1 });
  389. }
  390.  
  391. // Per-pointer ripple last positions tracked in pointer map (see below)
  392. function spawnDragRipple(x, y) {
  393.   if (dragRipples.length >= 16) dragRipples.shift();
  394.   dragRipples.push({ x, y, r:0, tr:75, life:1 });
  395.   // Second inner ring for water depth
  396.   if (dragRipples.length >= 16) dragRipples.shift();
  397.   dragRipples.push({ x, y, r:6, tr:52, life:0.82 });
  398. }
  399.  
  400. // ══════════════════════════════════════
  401. //  SPAWN BURST (tap)
  402. // ══════════════════════════════════════
  403. let combo = 1;
  404.  
  405. function spawnBurst(x, y, beatBonus) {
  406.   const n = Math.min((IS_MOB ? 10 : 15) + (combo > 1 ? combo * 2 : 0) + (beatBonus ? 5 : 0), 38);
  407.   for (let i = 0; i < n; i++) acquire(x, y, 'burst');
  408.  spawnTapRing(x, y, combo);
  409. }
  410.  
  411. // ══════════════════════════════════════
  412. //  MULTI-TOUCH SLIDE — per pointer tracking
  413. //  Each finger gets its own prev position
  414. //  so two fingers never interfere with each other
  415. // ══════════════════════════════════════
  416. const pointers = new Map();
  417. // Map<pointerId, { px, py, ripX, ripY }>
  418.  
  419. function spawnSlide(pid, x, y) {
  420.   let state = pointers.get(pid);
  421.   if (!state) {
  422.     pointers.set(pid, { px: x, py: y, ripX: x - 9999, ripY: y - 9999 });
  423.     // First touch point: spawn a drop
  424.     acquire(x, y, 'drop');
  425.     return;
  426.   }
  427.  
  428.   const dx = x - state.px, dy = y - state.py;
  429.   const dist = Math.sqrt(dx*dx + dy*dy);
  430.   if (dist < 1) return;
  431.  
  432.  // Fill drops along path (smooth, no gaps)
  433.  const SPACING = IS_MOB ? 9 : 7;
  434.  const steps   = Math.min(Math.ceil(dist / SPACING), 14);
  435.  
  436.  for (let i = 1; i <= steps; i++) {
  437.    if (active.length >= 400) break;
  438.     const t = i / steps;
  439.     const px = state.px + dx * t, py = state.py + dy * t;
  440.  
  441.     // Mostly 'drop' (water droplet), occasionally 'drip' or 'splash'
  442.     const rnd = Math.random();
  443.     if (rnd < 0.65)      acquire(px, py, 'drop');
  444.    else if (rnd < 0.85) acquire(px, py, 'drip');   // sometimes a drip falls away
  445.    else                 acquire(px, py, 'splash');  // rare sideways splash
  446.  }
  447.  
  448.  // Ripple: per-pointer, every ~22px
  449.  const rdx = x - state.ripX, rdy = y - state.ripY;
  450.  if (rdx*rdx + rdy*rdy >= 484) {
  451.     spawnDragRipple(x, y);
  452.     state.ripX = x; state.ripY = y;
  453.   }
  454.  
  455.   state.px = x; state.py = y;
  456. }
  457.  
  458. function releasePointer(pid) {
  459.   pointers.delete(pid);
  460. }
  461.  
  462. // ══════════════════════════════════════
  463. //  SCORE — MAX 9,999,999 then rollover
  464. // ══════════════════════════════════════
  465. const SCORE_MAX = 9999999;
  466. let score = 0, tapCount = 0, comboTimer = null, comboDecayTimer = null;
  467. const scoreEl  = document.getElementById('score');
  468. const comboEl  = document.getElementById('combo');
  469. const streakEl = document.getElementById('streak-fill');
  470.  
  471. function startComboDecay() {
  472.   if (comboDecayTimer) clearInterval(comboDecayTimer);
  473.   comboDecayTimer = setInterval(() => {
  474.     if (tapCount <= 0 && combo <= 1) {
  475.      clearInterval(comboDecayTimer);
  476.      comboDecayTimer = null;
  477.      comboEl.classList.add('hidden');
  478.      streakEl.style.width = '0%';
  479.      return;
  480.    }
  481.    tapCount = Math.max(0, tapCount - 4);
  482.    combo = Math.max(1, Math.min((tapCount >> 2) + 1, 20));
  483.     comboEl.textContent = '× ' + combo;
  484.     streakEl.style.width = Math.min((tapCount / 35) * 100, 100) + '%';
  485.     if (combo <= 1 && tapCount <= 0) {
  486.      clearInterval(comboDecayTimer);
  487.      comboDecayTimer = null;
  488.      comboEl.classList.add('hidden');
  489.      streakEl.style.width = '0%';
  490.    }
  491.  }, 180);
  492. }
  493.  
  494. function addScore(x, y) {
  495.  score += combo;
  496.  
  497.  // ROLLOVER
  498.  if (score > SCORE_MAX) {
  499.     score = score - SCORE_MAX - 1; // reset, carry over excess
  500.     scoreEl.classList.remove('rollover');
  501.     void scoreEl.offsetWidth; // reflow to re-trigger animation
  502.     scoreEl.classList.add('rollover');
  503.     // Celebration burst from center
  504.     for (let i = 0; i < 40; i++) acquire(IW/2, IH/2, 'burst');
  505.    spawnTapRing(IW/2, IH/2, 20);
  506.    spawnPopup(IW/2, IH/2 - 40, 'MAX!! ROLLOVER!', '#cc2200');
  507.  }
  508.  
  509.  tapCount++;
  510.  scoreEl.textContent = score.toString().padStart(7, '0');
  511.  scoreEl.classList.add('pop');
  512.  requestAnimationFrame(() => scoreEl.classList.remove('pop'));
  513.  
  514.   if (comboTimer) clearTimeout(comboTimer);
  515.   if (comboDecayTimer) clearInterval(comboDecayTimer);
  516.   comboDecayTimer = null;
  517.   combo = Math.min((tapCount >> 2) + 1, 20);
  518.   comboEl.textContent = '× ' + combo;
  519.   comboEl.classList.remove('hidden');
  520.   streakEl.style.width = Math.min((tapCount / 35) * 100, 100) + '%';
  521.   comboTimer = setTimeout(() => {
  522.     startComboDecay();
  523.   }, 1400);
  524.  
  525.   spawnPopup(x, y, '+' + combo, null);
  526.   if (combo >= 5 && combo % 5 === 0)
  527.    setTimeout(() => spawnPopup(x, y - 22, 'COMBO ×' + combo + '!', '#2255aa'), 70);
  528.  
  529.   document.getElementById('hint').classList.add('hide');
  530. }
  531.  
  532. function spawnPopup(x, y, text, color) {
  533.   const el = document.createElement('div');
  534.   el.className = 'popup';
  535.   el.style.cssText = 'left:'+(x-14)+'px;top:'+(y-10)+'px'+(color?';color:'+color:'');
  536.   el.textContent = text;
  537.   document.body.appendChild(el);
  538.   setTimeout(() => el.remove(), 700);
  539. }
  540.  
  541. // ══════════════════════════════════════
  542. //  AUDIO ENGINE
  543. // ══════════════════════════════════════
  544. let audioCtx, analyser, gainNode, source, audioBuffer;
  545. let isPlaying = false, isLooping = false, isMuted = false;
  546. let startRealTime = 0, pausedAt = 0, beatEnergy = 0;
  547. let tempoVal = 1.0, pitchVal = 1.0;
  548. const fftData = new Uint8Array(64);
  549.  
  550. function initAudio() {
  551.   if (audioCtx) return;
  552.   audioCtx = new (window.AudioContext || window.webkitAudioContext)();
  553.   analyser = audioCtx.createAnalyser();
  554.   analyser.fftSize = 128;
  555.   gainNode = audioCtx.createGain();
  556.   gainNode.gain.value = +document.getElementById('vol-slider').value;
  557.   analyser.connect(gainNode);
  558.   gainNode.connect(audioCtx.destination);
  559. }
  560. function resumeCtx() { if (audioCtx && audioCtx.state === 'suspended') audioCtx.resume(); }
  561.  
  562. function playAudio() {
  563.   if (window._fallbackAudio && !audioBuffer) {
  564.    window._fallbackAudio.play().then(() => {
  565.      isPlaying = true;
  566.       document.getElementById('play-btn').textContent = '⏸ pause';
  567.     }).catch(() => {});
  568.     return;
  569.   }
  570.   if (!audioBuffer) return;
  571.   if (source) { try { source.stop(); } catch(e){} }
  572.   source = audioCtx.createBufferSource();
  573.   source.buffer = audioBuffer;
  574.   source.loop   = isLooping;
  575.   source.playbackRate.value = tempoVal;
  576.   source.detune.value       = Math.log2(pitchVal) * 1200;
  577.   source.connect(analyser);
  578.   const startPos = Math.min(pausedAt, audioBuffer.duration - 0.01);
  579.   source.start(0, startPos);
  580.   startRealTime = audioCtx.currentTime - startPos / tempoVal;
  581.   isPlaying = true;
  582.   document.getElementById('play-btn').textContent = '⏸ pause';
  583.   source.onended = () => {
  584.     if (!isLooping) {
  585.       isPlaying = false; pausedAt = 0;
  586.       document.getElementById('play-btn').textContent = '▶ play';
  587.       document.getElementById('seek-done').style.width = '0%';
  588.       document.getElementById('cur-t').textContent = '0:00';
  589.     }
  590.   };
  591. }
  592. function pauseAudio() {
  593.   if (window._fallbackAudio && !audioBuffer) {
  594.    window._fallbackAudio.pause();
  595.     isPlaying = false;
  596.     document.getElementById('play-btn').textContent = '▶ play';
  597.     return;
  598.   }
  599.   if (!isPlaying) return;
  600.   pausedAt = (audioCtx.currentTime - startRealTime) * tempoVal;
  601.   try { source.stop(); } catch(e){}
  602.   isPlaying = false;
  603.   document.getElementById('play-btn').textContent = '▶ play';
  604. }
  605. function setTempo(v) {
  606.   tempoVal = Math.max(0.25, Math.min(3.0, Math.round(v * 20) / 20));
  607.   document.getElementById('tempo-val').textContent = tempoVal.toFixed(2) + 'x';
  608.   if (source && isPlaying) {
  609.    pausedAt = (audioCtx.currentTime - startRealTime) * source.playbackRate.value;
  610.     source.playbackRate.value = tempoVal;
  611.     startRealTime = audioCtx.currentTime - pausedAt / tempoVal;
  612.   }
  613. }
  614. function setPitch(v) {
  615.   pitchVal = Math.max(0.25, Math.min(3.0, Math.round(v * 20) / 20));
  616.   document.getElementById('pitch-val').textContent = pitchVal.toFixed(2) + 'x';
  617.   if (source && isPlaying) source.detune.value = Math.log2(pitchVal) * 1200;
  618. }
  619.  
  620. function addBtn(el, fn) {
  621.   el.addEventListener('pointerdown', e => e.stopPropagation(), { passive: true });
  622.   el.addEventListener('click',    e => { e.stopPropagation(); fn(e); });
  623.   el.addEventListener('touchend', e => { e.stopPropagation(); e.preventDefault(); fn(e); }, { passive: false });
  624. }
  625.  
  626. const playBtn   = document.getElementById('play-btn');
  627. const loopBtn   = document.getElementById('loop-btn');
  628. const muteBtn   = document.getElementById('mute-btn');
  629. const volSlider = document.getElementById('vol-slider');
  630. const seekTrack = document.getElementById('seek-track');
  631. const fileIn    = document.getElementById('file-in');
  632. const playerTab = document.getElementById('player-tab');
  633.  
  634. addBtn(playBtn, () => { if (!audioBuffer) return; resumeCtx(); isPlaying ? pauseAudio() : playAudio(); });
  635. addBtn(loopBtn, () => {
  636.   isLooping = !isLooping;
  637.   if (source) source.loop = isLooping;
  638.   if (window._fallbackAudio) window._fallbackAudio.loop = isLooping;
  639.   loopBtn.classList.toggle('on', isLooping);
  640.   loopBtn.textContent = isLooping ? '↺ ON' : '↺ loop';
  641. });
  642. addBtn(muteBtn, () => {
  643.   isMuted = !isMuted;
  644.   if (gainNode) gainNode.gain.value = isMuted ? 0 : +volSlider.value;
  645.   if (window._fallbackAudio) window._fallbackAudio.volume = isMuted ? 0 : +volSlider.value;
  646.   muteBtn.textContent = isMuted ? '🔇' : '🔊';
  647. });
  648. addBtn(document.getElementById('tempo-up'), () => setTempo(tempoVal + 0.05));
  649. addBtn(document.getElementById('tempo-dn'), () => setTempo(tempoVal - 0.05));
  650. addBtn(document.getElementById('pitch-up'), () => setPitch(pitchVal + 0.05));
  651. addBtn(document.getElementById('pitch-dn'), () => setPitch(pitchVal - 0.05));
  652.  
  653. volSlider.addEventListener('pointerdown', e => e.stopPropagation(), { passive: true });
  654. volSlider.addEventListener('input', e => { e.stopPropagation(); if (gainNode && !isMuted) gainNode.gain.value = +e.target.value; if (window._fallbackAudio && !isMuted) window._fallbackAudio.volume = +e.target.value; });
  655.  
  656. seekTrack.addEventListener('pointerdown', e => e.stopPropagation(), { passive: true });
  657. seekTrack.addEventListener('click', e => {
  658.   e.stopPropagation();
  659.   if (window._fallbackAudio && !audioBuffer) {
  660.    const rect = seekTrack.getBoundingClientRect();
  661.     window._fallbackAudio.currentTime = Math.max(0, Math.min(1, (e.clientX - rect.left) / rect.width)) * window._fallbackAudio.duration;
  662.     return;
  663.   }
  664.   if (!audioBuffer) return;
  665.   const rect = seekTrack.getBoundingClientRect();
  666.   pausedAt = Math.max(0, Math.min(1, (e.clientX - rect.left) / rect.width)) * audioBuffer.duration;
  667.   isPlaying ? playAudio() : updateSeek(pausedAt);
  668. });
  669. seekTrack.addEventListener('touchend', e => {
  670.   e.stopPropagation(); e.preventDefault();
  671.   if (!audioBuffer) return;
  672.   const rect = seekTrack.getBoundingClientRect();
  673.   const t = e.changedTouches[0];
  674.   pausedAt = Math.max(0, Math.min(1, (t.clientX - rect.left) / rect.width)) * audioBuffer.duration;
  675.   isPlaying ? playAudio() : updateSeek(pausedAt);
  676. }, { passive: false });
  677.  
  678. fileIn.addEventListener('pointerdown', e => e.stopPropagation(), { passive: true });
  679. fileIn.addEventListener('change', e => {
  680.   const file = e.target.files[0]; if (!file) return;
  681.   initAudio();
  682.   const trackNameEl = document.getElementById('track-name');
  683.   const cleanName = file.name.replace(/\.[^.]+$/, '');
  684.   trackNameEl.textContent = cleanName;
  685.  
  686.   const reader = new FileReader();
  687.   reader.onload = ev => {
  688.     audioCtx.decodeAudioData(ev.target.result.slice(0), buf => {
  689.       // Sukses decode — mode penuh (tempo, pitch, visualizer)
  690.       if (window._fallbackAudio) { window._fallbackAudio.pause(); window._fallbackAudio = null; }
  691.       audioBuffer = buf; pausedAt = 0;
  692.       document.getElementById('dur-t').textContent = fmt(buf.duration);
  693.       playAudio();
  694.     }, () => {
  695.       // Gagal decode → fallback ke HTMLAudioElement
  696.       trackNameEl.textContent = cleanName + ' (compat mode)';
  697.       audioBuffer = null; pausedAt = 0;
  698.       if (window._fallbackAudio) { window._fallbackAudio.pause(); window._fallbackAudio.src = ''; }
  699.       const audio = new Audio();
  700.       window._fallbackAudio = audio;
  701.       audio.src = URL.createObjectURL(file);
  702.       audio.volume = +document.getElementById('vol-slider').value;
  703.       audio.loop = isLooping;
  704.       // Hubungkan ke analyser supaya visualizer tetap jalan
  705.       if (!window._fallbackSrc) {
  706.         window._fallbackSrc = audioCtx.createMediaElementSource(audio);
  707.         window._fallbackSrc.connect(analyser);
  708.       }
  709.       audio.addEventListener('loadedmetadata', () => {
  710.         document.getElementById('dur-t').textContent = fmt(audio.duration);
  711.       }, { once: true });
  712.       audio.addEventListener('timeupdate', () => {
  713.         document.getElementById('seek-done').style.width = (audio.currentTime / audio.duration * 100) + '%';
  714.         document.getElementById('cur-t').textContent = fmt(audio.currentTime);
  715.       });
  716.       audio.addEventListener('ended', () => {
  717.         if (!isLooping) {
  718.           isPlaying = false;
  719.           document.getElementById('play-btn').textContent = '▶ play';
  720.           document.getElementById('seek-done').style.width = '0%';
  721.           document.getElementById('cur-t').textContent = '0:00';
  722.         }
  723.       });
  724.       audio.play().then(() => {
  725.         isPlaying = true;
  726.         document.getElementById('play-btn').textContent = '⏸ pause';
  727.       }).catch(() => {});
  728.     });
  729.   };
  730.   reader.readAsArrayBuffer(file);
  731. });
  732. document.getElementById('upload-btn').addEventListener('pointerdown', e => e.stopPropagation(), { passive: true });
  733.  
  734. let playerOpen = false;
  735. addBtn(playerTab, () => {
  736.   resumeCtx();
  737.   playerOpen = !playerOpen;
  738.   document.getElementById('player').classList.toggle('collapsed', !playerOpen);
  739.   document.getElementById('tab-arrow').textContent = playerOpen ? '▼' : '▲';
  740. });
  741.  
  742. const fmt = s => Math.floor(s/60) + ':' + (Math.floor(s%60)+'').padStart(2,'0');
  743. function updateSeek(bufPos) {
  744.   if (!audioBuffer) return;
  745.   document.getElementById('seek-done').style.width = (bufPos / audioBuffer.duration * 100) + '%';
  746.   document.getElementById('cur-t').textContent = fmt(bufPos);
  747. }
  748.  
  749. // ══════════════════════════════════════
  750. //  TAP ZONE INPUT — multi-touch safe
  751. // ══════════════════════════════════════
  752. const tapZone = document.getElementById('tap-zone');
  753.  
  754. tapZone.addEventListener('pointerdown', e => {
  755.   if (e.target.closest('#player')) return;
  756.   initAudio(); resumeCtx();
  757.   spawnBurst(e.clientX, e.clientY, beatEnergy > 0.55);
  758.   addScore(e.clientX, e.clientY);
  759.   // Register pointer for slide tracking
  760.   pointers.set(e.pointerId, { px: e.clientX, py: e.clientY, ripX: e.clientX - 9999, ripY: e.clientY - 9999 });
  761.   tapZone.setPointerCapture(e.pointerId);
  762. }, { passive: true });
  763.  
  764. tapZone.addEventListener('pointermove', e => {
  765.   if (!(e.buttons & 1)) return;
  766.   if (e.target.closest('#player')) return;
  767.   // Use coalesced events for smoothest path
  768.   const pts = (e.getCoalescedEvents && e.getCoalescedEvents().length)
  769.              ? e.getCoalescedEvents() : [e];
  770.   for (const pt of pts) spawnSlide(e.pointerId, pt.clientX, pt.clientY);
  771. }, { passive: true });
  772.  
  773. tapZone.addEventListener('pointerup',     e => releasePointer(e.pointerId), { passive: true });
  774. tapZone.addEventListener('pointercancel', e => releasePointer(e.pointerId), { passive: true });
  775. tapZone.addEventListener('pointerleave',  e => releasePointer(e.pointerId), { passive: true });
  776.  
  777. document.addEventListener('mousemove', e => {
  778.   const c = document.getElementById('cursor');
  779.   const r = document.getElementById('cursor-ring');
  780.   if (c) { c.style.left = e.clientX+'px'; c.style.top = e.clientY+'px'; }
  781.   if (r) { r.style.left = e.clientX+'px'; r.style.top = e.clientY+'px'; }
  782. }, { passive: true });
  783.  
  784. // ══════════════════════════════════════
  785. //  FREQ VISUALIZER
  786. // ══════════════════════════════════════
  787. let freqTick = 0;
  788. function drawFreq() {
  789.   if (++freqTick % 2 !== 0) return;
  790.   const fw = fCvs.width, fh = fCvs.height;
  791.   fCtx.clearRect(0, 0, fw, fh);
  792.   const n = 28, bw = (fw/n*0.62)|0, gap = (fw/n*0.38)|0;
  793.   for (let i = 0; i < n; i++) {
  794.    const val = fftData[i*2] / 255, bh = (val * fh) | 0;
  795.    fCtx.fillStyle = isDark()
  796.      ? (i < 7 ? '#88ccee' : '#aaddff')
  797.      : (i < 7 ? '#2255aa' : '#5aabdd');
  798.    fCtx.fillRect(i*(bw+gap), fh-bh, bw, bh);
  799.  }
  800. }
  801.  
  802. // ══════════════════════════════════════
  803. //  MAIN LOOP
  804. // ══════════════════════════════════════
  805. const TARGET_MS = IS_MOB ? 33 : 16;
  806. let lastTime = 0, lastBeat = 0, loopTick = 0;
  807.  
  808. function drawRings(arr, isTap) {
  809.  for (let i = arr.length - 1; i >= 0; i--) {
  810.     const rg = arr[i];
  811.     rg.r    += isTap ? ((rg.tr - rg.r) * 0.14 + 2) : ((rg.tr - rg.r) * 0.08 + 1);
  812.     rg.life -= isTap ? 0.05 : 0.038;
  813.     if (rg.life <= 0) { arr.splice(i, 1); continue; }
  814.  
  815.    ctx.globalAlpha = rg.life * (isTap ? (isDark() ? 0.75 : 0.82) : (isDark() ? 0.9 : 0.88));
  816.    ctx.strokeStyle = isTap
  817.      ? (isDark() ? '#55eeff' : '#3377dd')
  818.      : (isDark() ? '#aaeeff' : '#4499ee');
  819.    ctx.lineWidth   = isTap ? 2.5 : 3.5;
  820.    ctx.beginPath();
  821.    ctx.arc(rg.x, rg.y, rg.r, 0, 6.2832);
  822.    ctx.stroke();
  823.  }
  824. }
  825.  
  826. function loop(ts) {
  827.  requestAnimationFrame(loop);
  828.  if (ts - lastTime < TARGET_MS) return;
  829.  lastTime = ts; loopTick++;
  830.  
  831.  if (analyser && isPlaying && loopTick % 2 === 0) {
  832.    analyser.getByteFrequencyData(fftData);
  833.    const bass = (fftData[0] + fftData[1] + fftData[2]) / 765;
  834.    beatEnergy = bass;
  835.    if (bass > 0.62 && ts - lastBeat > 300 && active.length < 320) {
  836.      lastBeat = ts;
  837.       const bx = Math.random() * IW, by = Math.random() * IH * 0.65;
  838.       for (let i = 0; i < 5; i++) acquire(bx+(Math.random()-.5)*30, by+(Math.random()-.5)*30, 'drop');
  839.    }
  840.    const bufPos = (audioCtx.currentTime - startRealTime) * tempoVal;
  841.    if (audioBuffer) updateSeek(Math.min(bufPos, audioBuffer.duration));
  842.    drawFreq();
  843.  }
  844.  
  845.  ctx.clearRect(0, 0, IW, IH);
  846.  
  847.  // Rings — two separate arrays, never cross-delete
  848.  drawRings(tapRings,    true);
  849.  drawRings(dragRipples, false);
  850.  
  851.  // Particles
  852.  for (let i = active.length - 1; i >= 0; i--) {
  853.     const p = active[i];
  854.     p.x    += p.vx;
  855.     p.y    += p.vy;
  856.     p.vy   += p.grav;   // each type has its own gravity
  857.     p.vx   *= 0.984;
  858.     p.life -= p.decay;
  859.  
  860.     if (p.life <= 0) { p.alive = false; active.splice(i, 1); continue; }
  861.  
  862.    ctx.globalAlpha = p.life * 0.95;
  863.    ctx.fillStyle   = getColors()[p.ci];
  864.    const r = p.r * (0.4 + p.life * 0.6);
  865.    ctx.beginPath();
  866.    ctx.arc(p.x, p.y, r, 0, 6.2832);
  867.    ctx.fill();
  868.  }
  869.  
  870.  ctx.globalAlpha = 1;
  871.  
  872.  if (active.length > 420) {
  873.     const dead = active.splice(0, active.length - 420);
  874.     for (const p of dead) p.alive = false;
  875.   }
  876. }
  877.  
  878. requestAnimationFrame(loop);
  879.  
  880. // ══════════════════════════════════════
  881. //  DARK MODE TOGGLE
  882. // ══════════════════════════════════════
  883. const darkToggle = document.getElementById('dark-toggle');
  884. addBtn(darkToggle, e => {
  885.   e.stopPropagation();
  886.   document.body.classList.toggle('dark');
  887.   darkToggle.textContent = document.body.classList.contains('dark') ? '☀️' : '🌙';
  888. });
  889. </script>
  890. </body>
  891. </html>
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment