lemansky

Untitled

Dec 13th, 2021 (edited)
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.61 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <title>Document</title>
  6.     <script type="text/javascript">
  7.     document.addEventListener("DOMContentLoaded", function(){
  8.         let canvas = document.getElementById('canvasId');
  9.         let context = canvas.getContext("2d");  
  10.         let mouse;
  11.         let cubes = [];
  12.         let activeColor = 'red';
  13.  
  14.        
  15.         for (let i = 1; i <= 5; i++) {
  16.            let newCube = new ColorCube(canvas.width - 50*i - 10*i, canvas.height - 50, 50, 50);
  17.            context.beginPath();
  18.            context.fillStyle = newCube.color;
  19.            context.rect(newCube.x, newCube.y, newCube.width, newCube.height);
  20.            context.fill();
  21.            context.closePath();
  22.            cubes.push(newCube);
  23.        }
  24.        console.log(cubes);
  25.        
  26.    });
  27.  
  28.    const mousePlayer1 = (e) => {
  29.       return {
  30.         x: e.layerX,
  31.         y: e.layerY,
  32.       }
  33.     }
  34.  
  35.     const colorPicker = () => {
  36.         let color = '#';
  37.         let hex = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'];
  38.         for (let i = 0; i < 6; i++) {
  39.             color = color + hex[Math.floor(Math.random()*16)];
  40.         }
  41.  
  42.         return color;
  43.     }
  44.    class ColorCube{
  45.        constructor(x, y, width, height){
  46.            this.x = x;
  47.            this.y = y;
  48.            this.width = width;
  49.            this.height = height;
  50.            this.color = colorPicker();
  51.        }
  52.    }
  53.    
  54. </script>
  55. <style>
  56.     canvas{
  57.         background-color: black;
  58.     }
  59. </style>
  60. </head>
  61. <body>
  62.   <canvas width="800" height="800" id="canvasId"></canvas>
  63. </body>
  64. </html>
Add Comment
Please, Sign In to add comment