Advertisement
lemansky

Untitled

Nov 27th, 2020
869
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 4.47 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 canvasId = canvas.getContext("2d");
  11.  
  12.             canvasId.fillStyle = 'green';
  13.             // canvasId.fillRect(0, 0, 50, 50);
  14.  
  15.             // canvasId.fillRect(60, 0, 50, 50);
  16.  
  17.             // canvasId.fillRect(120, 0, 50, 50);
  18.  
  19.             // canvasId.fillRect(180, 0, 50, 50);
  20.  
  21.             // canvasId.fillRect(240, 0, 50, 50);
  22.  
  23.             // for (let i = 0; i < 5; i++) {
  24.            //     canvasId.fillRect(i*60, 0, 50, 50);
  25.            // }
  26.  
  27.            // for (let i = 0; i < 5; i++) {
  28.            //     canvasId.fillRect(750, i*60, 50, 50);
  29.            // }
  30.  
  31.            // for (let i = 0; i < 5; i++) {
  32.            //     canvasId.fillRect(0, 550 - (i * 60), 50, 50);
  33.            //     console.log("y = " + (550 - (i * 60)));
  34.            // }
  35.  
  36.            // for (let i = 0; i < 5; i++) {
  37.            //     canvasId.fillRect(750 - (i*60), 550, 50, 50);  
  38.            // }
  39.            
  40.            // 0 - 50 60 - 120 130 - 200 210 - 290 300 - 390
  41.            // w=50   w=60       w= 70     w=80     w=90
  42.            let w = 50, h = 50;
  43.            let startW = 0;
  44.            for (let i = 0; i < 5; i++) {
  45.                canvasId.fillRect(startW, 0, w, h);
  46.                w = w + 10;
  47.                h = h + 10;
  48.                startW = startW + w;
  49.            }
  50.  
  51.            w = 50, h = 50;
  52.            startW = 750;
  53.            let startH = 0;
  54.            for (let i = 0; i < 5; i++) {
  55.                canvasId.fillRect(startW - i*10, startH, w, h);
  56.                w = w + 10;
  57.                h = h + 10;
  58.                startH = startH + h;
  59.            }
  60.  
  61.  
  62.            startH = 550, w = 50, h = 50;
  63.            for (let i = 0; i < 5; i++) {
  64.                canvasId.fillRect(0, startH, w, h);
  65.                w = w + 10;
  66.                h = h + 10;
  67.                startH = startH - h - 10;
  68.            }
  69.  
  70.            startW = 750, startH = 550, w = 50, h = 50;
  71.            for (let i = 0; i < 5; i++) {
  72.                canvasId.fillRect(startW, startH, w, h);
  73.                w = w + 10;
  74.                h = h + 10;
  75.                startH = startH - 10;
  76.                startW = startW - w - 10;
  77.            }
  78.  
  79.            
  80.            // canvasId.moveTo(400-25, 300-25);
  81.            // canvasId.lineTo(400-25, 350-25);
  82.            // canvasId.stroke();
  83.  
  84.            // canvasId.moveTo(400-25, 350-25);
  85.            // canvasId.lineTo(450-25, 350-25);
  86.            // canvasId.stroke();
  87.  
  88.            // canvasId.moveTo(450-25, 350-25);
  89.            // canvasId.lineTo(450-25, 300-25);
  90.            // canvasId.stroke();
  91.  
  92.            // canvasId.moveTo(450-25, 300-25);
  93.            // canvasId.lineTo(400-25, 300-25);
  94.            // canvasId.stroke();
  95.  
  96.            canvasId.strokeStyle = 'green';
  97.            canvasId.beginPath();
  98.            canvasId.arc(400, 300, 50, 0, Math.PI*2);
  99.            canvasId.fill();
  100.            canvasId.stroke();
  101.            canvasId.closePath();
  102.  
  103.  
  104.            canvasId.strokeStyle = 'red';
  105.            canvasId.beginPath();
  106.            canvasId.moveTo(0, 0);
  107.            canvasId.lineTo(800, 600);
  108.            canvasId.stroke();
  109.            canvasId.moveTo(0, 600);
  110.            canvasId.lineTo(800, 0);
  111.            canvasId.stroke();
  112.            canvasId.closePath();
  113.  
  114.          
  115.  
  116.  
  117.  
  118.  
  119.            // 750, 550 / 50
  120.            // 680, 540 / 60
  121.            // 680 + 60 + 10 = 750
  122.  
  123.            //550 490 430 370 310
  124.            // от долен ляв ъгъл нагоре по вертикала 5 квадрата с 50/50 размери и 10px разстояние между тях
  125.  
  126.            // canvasId.fillRect(100, 0, 300, 150);
  127.            // canvasId.fillRect(750, 0, 50, 50);
  128.            // canvasId.fillRect(750, 550, 50, 50);
  129.            // canvasId.fillRect(0, 550, 50, 50);
  130.            // let w = 800, h = 600, kw = 100,  kh = 50;
  131.            // canvasId.fillRect(w/2 - kw/2, h/2 - kh/2 , kw, kh);
  132.            // ot centyra na kanvas izvajdame polovinata ot shirochinata po x i polovinata ot visochinata po y
  133.  
  134.  
  135.         });
  136.     </script>
  137.     <style>
  138.         #canvasId{
  139.             background:black;
  140.         }
  141.     </style>
  142. </head>
  143. <body>
  144.     <canvas id="canvasId" width="800" height="600"></canvas>
  145. </body>
  146. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement