Metodo HTML canvas createRadialGradient()
Esempio
Disegna un rettangolo e riempilo con un gradiente radiale/circolare:
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);
Supporto del browser
I numeri nella tabella specificano la prima versione del browser che supporta completamente il metodo.
Method | |||||
---|---|---|---|---|---|
createRadialGradient() | Yes | 9.0 | Yes | Yes | Yes |
Definizione e utilizzo
Il metodo createRadialGradient() crea un oggetto gradiente radiale/circolare.
Il gradiente può essere utilizzato per riempire rettangoli, cerchi, linee, testo, ecc.
Suggerimento: utilizza questo oggetto come valore per le proprietà strokeStyle o fillStyle .
Suggerimento: utilizza il metodo addColorStop() per specificare colori diversi e dove posizionare i colori nell'oggetto sfumatura.
sintassi JavaScript: | contesto .createRadialGradient( x0,y0,r0,x1,y1,r1 ); |
---|
Valori dei parametri
Parameter | Description |
---|---|
x0 | The x-coordinate of the starting circle of the gradient |
y0 | The y-coordinate of the starting circle of the gradient |
r0 | The radius of the starting circle |
x1 | The x-coordinate of the ending circle of the gradient |
y1 | The y-coordinate of the ending circle of the gradient |
r1 | The radius of the ending circle |
❮ Riferimento tela HTML