Advertisement
avr39ripe

jsGrid

May 9th, 2021
167
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>GalleryClass</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.         }
  22.         canvas {
  23.             margin: 10px;
  24.             border: 1px solid black;
  25.         }
  26.     </style>
  27. </head>
  28. <body>
  29.     <div id="container" class="container">
  30.         <canvas id="canvas" width="650" height="450">Please update your browser!</canvas>
  31.     </div>
  32.     <script>
  33.         'use strict'
  34.  
  35.         {
  36.             const canvas = document.getElementById('canvas');
  37.  
  38.             const ctx = canvas.getContext('2d');
  39.  
  40.             console.log(canvas.height);
  41.             console.log(canvas.width);
  42.             ctx.font = "10px serif";
  43.  
  44.             for (let y = 0; y < canvas.height; y += 50) {
  45.                 for (let x = 0; x < canvas.width; x += 50) {
  46.  
  47.                     ctx.textAlign = 'left';
  48.                     ctx.fillText(x, x - 18, 10);
  49.  
  50.                     ctx.beginPath();
  51.                     //ctx.lineWidth = 1;
  52.                     ctx.moveTo(x, y)
  53.                     ctx.lineTo(x, canvas.height);
  54.                     ctx.stroke();
  55.                 }
  56.  
  57.                 if (y > 0) {
  58.                     ctx.font = "10px serif";
  59.                     ctx.textAlign = 'right';
  60.                     ctx.fillText(y, 18, y + 10);
  61.                 }
  62.                
  63.  
  64.                 ctx.beginPath();
  65.                 //ctx.lineWidth = 1;
  66.                 ctx.moveTo(0, y)
  67.                 ctx.lineTo(canvas.width, y);
  68.                 ctx.stroke();
  69.             }
  70.  
  71.  
  72.             let dataURL = canvas.toDataURL("image/png");
  73.             let newTab = window.open('about:blank', 'image from canvas');
  74.             newTab.document.write("<img src='" + dataURL + "' alt='from canvas'/>");
  75.  
  76.             //ctx.beginPath();
  77.             //ctx.strokeStyle='red'
  78.             //ctx.lineWidth = 4;
  79.             //ctx.moveTo(50, 50)
  80.             //ctx.lineTo(100, 100);
  81.             //ctx.stroke();
  82.  
  83.         }
  84.     </script>
  85. </body>
  86. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement