js draw square to canvas 1

js draw square to canvas

// canvas context.fillRect(x, y, height, width);
ctx.fillRect(20, 20, 150, 100);

Here is what the above code is Doing:
1. We create a canvas element and store it in a variable called canvas.
2. We get the canvas context and store it in a variable called ctx.
3. We use the fillRect() method to draw a rectangle at position 20, 20 with a width of 150 and a height of 100.

Similar Posts