Advertisement
avr39ripe

jsGrid

May 13th, 2021
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html lang="en" id="html">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <title>CANVAS</title>
  6.     <style>
  7.         html,
  8.         body {
  9.             display: flex;
  10.             align-items: center;
  11.             justify-content: center;
  12.         }
  13.  
  14.         .container {
  15.             display: flex;
  16.             flex-direction: row;
  17.             justify-content: center;
  18.             align-content: center;
  19.             align-items: center;
  20.             margin-top: 30px;
  21.             position: relative;
  22.         }
  23.  
  24.         canvas {
  25.             margin: 10px;
  26.             border: 1px solid black;
  27.             /*background-image: url('grid.png');*/
  28.         }
  29.     </style>
  30. </head>
  31. <body>
  32.     <div id="container" class="container">
  33.         <canvas id="canvas" width="650" height="450">Please update your browser!</canvas>
  34.     </div>
  35.     <script>
  36.         'use strict'
  37.  
  38.         {
  39.             const canvas = document.getElementById('canvas');
  40.             canvas.width = 650;
  41.             canvas.height = 450;
  42.             const ctx = canvas.getContext('2d');
  43.  
  44.             ctx.beginPath();
  45.             ctx.strokeStyle = "black";
  46.             ctx.lineWidth = 1;
  47.  
  48.             ctx.font = "40px serif";
  49.             ctx.textAlign = "center";
  50.             ctx.strokeText("Test text on canvas", 200, 200);
  51.  
  52.             for (let y = 0; y < canvas.height; y += 50) {
  53.                 for (let x = 0; x < canvas.width; x += 50) {
  54.                     ctx.beginPath();
  55.                     //ctx.lineWidth = 1;
  56.                     ctx.moveTo(x, y)
  57.                     ctx.lineTo(x, canvas.height);
  58.                     ctx.stroke();
  59.                 }
  60.  
  61.                 ctx.beginPath();
  62.                 //ctx.lineWidth = 1;
  63.                 ctx.moveTo(0, y)
  64.                 ctx.lineTo(canvas.width, y);
  65.                 ctx.stroke();
  66.             }
  67.         }
  68.     </script>
  69. </body>
  70. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement