script.js 869 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. var canvas = document.getElementById("canvas");
  2. var ctx = canvas.getContext("2d");
  3. ctx.beginPath();
  4. ctx.arc(70, 70, 50, Math.PI/8, -Math.PI/8, false);
  5. ctx.lineTo(65,70);
  6. ctx.closePath();
  7. ctx.strokeStyle = "black";
  8. ctx.fillStyle = "yellow";
  9. ctx.fill();
  10. ctx.stroke();
  11. ctx.beginPath();
  12. ctx.arc(75, 45, 4, 0, 2 * Math.PI);
  13. ctx.fillStyle = "black";
  14. ctx.fill();
  15. ctx.stroke();
  16. function creatDots(amountOfDots){
  17. let directionX = 50;
  18. for(let i=0;i<amountOfDots;i++){
  19. ctx.beginPath();
  20. ctx.arc(directionX=directionX+50, 70, 5, 0, 2 * Math.PI, false);
  21. ctx.fillStyle ="yellow";
  22. ctx.fill()
  23. ctx.stroke();
  24. }
  25. }
  26. creatDots(8)
  27. canvas.addEventListener("click", paint);
  28. function paint(e){
  29. ctx.beginPath();
  30. ctx.arc(e.layerX, e.layerY, 5, 0, 2 * Math.PI, false);
  31. ctx.fillStyle ="red";
  32. ctx.fill()
  33. ctx.stroke();
  34. }