Write HTML code to draw a rectangle using Canvas and fill color in gradient from red to pink from start to end
belongs to collection: HTML5 programming Exercises
All Answers
total answers (1)
belongs to collection: HTML5 programming Exercises
total answers (1)
Solution
HTML5 provides addcolorstop() method to identify the colors and location in a gradient object. This is a method of HTML5 canvas element.
Syntax of addcolorstop()
gradient.addColorStop(stop,color);
Here, stop is a value between 0.0 and 1.0 that represents the position between start and end in a gradient and color is a color value to display at the stop position.
This is the following HTML5 code to draw a rectangle using canvas and fill color in gradient from red to pink from start to end.
Output of the above code
In the above code, getContext() method returns an object for working on canvas, the fillStyle is a property of canvas and used to fill color gradient in the drawing and the fillRect() method is used to draw a filled rectangle.
need an explanation for this answer? contact us directly to get an explanation for this answer