Advertisement
lemansky

Untitled

Apr 21st, 2021
588
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.30 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(60, 0, 60, 60);
  14.             // context.fillRect(130, 0, 70, 70);
  15.             // context.fillRect(210, 0, 80, 80);
  16.             // context.fillRect(300, 0, 90, 90);
  17.  
  18.             let w = 50;
  19.             let x = 0;
  20.             for (let index = 0; index < 5; index++) {
  21.                context.fillRect(x, 0, w, w);
  22.                w += 10;
  23.                x += w;
  24.            }
  25.  
  26.            w = 50;
  27.            x = canvas.width - w;
  28.            let y = canvas.height - w;
  29.            for (let index = 0; index < 5; index++) {
  30.                context.fillRect(x, y, w, w);
  31.                w += 10;
  32.                y -= 10;
  33.                x = x - w - 10;
  34.            }
  35.  
  36.            w = 50;
  37.            x = canvas.width - w;
  38.            y = 0;
  39.            for (let index = 0; index < 5; index++) {
  40.                context.fillRect(x, y, w, w);
  41.                x -= 10;
  42.                w += 10;
  43.                y += w;
  44.            }
  45.  
  46.            w = 50;
  47.            x = 0;
  48.            y = canvas.height - w;
  49.            for (let index = 0; index < 5; index++) {
  50.                context.fillRect(x, y, w, w);
  51.                w += 10;
  52.                y = y - w - 10;
  53.            }
  54.  
  55.            cx = canvas.width/2;
  56.            cy = canvas.height/2;
  57.            let r = 100;
  58.            color = 'red';
  59.            for (let index = 0; index < 5; index++) {
  60.                context.beginPath();
  61.                context.fillStyle = (index%2 == 0 ? 'green': 'red');
  62.                // context.fillStyle = (color == 'green' ? (color = 'red') : (color = 'green'));
  63.                context.arc(cx, cy, r, 0, Math.PI*2);
  64.                context.fill();
  65.                context.closePath();
  66.                r -= 20;
  67.            }
  68.  
  69.         });
  70.     </script>
  71.     <style>
  72.         #canvasId{
  73.             background:black;
  74.         }
  75.     </style>
  76. </head>
  77. <body>
  78.     <canvas id="canvasId" width="800" height="600"></canvas>
  79. </body>
  80. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement