Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- <script>
- document.addEventListener('DOMContentLoaded', function(){
- const canvas = document.getElementById("canvasId");
- const context = canvas.getContext("2d");
- context.fillStyle = 'green';
- // context.fillRect(60, 0, 60, 60);
- // context.fillRect(130, 0, 70, 70);
- // context.fillRect(210, 0, 80, 80);
- // context.fillRect(300, 0, 90, 90);
- let w = 50;
- let x = 0;
- for (let index = 0; index < 5; index++) {
- context.fillRect(x, 0, w, w);
- w += 10;
- x += w;
- }
- w = 50;
- x = canvas.width - w;
- let y = canvas.height - w;
- for (let index = 0; index < 5; index++) {
- context.fillRect(x, y, w, w);
- w += 10;
- y -= 10;
- x = x - w - 10;
- }
- w = 50;
- x = canvas.width - w;
- y = 0;
- for (let index = 0; index < 5; index++) {
- context.fillRect(x, y, w, w);
- x -= 10;
- w += 10;
- y += w;
- }
- w = 50;
- x = 0;
- y = canvas.height - w;
- for (let index = 0; index < 5; index++) {
- context.fillRect(x, y, w, w);
- w += 10;
- y = y - w - 10;
- }
- cx = canvas.width/2;
- cy = canvas.height/2;
- let r = 100;
- color = 'red';
- for (let index = 0; index < 5; index++) {
- context.beginPath();
- context.fillStyle = (index%2 == 0 ? 'green': 'red');
- // context.fillStyle = (color == 'green' ? (color = 'red') : (color = 'green'));
- context.arc(cx, cy, r, 0, Math.PI*2);
- context.fill();
- context.closePath();
- r -= 20;
- }
- });
- </script>
- <style>
- #canvasId{
- background:black;
- }
- </style>
- </head>
- <body>
- <canvas id="canvasId" width="800" height="600"></canvas>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement