Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any reason you don't use lineTo to create a real drawing? #5

Open
MomasVII opened this issue Nov 12, 2021 · 0 comments
Open

Any reason you don't use lineTo to create a real drawing? #5

MomasVII opened this issue Nov 12, 2021 · 0 comments

Comments

@MomasVII
Copy link

function drawLine(canvas, color, x, y, px, py) {
const context = canvas.getContext("2d");
context.beginPath();
context.moveTo(x, y);
context.lineTo(px, py);
context.stroke();
}

window.addEventListener(
"mousemove",
(event) => {
const { pageX: x, pageY: y } = event;
mouseCoordinates = { x, y };
mouseCoordinatespy = { px, py };

  if (mouseDown) {
    const color = colorHash.hex(dataTrack.id);
    //drawCircle(canvas, color, x, y);
    drawLine(canvas, color, x, y, px, py);

    dataTrack.send(
      JSON.stringify({
        mouseDown,
        mouseCoordinates,
        mouseCoordinatespy,
      })
    );
  }
  px = x;
  py = y;
},
false

);

track.on("message", (data) => {
const {
mouseDown,
mouseCoordinates: { x, y },
mouseCoordinatespy: { px, py },
} = JSON.parse(data);
if (mouseDown) {
drawLine(canvas, color, x, y, px, py);
}
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant