class TubeDrawObject { #tube; constructor(_x, _y, _tube, _scale) { this.x = _x; this.y = _y; this.scale = _scale; this.#tube = _tube; } get height() { return this.scale * this.#tube.height(); } get width() { return this.scale; } draw() { for (let layerIndex = 0; layerIndex < this.#tube.height(); layerIndex++) { let color = this.#tube.getColorAtLevel(layerIndex); color == null ? noFill() : fill(color); let layerY = this.y + (this.#tube.height()-layerIndex-1) * this.scale; if (layerIndex == 0) this.#drawTubeBottom(this.x, layerY, this.scale); else this.#drawTubeLayer(this.x, layerY, this.scale) } } #drawTubeLayer(_x, _y, _scale) { noStroke(); rect(_x, _y, _scale); stroke('black'); strokeWeight(2); line(_x, _y, _x, _y + _scale); line(_x + _scale, _y, _x + _scale, _y + _scale); } #drawTubeBottom(_x, _y, _scale) { noStroke(); rect(_x, _y, _scale, _scale/2); stroke('black'); line(_x, _y, _x, _y + _scale/2); line(_x + _scale, _y, _x + _scale, _y + _scale/2); arc(_x + _scale/2, _y + _scale/2, _scale, _scale, 0, PI); } inbounds(_x, _y) { return _x > this.x && _x < this.x + this.width && _y > this.y && _y < this.y + this.height; } }