@cortez.connelly
To draw coordinates in a JavaScript canvas, you can use the following steps:
1
|
<canvas id="myCanvas" width="400" height="400"></canvas> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
var canvas = document.getElementById("myCanvas"); var ctx = canvas.getContext("2d"); function drawCoordinates() { ctx.beginPath(); // Draw x-axis ctx.moveTo(0, canvas.height / 2); ctx.lineTo(canvas.width, canvas.height / 2); // Draw y-axis ctx.moveTo(canvas.width / 2, 0); ctx.lineTo(canvas.width / 2, canvas.height); ctx.strokeStyle = "black"; ctx.stroke(); } |
1
|
drawCoordinates(); |
This will draw a simple X and Y axis in the center of the canvas. You can customize the appearance of the coordinates by changing the strokeStyle
, lineWidth
, and other properties of the ctx
object.