Salve, ho questo codice:
vorrei fare il modo che posso disegnare triangoli in questo modo:codice:<!DOCTYPE HTML> <html lang="en"> <head> <meta charset="UTF-8"> <title>Fill Shapes</title> <script> function init() { var canvas = document.getElementById("canvas"); if(canvas.getContext) { var ctx = canvas.getContext("2d"); // Draw triangle ctx.fillStyle="#A2322E"; ctx.beginPath(); // Draw a triangle location for each corner from x:y 100,110 -> 200,10 -> 300,110 (it will return to first point) ctx.moveTo(100,110); ctx.lineTo(200,10); ctx.lineTo(300,110); ctx.closePath(); ctx.fill(); } } onload=init; </script> </head> <body> <!-- Unless canvas size is specified default size is 300 w x 150 h --> <canvas id="canvas" width="770" height="150" ></canvas> </body> </html>
drawTriangle(100,110,200,10,300,110);
sapete come fare?
avete idea come trasformare questo codice in una funzione per non far ripetere codice etc..
grazie mille.