rect javascript code example
Example 1: js draw square to canvas
// canvas context.fillRect(x, y, height, width);
ctx.fillRect(20, 20, 150, 100);
Example 2: how to make a rectangle in javascript
const canvas = document.getElementById('pong') // first make a index . html with a canvas height and width and id of pong or whatever
// and then we have to get access to our context to draw on it
const context = canvas.getContext('2d')
// then you do...
context.drawRect(20, 20, 150, 150);
context.fillStyle = '#fff' // thats white!!
Example 3: draw rectangle on canvas javascript
//Assuming you have canvas and context (ctx) set up:
ctx.fillStyle = "(enter color)";
ctx.fillRect(x, y, width, height);
//to set up canvas and context:
var canvas = document.getElementById("(enter canvas's id)");
var ctx = canvas.getContext("2d");
Example 4: javascript rect
// canvas context.fillRect(x, y, width, height);
ctx.fillRect(20, 20, 150, 100);
Example 5: rect js
It is open sorce javascript library for building UI