HTML canvas beginPath()Método
Ejemplo
Dibuja dos trazados en el lienzo; verde y púrpura:
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
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
Pruébalo »
Soporte del navegador
![]()
![]()
![]()
![]()
![]()
Internet Explorer 9, Firefox, Opera, Chrome y Safari admiten el método beginPath().
Nota:Internet Explorer 8 y versiones anteriores no admiten el elemento <canvas>.
Definición y uso
El método beginPath() inicia una ruta, o restablece la ruta actual.
Consejo:Utilice estos métodos para crear rutas: moveTo(), lineTo(), quadricCurveTo(), bezierCurveTo(), arcTo() y arc().
Consejo:Utilicestroke()el método para dibujar la ruta exacta en el lienzo.
| Sintaxis de JavaScript: | context.beginPath(); |
|---|
Otras extensiones
Objeto Canvas