195k views
3 votes
Which built-in HTML5 object is used to draw on the canvas? a) b) c) d)

1 Answer

6 votes

Final answer:

The CanvasRenderingContext2D interface is the built-in HTML5 object used to draw on a canvas. Its properties and methods allow drawing of shapes on the canvas to be possible. An HTML Canvas element is set up and targeted through JavaScript to get the 2D context for drawing.

Step-by-step explanation:

The built-in HTML5 object used to draw on the canvas is the CanvasRenderingContext2D interface. It provides the properties and methods for drawing on the canvas. For instance, to create a rectangle, you would utilise the fillRect() or strokeRect() methods.

As an example, a canvas would be set up with HTML like so: <canvas id='myCanvas' width='500' height='500'></canvas>. Then, it would be targeted in JavaScript using: let canvas = document.getElementById('myCanvas'); and finally, the 2D context would be declared through: let ctx = canvas.getContext('2d');. The context can now be utilized to draw on the canvas.

Learn more about CanvasRenderingContext2D

User LikeMaBell
by
7.9k points