Javascript examples for Canvas Reference:createRadialGradient
The createRadialGradient() method creates a radial/circular gradient object which can be used to fill rectangles, circles, lines, text, etc.
context.createRadialGradient(x0, y0, r0, x1, y1, r1);
Parameter | Description |
---|---|
x0 | The x-coordinate of the starting circle |
y0 | The y-coordinate of the starting circle |
r0 | The radius of the starting circle |
x1 | The x-coordinate of the ending circle |
y1 | The y-coordinate of the ending circle |
r1 | The radius of the ending circle |
The following code shows how to draw a rectangle and fill with a radial/circular gradient.
<!DOCTYPE html> <html> <body> <canvas id="myCanvas" width="300" height="250" style="border:1px solid #d3d3d3;"> Your browser does not support the HTML5 canvas tag.</canvas> <script> 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"); ctx.fillStyle = grd;/* w w w .j ava 2 s .c om*/ ctx.fillRect(10, 10, 150, 100); </script> </body> </html>