Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML canvas createRadialGradient() method

HTML canvas createRadialGradient() method

Canvas Object Reference Canvas object

Example

Draw a rectangle and fill it with a radial/circular gradient:

YourbrowserdoesnotsupporttheHTML5canvastag.

JavaScript:

var c=document.getElementById("myCanvas");

var ctx=c.getContext("2d");

var grd=ctx.createRadialGradient(75,50,5,90,60,100);

grd.addColorStop(0,"red");

grd.addColorStop(1,"white");

// Fill with gradient

ctx.fillStyle=grd;

ctx.fillRect(10,10,150,100);

Try it »


Browser support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

Internet Explorer 9, Firefox, Opera, Chrome and Safari support the createRadialGradient() method.

**Note:** Internet Explorer 8 and earlier versions do not support .


Definition and Usage

The createRadialGradient() method creates a radial/circular gradient object.

The gradient can be used to fill rectangles, circles, lines, text, and so on.

**Tip:** Please use this object as strokeStyle or fillStyle the value of the property.

**Tip:** Please use addColorStop() The method specifies different colors and where to position the colors within the gradient object.

JavaScript syntax: context.createRadialGradient(x0,y0,r0,x1,y1,r1);

Parameter value

Parameters Description
x0 The x-coordinate of the gradient's starting circle
y0 The y-coordinate of the gradient's starting circle
r0 The radius of the starting circle
x1 The x-coordinate of the gradient's ending circle
y1 The y-coordinate of the gradient's ending circle
r1 The radius of the ending circle

Canvas Object Reference Canvas object