how to change canvas color in javascript
let ctx = canvas.getContext("2d"); ctx.fillStyle = "#ff0000"; ctx.fillRect(20, 20, 150, 100);
Here is what the above code is Doing:
1. We create a canvas element in the HTML.
2. We get a reference to the canvas element in JavaScript.
3. We get a reference to the canvas element’s context.
4. We set the fillStyle property of the context to red.
5. We draw a rectangle on the canvas.