index.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. let ctx = canvas.getContext('2d')
  2. ctx.beginPath();
  3. // 1,2: x и y от начала координат;
  4. // 3: радиус
  5. // 4,5: начало и конец отрисовки
  6. // 6: направление отрисовки
  7. ctx.arc(100, 100, 10, 0, 1.5 * Math.PI, false);
  8. // ctx.lineTo(50, 50) // зависит только от начальной точки канваса
  9. ctx.closePath()
  10. ctx.fillStyle = '#00FF00'
  11. ctx.fill()
  12. ctx.stroke();
  13. canvas.onclick = (e) => {
  14. // console.log(e)
  15. ctx.beginPath();
  16. ctx.arc(e.layerX, e.layerY, radiusInput.value ? radiusInput.value : 5, 0, 1.5 * Math.PI, false);
  17. ctx.closePath()
  18. ctx.fillStyle = colorInput.value
  19. ctx.fill()
  20. ctx.stroke();
  21. }
  22. function getRandomInt(min, max) {
  23. return Math.round(Math.random() * (max - min)) + min;
  24. }
  25. randomBtn.onclick = () => {
  26. let x = getRandomInt(0, 400)
  27. let y = getRandomInt(0, 400)
  28. let radius = getRandomInt(1, 50)
  29. let r = getRandomInt(0, 255)
  30. let g = getRandomInt(0, 255)
  31. let b = getRandomInt(0, 255)
  32. ctx.beginPath();
  33. ctx.arc(x, y, radius, 0, 1.5 * Math.PI, false);
  34. ctx.closePath()
  35. ctx.fillStyle = ` rgb(${r}, ${g}, ${b})`
  36. ctx.fill()
  37. ctx.stroke();
  38. }
  39. // for (let index = 0; index < 10000; index++) {
  40. // let x = getRandomInt(0, 400)
  41. // let y = getRandomInt(0, 400)
  42. // let radius = getRandomInt(1, 5)
  43. // let r = getRandomInt(0, 255)
  44. // let g = getRandomInt(0, 255)
  45. // let b = getRandomInt(0, 255)
  46. // ctx.beginPath();
  47. // ctx.arc(x, y, radius, 0, 2 * Math.PI, false);
  48. // ctx.closePath()
  49. // ctx.fillStyle = ` rgb(${r}, ${g}, ${b})`
  50. // ctx.fill()
  51. // ctx.stroke();
  52. // }
  53. // three.js babylon.js