C'est le jeu des tubes de couleur dans les pubs la
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TubeDrawObject.js 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. class TubeDrawObject
  2. {
  3. #tube;
  4. constructor(_x, _y, _tube, _scale)
  5. {
  6. this.x = _x;
  7. this.y = _y;
  8. this.scale = _scale;
  9. this.#tube = _tube;
  10. }
  11. get height()
  12. {
  13. return this.scale * this.#tube.height();
  14. }
  15. get width()
  16. {
  17. return this.scale;
  18. }
  19. draw()
  20. {
  21. for (let layerIndex = 0; layerIndex < this.#tube.height(); layerIndex++)
  22. {
  23. let color = this.#tube.getColorAtLevel(layerIndex);
  24. color == null ? noFill() : fill(color);
  25. let layerY = this.y + (this.#tube.height()-layerIndex-1) * this.scale;
  26. if (layerIndex == 0) this.#drawTubeBottom(this.x, layerY, this.scale);
  27. else this.#drawTubeLayer(this.x, layerY, this.scale)
  28. }
  29. }
  30. #drawTubeLayer(_x, _y, _scale)
  31. {
  32. noStroke();
  33. rect(_x, _y, _scale);
  34. stroke('black');
  35. strokeWeight(2);
  36. line(_x, _y, _x, _y + _scale);
  37. line(_x + _scale, _y, _x + _scale, _y + _scale);
  38. }
  39. #drawTubeBottom(_x, _y, _scale)
  40. {
  41. noStroke();
  42. rect(_x, _y, _scale, _scale/2);
  43. stroke('black');
  44. line(_x, _y, _x, _y + _scale/2);
  45. line(_x + _scale, _y, _x + _scale, _y + _scale/2);
  46. arc(_x + _scale/2, _y + _scale/2, _scale, _scale, 0, PI);
  47. }
  48. inbounds(_x, _y)
  49. {
  50. return _x > this.x && _x < this.x + this.width
  51. && _y > this.y && _y < this.y + this.height;
  52. }
  53. }