1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| private drawOneWater(height: number, color: Color) { const radiansA = this.bottleAngle / 180 * Math.PI; const radiansM = Math.atan(2 * height / this.bottleWidth); const tempWTan = this.bottleWidth * Math.tan(radiansA); this.drawGraphics.fillColor = color; if (radiansA <= radiansM) { if (radiansA < -radiansM) { let hL = Math.sqrt(2 * height * -tempWTan); hL = hL > this.bottleHeight ? this.bottleHeight : hL; const bW = hL / Math.tan(-radiansA); this.drawGraphics.moveTo(this.bottleWidth, 0); this.drawGraphics.lineTo(this.bottleWidth, hL); this.drawGraphics.lineTo(this.bottleWidth - bW, 0); this.drawGraphics.lineTo(this.bottleWidth, 0); } else { this.drawGraphics.moveTo(0, 0); let hL = height + tempWTan / 2; let cutOffset = 0; if (hL > this.bottleHeight) { cutOffset += hL - this.bottleHeight } let hR = height - tempWTan / 2; if (hR > this.bottleHeight) { cutOffset += hR - this.bottleHeight }
this.drawGraphics.lineTo(this.bottleWidth, 0); this.drawGraphics.lineTo(this.bottleWidth, hR - cutOffset); this.drawGraphics.lineTo(0, hL - cutOffset); this.drawGraphics.lineTo(0, 0); } } else { let hL = Math.sqrt(2 * height * tempWTan); hL = hL > this.bottleHeight ? this.bottleHeight : hL; const bW = hL / Math.tan(radiansA); this.drawGraphics.moveTo(0, 0); this.drawGraphics.lineTo(bW, 0); this.drawGraphics.lineTo(0, hL); this.drawGraphics.lineTo(0, 0); } this.drawGraphics.fill(); }
|