1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
<!DOCTYPE html> <html> <head> <title>Dibujo Simple en JavaScript</title> </head> <body> <canvas id="myCanvas" width="400" height="400"></canvas> <script> // Obtén el contexto del canvas var canvas = document.getElementById("myCanvas"); var ctx = canvas.getContext("2d"); // Dibuja un círculo ctx.beginPath(); ctx.arc(200, 200, 100, 0, 2 * Math.PI); ctx.fillStyle = "blue"; ctx.fill(); ctx.closePath(); // Dibuja un rectángulo ctx.beginPath(); ctx.rect(50, 50, 300, 200); ctx.fillStyle = "green"; ctx.fill(); ctx.closePath(); // Dibuja una línea ctx.beginPath(); ctx.moveTo(50, 50); ctx.lineTo(350, 250); ctx.strokeStyle = "red"; ctx.lineWidth = 5; ctx.stroke(); ctx.closePath(); </script> </body> </html> |