Advertisement
avr39ripe

jsCanvasDrill

May 13th, 2021
151
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.         function drawQuadraticCurve(ctx, bX, bY, eX, eY, cpX, cpY) {
  40.             ctx.beginPath();
  41.             ctx.strokeStyle = 'blue';
  42.             ctx.moveTo(bX, bY);
  43.             ctx.lineTo(cpX, cpY);
  44.             ctx.lineTo(eX, eY);
  45.             ctx.stroke();
  46.  
  47.             ctx.beginPath();
  48.             ctx.strokeStyle = 'red';
  49.             ctx.lineWidth = 2;
  50.             ctx.moveTo(bX, bY);
  51.             ctx.quadraticCurveTo(cpX, cpY, eX, eY);
  52.             ctx.stroke();
  53.         }
  54.  
  55.         function drawBezierCurve(ctx, bX, bY, eX, eY, cpAX, cpAY, cpBX, cpBY) {
  56.             ctx.beginPath();
  57.             ctx.strokeStyle = 'blue';
  58.             ctx.moveTo(bX, bY);
  59.             ctx.lineTo(cpAX, cpAY);
  60.             ctx.moveTo(cpBX, cpBY)
  61.             ctx.lineTo(eX, eY);
  62.             ctx.stroke();
  63.  
  64.             ctx.beginPath();
  65.             ctx.strokeStyle = 'red';
  66.             ctx.lineWidth = 2;
  67.             ctx.moveTo(bX, bY);
  68.             ctx.bezierCurveTo(cpAX, cpAY, cpBX, cpBY, eX, eY);
  69.             ctx.stroke();
  70.         }
  71.  
  72.         {
  73.             const canvas = document.getElementById('canvas');
  74.             canvas.width = 650;
  75.             canvas.height = 450;
  76.             const ctx = canvas.getContext('2d');
  77.  
  78.             //let cX = canvas.width / 2;
  79.             //let cY = canvas.height / 2;
  80.  
  81.             //let radius = 200;
  82.  
  83.             //let degreeB = 45;
  84.  
  85.             //let radiansB = (Math.PI / 180) * degreeB;
  86.  
  87.             //let degreeE = 90 + 45;
  88.  
  89.             //let radiansE = (Math.PI / 180) * degreeE;
  90.  
  91.             //ctx.arc(cX, cY, radius, radiansB, radiansE);
  92.  
  93.             //ctx.lineWidth = 2;
  94.             //ctx.strokeStyle = 'red';
  95.             //ctx.fillStyle = 'blue';
  96.             //ctx.stroke();
  97.             ////ctx.fill();
  98.  
  99.             //drawQuadraticCurve(ctx, 100, 100, 300, 300, 400, 30);
  100.  
  101.             //drawBezierCurve(ctx, 100, 100, 300, 300, 200, 50, 350, 200);
  102.  
  103.             ctx.translate(canvas.width / 2, canvas.height / 2);
  104.             ctx.rotate(- Math.PI / 2);
  105.  
  106.             ctx.moveTo(0, 0);
  107.             ctx.lineTo(-200, 200);
  108.  
  109.             ctx.lineWidth = 2;
  110.             ctx.strokeStyle = 'red';
  111.             ctx.fillStyle = 'red';
  112.             ctx.stroke();
  113.            
  114.         }
  115.     </script>
  116. </body>
  117. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement