HTML canvas createRadialGradient() methode

Definitie en gebruik

createLinearGradient() methode om een stralings-/cirkelvormige gradientobject te maken.

Gradients kunnen worden gebruikt om rechthoeken, cirkels, lijnen, tekst enz. te vullen.

Tip:Gebruik dit object als strokeStyle of fillStyle waarden van de eigenschap.

Tip:Gebruik addColorStop() De methode bepaalt verschillende kleuren en waar de kleuren zich in het gradient-object bevinden.

Voorbeeld

Teken van een rechthoek en vul deze met een stralings-/cirkelvormige verloop.

Uw browser ondersteunt de HTML5 canvas tag niet.

JavaScript:

var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
var grd =ctx.createRadialGradient(75, 50, 5, 90, 60, 100);
grd.addColorStop(0, "rood");
grd.addColorStop(1, "wit");
// Vul met een gradient
ctx.fillStyle = grd;
ctx.fillRect(10,10,150,100);

Try it yourself

Syntax

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

Parameter value

Parameter Description
x0 X coordinate of the start circle of the gradient
y0 Y coordinate of the start circle of the gradient
r0 Radius of the start circle
x1 X coordinate of the end circle of the gradient
y1 Y coordinate of the end circle of the gradient
r1 Radius of the end circle

Browser support

The numbers in the table indicate the first browser version that fully supports this property.

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
4.0 9.0 3.6 4.0 10.1

Note:Internet Explorer 8 and earlier versions do not support the <canvas> element.