Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.37 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3.  
  4. <head>
  5.     <meta charset="UTF-8">
  6.     <title>Colorwave</title>
  7.     <link rel="stylesheet" href="style.css">
  8.     <style>
  9.         * {
  10.             margin: 0;
  11.         }
  12.  
  13.         canvas {
  14.             position: fixed;
  15.             top: 50%;
  16.             left: 50%;
  17.             transform: translate(-50%, -50%);
  18.             box-shadow: 0 0 0 2px yellow;
  19.             background-color: #323232;
  20.         }
  21.  
  22.         body {
  23.             background-color: #969696;
  24.             height: 100vh;
  25.         }
  26.     </style>
  27. </head>
  28.  
  29. <body>
  30.     <canvas id="canvas" width="800" height="600"></canvas>
  31.     <script src="script.js">
  32.         var canvas = document.getElementById('canvas');
  33.         var ctx = canvas.getContext('2d');
  34.  
  35.         function randomColor() {
  36.             var deg = Math.random() * 360;
  37.             return `hsl(${deg}, 60%, 50%)`;
  38.         }
  39.  
  40.         var xPos = 0;
  41.         var yPos = -50;
  42.  
  43.         function drawSquare() {
  44.             if (yPos > 600) {
  45.                 xPos += 50;
  46.                 yPos = -50;
  47.             }
  48.  
  49.             if (yPos == -50)
  50.                 ctx.fillStyle = randomColor();
  51.  
  52.             ctx.fillRect(xPos, yPos, 50, 50);
  53.             yPos += 20;
  54.  
  55.             window.requestAnimationFrame(drawSquare);
  56.         }
  57.         window.requestAnimationFrame(drawSquare);
  58.     </script>
  59. </body>
  60.  
  61. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement