See the screenshot below the code snippets.
Paset this into the HTML box
<canvas id="myCanvas" width="578" height="200"></canvas>
Paste this into the JavaScript box, select jQuery 3.3.1 then click run
$(function() { var c = document.getElementById("myCanvas"); var ctx = c.getContext("2d"); function DrawBox(x, y, w, h) { ctx.beginPath(); ctx.lineWidth = "2"; ctx.strokeStyle = "black"; ctx.moveTo(x, y); ctx.lineTo(x + w, y); ctx.lineTo(x + w, y + h); ctx.lineTo(x, y + h); ctx.lineTo(x, y); ctx.stroke(); } function DrawLine(x1, y1, x2, y2) { ctx.beginPath(); ctx.lineWidth = "2"; ctx.strokeStyle = "red"; ctx.moveTo(x1, y1); ctx.lineTo(x2, y2); ctx.stroke(); } DrawBox(10, 10, 40, 20); DrawBox(70, 30, 40, 20); DrawLine(50, 20, 70, 40); DrawBox(70, 70, 40, 20); DrawLine(30, 30, 90, 70); });
No comments:
Post a Comment