Advertisement
lemansky

Untitled

May 4th, 2022
901
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.20 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6.     <title>Document</title>
  7.     <script>
  8.         document.addEventListener('DOMContentLoaded', function(){
  9.             const canvas = document.getElementById("canvasId");
  10.             const context = canvas.getContext("2d");
  11.  
  12.             context.fillStyle = 'green';
  13.             // context.fillRect(0, 0, 50, 50);
  14.             // context.fillRect(60, 0, 60, 60);
  15.             // context.fillRect(130, 0, 70, 70);
  16.             // context.fillRect(210, 0, 80, 80);
  17.             // context.fillRect(300, 0, 90, 90);
  18.  
  19.             let x = 0, y = 0, w = 50, h = 50;
  20.             for(let i = 0; i < 5; i++){
  21.                context.fillRect(x, y, w, h);
  22.                w = h = w + 10;
  23.                x = x + w;
  24.            }
  25.  
  26.            y = 0, w = 50, h = 50, x = canvas.width - w;
  27.            for(let i = 0; i < 5; i++){
  28.                context.fillRect(x, y, w, h);
  29.                x = x - 10;
  30.                w = h = w + 10;
  31.                y = y + h
  32.            }
  33.            
  34.            w = 50, h = 50, x = canvas.width - w, y = canvas.height - h;
  35.            for(let i = 0; i < 5; i++){
  36.                context.fillRect(x, y, w, h);
  37.                w = h = w + 10;
  38.                y = y - 10;
  39.                x = x - w - 10;
  40.            }
  41.  
  42.            x = 0, w = 50, h = 50, y = canvas.height - h;
  43.            for(let i = 0; i < 5; i++){
  44.                context.fillRect(x, y, w, h);
  45.                w = h = h + 10;
  46.                y = y - h - 10;
  47.            }
  48.  
  49.            x = canvas.width/2, y = canvas.height/2, r = 100;
  50.            for(let i = 0; i < 5; i++){
  51.  
  52.                context.beginPath();
  53.                context.arc(x, y, r, 0, Math.PI*2);
  54.                context.fill();
  55.                context.closePath();
  56.                r = r - 20;
  57.                context.fillStyle = context.fillStyle == '#008000' ? '#FF0000' : '#008000';
  58.                console.log(context.fillStyle);
  59.            }
  60.            
  61.         });
  62.     </script>
  63.     <style>
  64.         #canvasId{
  65.             background:black;
  66.         }
  67.     </style>
  68. </head>
  69. <body>
  70.     <canvas id="canvasId" width="800" height="600"></canvas>
  71. </body>
  72. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement