Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to draw square to the center in canvas

<style>
      .main-canvas {
        margin: 20px;
        border: 1px solid black;
      }
</style>

<canvas width="600" height="400" class="main-canvas"></canvas>

const canvas = document.querySelector('.main-canvas');
const ctx = canvas.getContext('2d');

ctx.fillRect(200, 100, 200, 200);
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #draw #square #center #canvas
ADD COMMENT
Topic
Name
1+5 =