I am in university and have just started programming. we were told to create an image comprising of only squares circles and triangles and also to make it mov.
i created a boat comprising of 4 squares and a triangle for the sail.
the image is complete however when i compile it and run it each square moves at a different time so the boat doesn't look like its moving instead it looks like different shapes are moving at different times.
i was told i could make all of the shapes move at the same time using a for loop moving each shape one pixel at a time however i have no idea how to implement this. here is the code below which i have written so far.
somebody plz help
public class Picture { private Square ocean; private Square boat; private Triangle sail; private Circle sun; private Square sail2; private Square sail3; private Square boat2; /** * Constructor for objects of class Picture */ public Picture() { // nothing to do... instance variables are automatically set to null } /** * Draw this picture. */ public void draw() { ocean = new Square(); ocean.moveVertical(150); ocean.changeSize(800); ocean.makeVisible(); ocean.changeColor("blue"); ocean.moveHorizontal(-60); boat = new Square(); boat.changeColor("black"); boat.moveHorizontal(20); boat.moveVertical(100); boat.makeVisible(); boat.changeSize(70); boat2 = new Square(); boat2.makeVisible(); boat2.changeColor("black"); boat2.moveHorizontal(90); boat2.moveVertical(100); boat2.changeSize(70); sail = new Triangle(); sail.changeSize(100, 70); sail.moveHorizontal(75); sail.moveVertical(15); sail.makeVisible(); sail.changeColor("red"); sail2 = new Square(); sail2.changeColor("black"); sail2.changeSize(20); sail2.moveHorizontal(65); sail2.moveVertical(80); sail2.makeVisible(); sail3 = new Square(); sail3.changeColor("black"); sail3.changeSize(20); sail3.moveVertical(80); sail3.moveHorizontal(40); sun = new Circle(); sun.changeColor("yellow"); sun.moveHorizontal(350); sun.moveVertical(-100); sun.changeSize(90); sun.makeVisible(); sun.slowMoveVertical(110); } /** * Change this picture to black/white display */ public void setBlackAndWhite() { if(ocean != null) // only if it's painted already... { ocean.changeColor("black"); boat.changeColor("white"); sail.changeColor("black"); sun.changeColor("black"); } } /** * Change this picture to use color display */ public void setColor() { if(ocean != null) // only if it's painted already... { ocean.changeColor("red"); boat.changeColor("black"); sail.changeColor("green"); sun.changeColor("yellow"); } } }