0

I am trying to draw a triangle and store it's x/y coordindates. Following https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Drawing_shapes

function draw() {
  var canvas = document.getElementById('canvas');
  if (canvas.getContext){
    var ctx = canvas.getContext('2d');
    ctx.translate(0,100);
    ctx.beginPath();
    ctx.moveTo(75,50);
    // READ X/Y VALUE HERE
    ctx.lineTo(100,75);
    // READ X/Y VALUE HERE
    ctx.lineTo(100,25);
    // READ X/Y VALUE HERE
    ctx.fill();
  }
}

How do I get the x/y values in the places marked, as the translate will mean the values put into moveTo and lineTo will be different.

Thanks

holmeswatson
  • 969
  • 3
  • 14
  • 39

0 Answers0