class Bottle { int w, h, hLid; int lidShift, labelShift; color c, cLid, cLabel; int weight; boolean isOnRight, isOnLeft; int homeX, homeY; int currX, currY; int clickX, clickY; boolean rectangular; public Bottle(boolean isRect, int newweight, int neww, int newh, int newhLid, int newlidShift, int newlabelShift, color newc, color newcLid, color newcLabel) { rectangular = isRect; weight = newweight; w=neww; h=newh; hLid=newhLid; lidShift=newlidShift; labelShift=newlabelShift; c=newc; cLid=newcLid; cLabel=newcLabel; homeX=homeY=currX=currY=clickX=clickY=-1; } public void setHomePosition(int x, int y) { homeX=x; homeY=y; } public void draw(int xPos, int yPos) { currX = xPos; currY = yPos; if (rectangular) { drawRectangularBottle(xPos, yPos); } else { drawOblongBottle(xPos, yPos); } } // Draw bottle to appear on correct side of scale public void drawOnScale(Scale theScale, char side) { int x = theScale.midXOfSide(side) - w/2; int y = theScale.midYOfSide(side); draw(x,y); } // Generic bottle, where xPos yPos is the bottom left corner of the bottle's bounding box protected void drawRectangularBottle(int xPos, int yPos) { // lid if (lidShift > 0) { fill(cLid); rect(xPos+lidShift, yPos-h-hLid, w-(2*lidShift), hLid); } // bottle fill(c); rect(xPos, yPos-h, w, h); if (labelShift > 0 && cLabel != -1) { // label fill(cLabel); rect(xPos, yPos-h+labelShift, w, h-(2*labelShift)); } } // Oblong bottle, where xPos yPos is the bottom left corner of the bottle's bounding box protected void drawOblongBottle(int xPos, int yPos) { // lid if (lidShift > 0) { fill(cLid); rect(xPos+lidShift, yPos-h-hLid, w-(2*lidShift), hLid); } // bottle fill(c); ellipseMode(CORNER); ellipse(xPos, yPos-h, w, h); ellipseMode(CENTER); if (labelShift > 0 && cLabel != -1) { // label fill(cLabel); rect(xPos+labelShift, yPos-h+labelShift, w-(2*labelShift), h-(2*labelShift)); } } // Check whether the given coordinate is within the bounding box of the bottle public boolean hitTest(int x, int y) { int totalX = w; int totalY = h + hLid; int startX = currX; int endX = currX + totalX; int startY = currY - totalY; int endY = currY; if (x >= startX && x <= endX && y >= startY && y <= endY) { return true; } else { return false; } } // Set the x/y where the mouse was clicked relative to the bottom left corner public void setMouseClick(int x, int y) { clickX = x-currX; clickY = y-currY; } }