HTML
In creating the shapes with HTML
These methods can be used to create a rectangle where x = the x coordinate of the rectangle, y = the y coordinate of the rectangle, width = the width of the rectangle and height of the rectangle.
The methods for creating square are same as rectangle, the difference is the width value which is the same as the height unlike in rectangle.
These methods can be used to create a triangle.
-beginPath(): This method is to start a new path for the drawing.
-moveTo(x, y): This method help to move the pen at the first vertex of the triangle
-lineTo(x, y): This method draw the bottom vertex of the triangle.
These following methods are used in creating a circle:
This shape uses the same types of methods but uses;
-ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle, counterclockwise): where
-x and y are the center coordinate of the ellipse,
-radiusX and radiusY is the horizontal and vertical radii of the
ellipse,
-rotation displays the rotation of the ellipse in radians,
-startAngle and endAngle indicate the start and end angles for the
drawing, in radians and
-counterclockwise which is optional with the value of true or false
(default is false).
This shape uses the following methods;
This shape is quite similar to parallelogram, they utilize the same methods in drawing them. The only different about them is the values of the coordinates.
This shape combines the methods of drawing triangle with the methods of the semi circle.
To create a polygon, you need to determine the sides of the shape since there are different number of sides.
These following methods are used in creating a polygon:
To get the angle, you have to calculate with this formula by dividing the circle into two;
angle = 2π/ n
hexagon
heptagon
Finally, we have come to the end of this article. The shapes we created have series of methods in drawing them.
Thank you for reading. Connect with me on
Linkedin
X
The above is the detailed content of How to create shapes with HTML canvas. For more information, please follow other related articles on the PHP Chinese website!