Learn html - html tutorial - Rect method in html5 canvas - html examples - html programs
- The rect() is a method of <canvas> element.
- This method is used to create a rectangle in the canvas.
- It has four parameters they are x, y, width and height.
Syntax for rect() Method in HTML5 Canvas:
Parameter values for rect() Method in HTML5 Canvas:
Value |
Description |
x |
The x axis coordinate of the rectangle starting point. |
y |
The y axis coordinate of the rectangle starting point. |
width |
It is used to set a width for the rectangle. . |
height |
It is used to set a height for the rectangle. |
Sample Coding for rect() Method in HTML5 Canvas:
Code Explanation for rect() Method in HTML5 Canvas:
- ”wikitechyCanvas” is used to define the id attribute value for canvas element.
- The getElementById(); method is used to get the element that has the id attributes value as “wikitechyCanvas”.
- a.getContext(“2d”) method is returns a two-dimensional drawing context on the canvas
- rect() method is used to drawing a rectangle in the canvas.
- strokeStyle is used to change the color of the rectangle outline as a green.
- stroke method is used to draw a path on the canvas.
Output for rect() Method in HTML5 Canvas:
- The canvas rectangle with blue border.
- The green color rectangle shows that a rectangle drawn by using rect() method.
Browser Support for rect() Method in HTML5 Canvas:
Tips and Notes
- The stroke or fill method is used to draw a rectangle on the canvas.
- The strokeStyle property in canvas is used to change the color of the rectangle outline.
Related Searches to rect() Method in HTML5 Canvas
canvas draw rectangle fill
canvas fillrect color
html5 canvas draw rectangle with mouse
canvas fill color
canvas draw rectangle android
javascript rectangle object
rectangle blank canvas
javascript draw rectangle with mouse
Html5 Canvas
html tutorials