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 canvasId = canvas.getContext("2d");
- canvasId.fillStyle = 'green';
- // canvasId.fillRect(0, 0, 50, 50);
- // canvasId.fillRect(60, 0, 50, 50);
- // canvasId.fillRect(120, 0, 50, 50);
- // canvasId.fillRect(180, 0, 50, 50);
- // canvasId.fillRect(240, 0, 50, 50);
- // for (let i = 0; i < 5; i++) {
- // canvasId.fillRect(i*60, 0, 50, 50);
- // }
- // for (let i = 0; i < 5; i++) {
- // canvasId.fillRect(750, i*60, 50, 50);
- // }
- // for (let i = 0; i < 5; i++) {
- // canvasId.fillRect(0, 550 - (i * 60), 50, 50);
- // console.log("y = " + (550 - (i * 60)));
- // }
- // for (let i = 0; i < 5; i++) {
- // canvasId.fillRect(750 - (i*60), 550, 50, 50);
- // }
- // 0 - 50 60 - 120 130 - 200 210 - 290 300 - 390
- // w=50 w=60 w= 70 w=80 w=90
- let w = 50, h = 50;
- let startW = 0;
- for (let i = 0; i < 5; i++) {
- canvasId.fillRect(startW, 0, w, h);
- w = w + 10;
- h = h + 10;
- startW = startW + w;
- }
- w = 50, h = 50;
- startW = 750;
- let startH = 0;
- for (let i = 0; i < 5; i++) {
- canvasId.fillRect(startW - i*10, startH, w, h);
- w = w + 10;
- h = h + 10;
- startH = startH + h;
- }
- startH = 550, w = 50, h = 50;
- for (let i = 0; i < 5; i++) {
- canvasId.fillRect(0, startH, w, h);
- w = w + 10;
- h = h + 10;
- startH = startH - h - 10;
- }
- startW = 750, startH = 550, w = 50, h = 50;
- for (let i = 0; i < 5; i++) {
- canvasId.fillRect(startW, startH, w, h);
- w = w + 10;
- h = h + 10;
- startH = startH - 10;
- startW = startW - w - 10;
- }
- // canvasId.moveTo(400-25, 300-25);
- // canvasId.lineTo(400-25, 350-25);
- // canvasId.stroke();
- // canvasId.moveTo(400-25, 350-25);
- // canvasId.lineTo(450-25, 350-25);
- // canvasId.stroke();
- // canvasId.moveTo(450-25, 350-25);
- // canvasId.lineTo(450-25, 300-25);
- // canvasId.stroke();
- // canvasId.moveTo(450-25, 300-25);
- // canvasId.lineTo(400-25, 300-25);
- // canvasId.stroke();
- canvasId.strokeStyle = 'green';
- canvasId.beginPath();
- canvasId.arc(400, 300, 50, 0, Math.PI*2);
- canvasId.fill();
- canvasId.stroke();
- canvasId.closePath();
- canvasId.strokeStyle = 'red';
- canvasId.beginPath();
- canvasId.moveTo(0, 0);
- canvasId.lineTo(800, 600);
- canvasId.stroke();
- canvasId.moveTo(0, 600);
- canvasId.lineTo(800, 0);
- canvasId.stroke();
- canvasId.closePath();
- // 750, 550 / 50
- // 680, 540 / 60
- // 680 + 60 + 10 = 750
- //550 490 430 370 310
- // от долен ляв ъгъл нагоре по вертикала 5 квадрата с 50/50 размери и 10px разстояние между тях
- // canvasId.fillRect(100, 0, 300, 150);
- // canvasId.fillRect(750, 0, 50, 50);
- // canvasId.fillRect(750, 550, 50, 50);
- // canvasId.fillRect(0, 550, 50, 50);
- // let w = 800, h = 600, kw = 100, kh = 50;
- // canvasId.fillRect(w/2 - kw/2, h/2 - kh/2 , kw, kh);
- // ot centyra na kanvas izvajdame polovinata ot shirochinata po x i polovinata ot visochinata po y
- });
- </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