Método HTML canvas createRadialGradient()
Ejemplo
Dibuja un rectángulo y rellénalo con un degradado radial/circular:
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);
Compatibilidad con navegador
Los números en la tabla especifican la primera versión del navegador que soporta totalmente este método.
Method | |||||
---|---|---|---|---|---|
createRadialGradient() | Yes | 9.0 | Yes | Yes | Yes |
Definición y uso
El método createRadialGradient() crea un objeto de degradado radial/circular.
El degradado se puede utilizar para rellenar rectángulos, círculos, líneas, texto, etc.
Sugerencia: utilice este objeto como valor para las propiedades strokeStyle o fillStyle .
Sugerencia: use el método addColorStop() para especificar diferentes colores y dónde ubicar los colores en el objeto degradado.
Sintaxis de JavaScript: | contexto .createRadialGradient( x0,y0,r0,x1,y1,r1 ); |
---|
Valores paramétricos
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 |
❮ Referencia de lienzo HTML