Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>RAINBOW Illusion — Only 3 Colors</title>
- <style>
- html, body {
- margin: 0;
- height: 75%;
- background: #000;
- overflow: hidden;
- }
- body {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- font-family: "Futura Bold", system-ui, sans-serif;
- }
- #container {
- display: flex;
- justify-content: center;
- align-items: center;
- height: 80vh;
- width: 100vw;
- }
- #word {
- font-size: 250px;
- font-weight: 900;
- color: #ffffff;
- display: inline-flex;
- }
- #word span {
- display: inline-block;
- }
- #A + span,
- #I,
- #N,
- #B,
- #O,
- #W {
- margin-left: -8px;
- }
- #controls {
- position: fixed;
- bottom: 20px;
- }
- #toggle {
- padding: 8px 18px;
- font-size: 32px;
- font-weight: 600;
- cursor: pointer;
- }
- </style>
- </head>
- <body>
- <div id="container">
- <div id="word">
- <span id="R">R</span>
- <span id="A">A</span>
- <span id="I">I</span>
- <span id="N">N</span>
- <span id="B">B</span>
- <span id="O">O</span>
- <span id="W">W</span>
- </div>
- </div>
- <div id="controls">
- <button id="toggle">PAUSE</button>
- </div>
- <script>
- const R = "#ff0000";
- const G = "#00ff00";
- const B = "#0000ff";
- const ORANGE = [R, R, R, G, R, G];
- const YELLOW = [G, G, R, G, G, R];
- const INDIGO = [B, B, B, B, B, R];
- const PURPLE = [B, R, B, R, B, R];
- const elR = document.getElementById("R");
- const elA = document.getElementById("A");
- const elI = document.getElementById("I");
- const elN = document.getElementById("N");
- const elB = document.getElementById("B");
- const elO = document.getElementById("O");
- const elW = document.getElementById("W");
- elR.style.color = R;
- elN.style.color = G;
- elB.style.color = B;
- let frame = 0;
- let playing = true;
- const toggleBtn = document.getElementById("toggle");
- toggleBtn.addEventListener("click", () => {
- playing = !playing;
- toggleBtn.textContent = playing ? "PAUSE" : "PLAY";
- // restore defaults immediately when paused
- if (!playing) {
- elR.style.color = R;
- elN.style.color = G;
- elB.style.color = B;
- elW.style.color = PURPLE[frame % 6];
- }
- });
- function animate() {
- if (playing) {
- const f = frame % 6;
- elA.style.color = ORANGE[f];
- elI.style.color = YELLOW[f];
- elO.style.color = INDIGO[f];
- elW.style.color = PURPLE[f];
- const flicker = (frame % 15 === 0);
- elR.style.color = flicker ? "#000000" : R;
- elN.style.color = flicker ? "#000000" : G;
- elB.style.color = flicker ? "#000000" : B;
- elW.style.color = flicker ? "#000000" : W;
- frame++;
- }
- requestAnimationFrame(animate);
- }
- animate();
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment