Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Document</title>
- <script type="text/javascript">
- document.addEventListener("DOMContentLoaded", function(){
- let canvas = document.getElementById('canvasId');
- let canvasId = canvas.getContext("2d");
- let x = 400, y = 50, r = 20;
- canvasId.beginPath();
- canvasId.fillStyle = 'red';
- canvasId.arc(x, y, r, 0, Math.PI*2);
- canvasId.fill();
- canvasId.closePath();
- for (let i = 1; i <= 5; i++) {
- canvasId.beginPath();
- canvasId.fillStyle = 'white';
- x += 50; // 400 + 1*50 -> 450 : 450 + 2*50 -> 550 : 550 + 3*50 -> 700 // 450, 500, 550, 600
- y += 50;
- canvasId.arc(x, y, r, 0, Math.PI*2);
- canvasId.fill();
- canvasId.closePath();
- } // посока надолу и надясно
- for (let i = 1; i <= 5; i++) {
- canvasId.beginPath();
- canvasId.fillStyle = 'white';
- x -= 50;
- y += 50;
- canvasId.arc(x, y, r, 0, Math.PI*2);
- canvasId.fill();
- canvasId.closePath();
- } // посока надолу и наляво
- for (let i = 1; i <= 5; i++) {
- canvasId.beginPath();
- canvasId.fillStyle = 'white';
- x -= 50;
- y -= 50;
- canvasId.arc(x, y, r, 0, Math.PI*2);
- canvasId.fill();
- canvasId.closePath();
- } // нагоре и наляво
- for (let i = 1; i <= 4; i++) {
- canvasId.beginPath();
- canvasId.fillStyle = 'white';
- x += 50;
- y -= 50;
- canvasId.arc(x, y, r, 0, Math.PI*2);
- canvasId.fill();
- canvasId.closePath();
- } // нагоре и надясно
- });
- </script>
- <style>
- canvas{
- background-color: black;
- }
- </style>
- </head>
- <body>
- <canvas width="800" height="800" id="canvasId"></canvas>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement