Método HTML canvas fillRect()
Ejemplo
Dibuja un rectángulo relleno de 150*100 píxeles:
JavaScript:
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.fillRect(20, 20, 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 | |||||
---|---|---|---|---|---|
fillRect() | Yes | 9.0 | Yes | Yes | Yes |
Definición y uso
El método fillRect() dibuja un rectángulo "relleno". El color predeterminado del relleno es negro.
Sugerencia: use la propiedad fillStyle para establecer un color, un degradado o un patrón para rellenar el dibujo.
Sintaxis de JavaScript: | contexto .fillRect( x,y,ancho,alto ); |
---|
Valores paramétricos
Parameter | Description | Play it |
---|---|---|
x | The x-coordinate of the upper-left corner of the rectangle | |
y | The y-coordinate of the upper-left corner of the rectangle | |
width | The width of the rectangle, in pixels | |
height | The height of the rectangle, in pixels |
❮ Referencia de lienzo HTML