Advertisement
lemansky

Untitled

Dec 13th, 2020
648
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.06 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 canvasId = canvas.getContext("2d");  
  10.         let x = 400, y = 50, r = 20;
  11.  
  12.         canvasId.beginPath();
  13.         canvasId.fillStyle = 'red';
  14.         canvasId.arc(x, y, r, 0, Math.PI*2);
  15.         canvasId.fill();
  16.         canvasId.closePath();
  17.  
  18.         for (let i = 1; i <= 5; i++) {
  19.            canvasId.beginPath();
  20.            canvasId.fillStyle = 'white';
  21.            x += 50; // 400 + 1*50 -> 450 : 450 + 2*50 -> 550 : 550 + 3*50 -> 700 // 450, 500, 550, 600
  22.             y += 50;
  23.             canvasId.arc(x, y, r, 0, Math.PI*2);
  24.             canvasId.fill();
  25.             canvasId.closePath();
  26.         } // посока надолу и надясно
  27.  
  28.         for (let i = 1; i <= 5; i++) {
  29.            canvasId.beginPath();
  30.            canvasId.fillStyle = 'white';
  31.            x -= 50;
  32.            y += 50;
  33.            canvasId.arc(x, y, r, 0, Math.PI*2);
  34.            canvasId.fill();
  35.            canvasId.closePath();
  36.        } // посока надолу и наляво
  37.        
  38.        for (let i = 1; i <= 5; i++) {
  39.            canvasId.beginPath();
  40.            canvasId.fillStyle = 'white';
  41.            x -= 50;
  42.            y -= 50;
  43.            canvasId.arc(x, y, r, 0, Math.PI*2);
  44.            canvasId.fill();
  45.            canvasId.closePath();
  46.        } // нагоре и наляво
  47.  
  48.        for (let i = 1; i <= 4; i++) {
  49.            canvasId.beginPath();
  50.            canvasId.fillStyle = 'white';
  51.            x += 50;
  52.            y -= 50;
  53.            canvasId.arc(x, y, r, 0, Math.PI*2);
  54.            canvasId.fill();
  55.            canvasId.closePath();
  56.        } // нагоре и надясно
  57.  
  58.    });
  59.  
  60. </script>
  61. <style>
  62.     canvas{
  63.         background-color: black;
  64.     }
  65. </style>
  66. </head>
  67. <body>
  68.   <canvas width="800" height="800" id="canvasId"></canvas>
  69. </body>
  70. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement