The class SquareFigure is given and consists of the sole object window and methods,which can be sent to this class: moveRight,moveLeft,moveUp,moveDown,moveTo,setWidth,setColour and drawHollow
The absolute center of the window is at (196,134), which means that as the width of the square is 50 pixels, the top-left corner is at (171,109).
The square is supposed to grow to top-left corner of (71,9);top-right corner (321,9); bottom-left corner at (71,259) and bottom-right corner at (321,259); The square is supposed to grow symmetrically to all corners from the middle at once, so that the final width is 250pix.(from 50 pixels originally).
My new code merely changed the side of the growing square, but still doesn't make it grow to all sides(only to the top-left and bottom-left hand side).
public class GrowingSquare {
public static void main (
String [ ] args){
SquareFigure.create();
SquareFigure.setWidth(50);
int oldX = SquareFigure.getXCorner();
int oldY = SquareFigure.getYCorner();
int height = SquareFigure.getYCorner();
for (int i = 1; i < 101; i = i + 2){
Delay.milliseconds(50);
SquareFigure.setWidth(50+i);
SquareFigure.moveTo((oldX = oldX - 2),(oldY = oldY - 2));
height = height + 2;
}
}
}