here2share

RAINBOW Illusion - Only 3 Colors.html

Mar 16th, 2026
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.87 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>RAINBOW Illusion — Only 3 Colors</title>
  6. <style>
  7.   html, body {
  8.     margin: 0;
  9.     height: 75%;
  10.     background: #000;
  11.     overflow: hidden;
  12.   }
  13.   body {
  14.     display: flex;
  15.     flex-direction: column;
  16.     align-items: center;
  17.     justify-content: center;
  18.     font-family: "Futura Bold", system-ui, sans-serif;
  19.   }
  20.   #container {
  21.     display: flex;
  22.     justify-content: center;
  23.     align-items: center;
  24.     height: 80vh;
  25.     width: 100vw;
  26.   }
  27.   #word {
  28.     font-size: 250px;
  29.     font-weight: 900;
  30.     color: #ffffff;
  31.     display: inline-flex;
  32.   }
  33.   #word span {
  34.     display: inline-block;
  35.   }
  36.   #A + span,
  37.   #I,
  38.   #N,
  39.   #B,
  40.   #O,
  41.   #W {
  42.     margin-left: -8px;
  43.   }
  44.   #controls {
  45.     position: fixed;
  46.     bottom: 20px;
  47.   }
  48.   #toggle {
  49.     padding: 8px 18px;
  50.     font-size: 32px;
  51.     font-weight: 600;
  52.     cursor: pointer;
  53.   }
  54. </style>
  55. </head>
  56. <body>
  57. <div id="container">
  58.   <div id="word">
  59.     <span id="R">R</span>
  60.     <span id="A">A</span>
  61.     <span id="I">I</span>
  62.     <span id="N">N</span>
  63.     <span id="B">B</span>
  64.     <span id="O">O</span>
  65.     <span id="W">W</span>
  66.   </div>
  67. </div>
  68.  
  69. <div id="controls">
  70.   <button id="toggle">PAUSE</button>
  71. </div>
  72.  
  73. <script>
  74.   const R = "#ff0000";
  75.   const G = "#00ff00";
  76.   const B = "#0000ff";
  77.  
  78.   const ORANGE = [R, R, R, G, R, G];
  79.   const YELLOW = [G, G, R, G, G, R];
  80.   const INDIGO = [B, B, B, B, B, R];
  81.   const PURPLE = [B, R, B, R, B, R];
  82.  
  83.   const elR = document.getElementById("R");
  84.   const elA = document.getElementById("A");
  85.   const elI = document.getElementById("I");
  86.   const elN = document.getElementById("N");
  87.   const elB = document.getElementById("B");
  88.   const elO = document.getElementById("O");
  89.   const elW = document.getElementById("W");
  90.  
  91.   elR.style.color = R;
  92.   elN.style.color = G;
  93.   elB.style.color = B;
  94.  
  95.   let frame = 0;
  96.   let playing = true;
  97.  
  98.   const toggleBtn = document.getElementById("toggle");
  99.   toggleBtn.addEventListener("click", () => {
  100.     playing = !playing;
  101.     toggleBtn.textContent = playing ? "PAUSE" : "PLAY";
  102.  
  103.     // restore defaults immediately when paused
  104.     if (!playing) {
  105.       elR.style.color = R;
  106.       elN.style.color = G;
  107.       elB.style.color = B;
  108.       elW.style.color = PURPLE[frame % 6];
  109.  
  110.     }
  111.   });
  112.  
  113.   function animate() {
  114.     if (playing) {
  115.       const f = frame % 6;
  116.  
  117.       elA.style.color = ORANGE[f];
  118.       elI.style.color = YELLOW[f];
  119.       elO.style.color = INDIGO[f];
  120.       elW.style.color = PURPLE[f];
  121.  
  122.       const flicker = (frame % 15 === 0);
  123.       elR.style.color = flicker ? "#000000" : R;
  124.       elN.style.color = flicker ? "#000000" : G;
  125.       elB.style.color = flicker ? "#000000" : B;
  126.       elW.style.color = flicker ? "#000000" : W;
  127.  
  128.       frame++;
  129.     }
  130.  
  131.     requestAnimationFrame(animate);
  132.   }
  133.  
  134.   animate();
  135. </script>
  136. </body>
  137. </html>
Advertisement
Add Comment
Please, Sign In to add comment