Drawing Complex Shapes via lines
<!DOCTYPE HTML> <html lang = "en"> <head> <script type = "text/javascript"> function draw(){//from w ww . ja v a2s . c o m let drawing = document.getElementById("drawing"); let con = drawing.getContext("2d"); con.beginPath(); con.strokeStyle = "red"; con.fillStyle = "blue"; con.lineWidth = "5"; con.moveTo(100, 100); con.lineTo(200, 200); con.lineTo(200, 100); con.lineTo(100, 100); con.closePath(); con.stroke(); con.fill(); } </script> </head> <body onload = "draw()"> <h1>Path Demo</h1> <canvas id = "drawing" height = "400" width = "400"> <p>Canvas not supported</p> </canvas> </body> </html>