main.js 540 B

12345678910111213141516171819202122232425
  1. let ctx = canvas.getContext("2d");
  2. ctx.beginPath();
  3. ctx.arc(50, 50, 50, Math.PI/6, -Math.PI/6, false);
  4. ctx.lineTo(50, 50);
  5. ctx.closePath();
  6. ctx.strokeStyle = 'black';
  7. ctx.fillStyle = "green";
  8. ctx.fill();
  9. ctx.stroke();
  10. ctx.beginPath();
  11. ctx.arc(57, 25, 5, 0, 2 * Math.PI);
  12. ctx.fillStyle = "black";
  13. ctx.fill();
  14. ctx.stroke();
  15. function drawCircle(e){
  16. ctx.beginPath();
  17. ctx.arc(e.layerX, e.layerY, 5, 0, 2 * Math.PI, false);
  18. ctx.fillStyle ="yellow";
  19. ctx.fill()
  20. ctx.stroke();
  21. }
  22. canvas.addEventListener("click", drawCircle);