Método HTML canvas beginPath()
Ejemplo
Dibuja dos caminos en el lienzo; uno verde y otro morado:
JavaScript:
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.beginPath();
ctx.lineWidth = "5";
ctx.strokeStyle = "green"; // Green path
ctx.moveTo(0, 75);
ctx.lineTo(250, 75);
ctx.stroke(); // Draw it
ctx.beginPath();
ctx.strokeStyle = "purple"; // Purple path
ctx.moveTo(50, 0);
ctx.lineTo(150, 130);
ctx.stroke(); // Draw it
Compatibilidad con navegador
Los números en la tabla especifican la primera versión del navegador que soporta totalmente este método.
Method | |||||
---|---|---|---|---|---|
beginPath() | Yes | 9.0 | Yes | Yes | Yes |
Definición y uso
El método beginPath() comienza una ruta o restablece la ruta actual.
Sugerencia: utilice moveTo(), lineTo(), quadricCurveTo(), bezierCurveTo(), arcTo() y arc() para crear rutas.
Sugerencia: utilice el método stroke() para dibujar realmente la ruta en el lienzo.
Sintaxis de JavaScript: | contexto .beginPath(); |
---|
❮ Referencia de lienzo HTML