HTML5 concise tutorial-1.1.4.HTML5Canvas reference manual-radiation gradient createRadialGradient, html5canvas

Source: Internet
Author: User

HTML5 concise tutorial-1.1.4.HTML5Canvas reference manual-radiation gradient createRadialGradient, html5canvas

Connection: http://blog.csdn.net/tomorrow13210073213/article/details/42486639

Reprinted please indicate the source


In the previous blog, we introduced the HTML5 canvas to provide us with a method to draw a linear gradient. In this article, we will introduce another HTML5 gradient, a radiation gradient. CreateRadialGradient () is used to create a radiation gradient (). Similar to linear gradient, the createRadialGradient () method can be used to create a canvas-based linear gradient. The created linear gradient can be used to fill the path and define strokes.


Method: createRadialGradient ()
Method Name: createRadialGradient ()
Method Description: used to create a gradient based on the entire canvas. The gradient can be used to fill the path or define the stroke (as the value of the attribute fillStyle or strokeStyle)
Js Syntax: context. createRadialGradient (x0, y0, r0, x1, y1, r1 );
Parameter: x0: x coordinate of the starting circle of the gradient,
Parameter: y0: y coordinate of the starting circle of the gradient,
Parameter: r0: the radius of the Start circle,
Parameter: x1: x coordinate of the ending circle of the gradient,
Parameter: y1: y coordinate of the ending circle of the gradient,
Parameter: r1: radius of the ending circle
Browser compatibility: IE 9, Firefox, Opera, Chrome, and Safari support the createLinearGradient () method.
Note: (1) After obtaining the gradient object, we need to use the addColorStop () method to specify different colors and where to locate the color in the gradient object. This method is described in another blog.
(2) The gradient defined by the createRadialGradient () method is based on the entire canvas. It is invisible only by defining the gradient. After defining the gradient as the value of the fillStyle or strokeStyle attribute, we actually show the gradient of the rectangle (surface or stroke) and circle (surface or stroke) defined by the path.


The definition and application of the createRadialGradient () method are basically the same as those of createLinearGradient (). The parameters of the createRadialGradient () method are different only because the gradient types are different.


The following is our test code:

<! DOCTYPE html> 

The following is a test:


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.