diff --git a/Picture/Canvas.java b/Picture/Canvas.java index 775ec7e..d1ece5a 100644 --- a/Picture/Canvas.java +++ b/Picture/Canvas.java @@ -28,8 +28,8 @@ public class Canvas public static Canvas getCanvas() { if(canvasSingleton == null) { - canvasSingleton = new Canvas("BlueJ Shapes Demo", 300, 300, - Color.white); + canvasSingleton = new Canvas("BlueJ Shapes Demo", 700, 700, + new Color(25, 25, 112)); } canvasSingleton.setVisible(true); return canvasSingleton; @@ -83,6 +83,7 @@ public void setVisible(boolean visible) graphic.setColor(backgroundColour); graphic.fillRect(0, 0, size.width, size.height); graphic.setColor(Color.black); + } frame.setVisible(visible); } @@ -119,7 +120,8 @@ public void erase(Object referenceObject) * Set the foreground colour of the Canvas. * @param newColour the new colour for the foreground of the Canvas */ - public void setForegroundColor(String colorString) + public void setForegroundColor(String colorString + ) { if(colorString.equals("red")) graphic.setColor(Color.red); @@ -135,7 +137,26 @@ else if(colorString.equals("magenta")) graphic.setColor(Color.magenta); else if(colorString.equals("white")) graphic.setColor(Color.white); - else + else if(colorString.equals("brown")) + graphic.setColor(new Color(188,143,143)); + else if(colorString.equals("dark green")) + graphic.setColor(new Color(0,100,0)); + else if(colorString.equals("tan")) + graphic.setColor(new Color(210,180,140)); + else if(colorString.equals("dark brown")) + graphic.setColor(new Color(78,53,36)); + else if(colorString.equals("Midnight blue")) + graphic.setColor(new Color(25,25,112)); + else if (colorString.equals("Moon Yellow")) + graphic.setColor(new Color(254, 252, 215)); + else if (colorString.equals("Gray")) + graphic.setColor(new Color(183,179,164)); + else if (colorString.equals("gravel")) + graphic.setColor(new Color(83,84,78)); + else if (colorString.equals("gold")) + graphic.setColor(new Color(255,215,0)); + + else graphic.setColor(Color.black); } diff --git a/Picture/Picture.java b/Picture/Picture.java index c5c557a..6a78609 100644 --- a/Picture/Picture.java +++ b/Picture/Picture.java @@ -12,10 +12,34 @@ */ public class Picture { - private Square wall; + private Rectangl wall; private Square window; private Triangle roof; private Circle sun; + private Rectangl pool; + private Triangle tree; + private Rectangl wall2; + private Rectangl wall3; + private Rectangl door; + private Rectangl door2; + private Square window2; + private Rectangl ground; + private Rectangl walkway; + private Rectangl ground2; + private Rectangl ground3; + private Rectangl boardWalk; + private Rectangl window3; + private Rectangl window4; + private Circle windowRound; + private Rectangl rectangleWindow; + private Rectangl rectangleWindow2; + private Rectangl rectWind; + private Rectangl squareGarage; + private Rectangl squareGarageColor; + private Square stars; + private Rectangl treeBark; + private Rectangl roofRec; + /** * Constructor for objects of class Picture @@ -30,29 +54,256 @@ public Picture() */ public void draw() { - wall = new Square(); - wall.moveVertical(80); - wall.changeSize(100); - wall.makeVisible(); - + + + sun = new Circle(); + sun.changeColor("Moon Yellow"); + //sun.moveHorizontal(600); + //sun.moveVertical(-10); + sun.makeInvisible(); + + + boardWalk = new Rectangl(); + boardWalk.changeWidth(400); + boardWalk.changeHeight(20); + boardWalk.moveVertical(400); + boardWalk.moveHorizontal(300); + boardWalk.changeColor("dark brown"); + boardWalk.makeVisible(); + + tree = new Triangle(); + tree.changeColor("green"); + tree.changeSize(150, 10); + tree.moveHorizontal(350); + tree.moveVertical(250); + tree.makeVisible(); + + treeBark = new Rectangl(); + treeBark.changeHeight(40); + treeBark.changeWidth(10); + treeBark.moveHorizontal(365); + treeBark.moveVertical(360); + treeBark.changeColor("dark brown"); + treeBark.makeVisible(); + + tree = new Triangle(); + tree.changeColor("green"); + tree.changeSize(150, 10); + tree.moveHorizontal(380); + tree.moveVertical(250); + tree.makeVisible(); + + treeBark = new Rectangl(); + treeBark.changeHeight(40); + treeBark.changeWidth(10); + treeBark.moveHorizontal(395); + treeBark.moveVertical(360); + treeBark.changeColor("dark brown"); + treeBark.makeVisible(); + + tree = new Triangle(); + tree.changeColor("green"); + tree.changeSize(150, 10); + tree.moveHorizontal(410); + tree.moveVertical(250); + tree.makeVisible(); + + treeBark = new Rectangl(); + treeBark.changeHeight(40); + treeBark.changeWidth(10); + treeBark.moveHorizontal(425); + treeBark.moveVertical(360); + treeBark.changeColor("dark brown"); + treeBark.makeVisible(); + + + + + wall3 = new Rectangl(); + wall3.changeWidth(200); + wall3.changeHeight(90); + wall3.moveVertical(280); + wall3.moveHorizontal(99); + wall3.changeColor("tan"); + wall3.makeVisible(); + + wall2 = new Rectangl(); + wall2.changeWidth(200); + wall2.changeHeight(90); + wall2.moveVertical(320); + wall2.moveHorizontal(99); + wall2.changeColor("tan"); + wall2.makeVisible(); + + window2 = new Square(); + window2.changeColor("yellow"); + window2.moveVertical(300); + window2.moveHorizontal(200); + window2.makeVisible(); + + window = new Square(); - window.changeColor("black"); - window.moveHorizontal(20); - window.moveVertical(100); + window.changeColor("yellow"); + window.moveVertical(300); + window.moveHorizontal(110); window.makeVisible(); + + + + window3 = new Rectangl (); + window3.changeColor("yellow"); + window3.moveVertical(350); + window3.moveHorizontal(110); + window3.changeHeight(45); + window3.changeWidth(60); + window3.makeVisible(); + + + window4 = new Rectangl (); + window4.changeColor("yellow"); + window4.moveVertical(350); + window4.moveHorizontal(230); + window4.changeHeight(45); + window4.changeWidth(55); + window4.makeVisible(); + + + + + door2 = new Rectangl(); + door2.moveVertical(350); + door2.moveHorizontal(180); + door2.changeHeight(50); + door2.changeWidth(40); + door2.changeColor("dark brown"); + door2.makeVisible(); + + door2 = new Rectangl(); + door2.moveVertical(370); + door2.moveHorizontal(185); + door2.changeHeight(5); + door2.changeWidth(5); + door2.changeColor("gold"); + door2.makeVisible(); + + + + pool = new Rectangl(); + pool.changeWidth(400); + pool.changeHeight(20); + pool.moveVertical(400); + pool.moveHorizontal(500); + pool.changeColor("blue"); + pool.makeVisible(); + + + + ground = new Rectangl(); + ground.changeWidth(300); + ground.changeHeight(300); + ground.moveVertical(400); + ground.moveHorizontal(-100); + ground.changeColor("dark green"); + ground.makeVisible(); + + ground2 = new Rectangl(); + ground2.changeWidth(80); + ground2.changeHeight(400); + ground2.moveVertical(400); + ground2.moveHorizontal(220); + ground2.changeColor("dark green"); + ground2.makeVisible(); + + + ground3 = new Rectangl(); + ground3.changeWidth(700); + ground3.changeHeight(300); + ground3.moveVertical(420); + ground3.moveHorizontal(270); + ground3.changeColor("dark green"); + ground3.makeVisible(); + + walkway = new Rectangl(); + walkway.changeWidth(50); + walkway.changeHeight(500); + walkway.moveVertical(400); + walkway.moveHorizontal(180); + walkway.changeColor("brown"); + walkway.makeVisible(); + + roof = new Triangle(); - roof.changeSize(50, 140); - roof.moveHorizontal(60); - roof.moveVertical(70); + roof.changeColor("black"); + roof.changeSize(100, 300); + roof.moveVertical(230); + roof.moveHorizontal(180); roof.makeVisible(); + + windowRound = new Circle(); + windowRound.changeColor("yellow"); + windowRound.moveVertical(220); + windowRound.moveHorizontal(185); + windowRound.changeSize(50); + windowRound.makeVisible(); + + rectangleWindow = new Rectangl(); + rectangleWindow.moveVertical(250); + rectangleWindow.moveHorizontal(175); + rectangleWindow.changeHeight(10); + rectangleWindow.changeWidth(50); + rectangleWindow.changeColor("dark brown"); + rectangleWindow.makeVisible(); + + rectangleWindow2 = new Rectangl(); + rectangleWindow2.moveVertical(230); + rectangleWindow2.moveHorizontal(195); + rectangleWindow2.changeHeight(50); + rectangleWindow2.changeWidth(10); + rectangleWindow2.changeColor("dark brown"); + rectangleWindow2.makeVisible(); + - sun = new Circle(); - sun.changeColor("yellow"); - sun.moveHorizontal(180); - sun.moveVertical(-10); - sun.changeSize(60); + + + squareGarage = new Rectangl(); + squareGarage.changeColor("tan"); + squareGarage.moveVertical(320); + squareGarage.moveHorizontal(-50); + squareGarage.changeHeight(80); + squareGarage.changeWidth(150); + squareGarage.makeVisible(); + + squareGarageColor = new Rectangl(); + squareGarageColor.changeColor("Gray"); + squareGarageColor.moveVertical(330); + squareGarageColor.moveHorizontal(-50); + squareGarageColor.changeHeight(70); + squareGarageColor.changeWidth(150); + squareGarageColor.makeVisible(); + + roofRec = new Rectangl(); + roofRec.changeColor("black"); + roofRec.changeHeight(10); + roofRec.changeWidth(148); + roofRec.moveVertical(310); + roofRec.moveHorizontal(-50); + roofRec.makeVisible(); + + walkway = new Rectangl(); + walkway.changeWidth(150); + walkway.changeHeight(500); + walkway.moveVertical(400); + walkway.moveHorizontal(-50); + walkway.changeColor("gravel"); + walkway.makeVisible(); + sun.makeVisible(); + sun.slowMoveHorizontal(600); + + + + } /** diff --git a/Picture/Rectangl.java b/Picture/Rectangl.java new file mode 100644 index 0000000..424efae --- /dev/null +++ b/Picture/Rectangl.java @@ -0,0 +1,210 @@ +import java.awt.*; +/** + * Write a description of class Rectangl here. + * + * @author (your name) + * @version (a version number or a date) + */ +public class Rectangl +{ + private int size; + private int xPosition; + private int yPosition; + private String color; + private boolean isVisible; + private int height; + private int width; + + + /** + * Create a new square at default position with default color. + */ + public Rectangl() + { + size = 200; + xPosition=30; + yPosition=50; + height = 30; + width = 20; + color = "red"; + isVisible = false; + } + + /** + * Make this square visible. If it was already visible, do nothing. + */ + public void makeVisible() + { + isVisible = true; + draw(); + } + + /** + * Make this square invisible. If it was already invisible, do nothing. + */ + public void makeInvisible() + { + erase(); + isVisible = false; + } + + /** + * Move the square a few pixels to the right. + */ + public void moveRight() + { + moveHorizontal(20); + } + + /** + * Move the square a few pixels to the left. + */ + public void moveLeft() + { + moveHorizontal(-20); + } + + /** + * Move the square a few pixels up. + */ + public void moveUp() + { + moveVertical(-20); + } + + /** + * Move the square a few pixels down. + */ + public void moveDown() + { + moveVertical(20); + } + + /** + * Move the square horizontally by 'distance' pixels. + */ + public void moveHorizontal(int distance) + { + erase(); + xPosition += distance; + draw(); + } + + /** + * Move the square vertically by 'distance' pixels. + */ + public void moveVertical(int distance) + { + erase(); + yPosition += distance; + draw(); + } + + /** + * Slowly move the square horizontally by 'distance' pixels. + */ + public void slowMoveHorizontal(int distance) + { + int delta; + + if(distance < 0) + { + delta = -1; + distance = -distance; + } + else + { + delta = 1; + } + + for(int i = 0; i < distance; i++) + { + xPosition += delta; + draw(); + } + } + + /** + * Slowly move the square vertically by 'distance' pixels. + */ + public void slowMoveVertical(int distance) + { + int delta; + + if(distance < 0) + { + delta = -1; + distance = -distance; + } + else + { + delta = 1; + } + + for(int i = 0; i < distance; i++) + { + yPosition += delta; + draw(); + } + } + + /** + * Change the size to the new size (in pixels). Size must be >= 0. + */ + + public void changeSize(int newSize) + { + erase(); + size = newSize; + draw(); + } + + public void changeWidth(int newWidth) + { + erase(); + width = newWidth; + draw(); + } + + public void changeHeight(int newHeight) + { + erase(); + height = newHeight; + draw(); + } + + /** + * Change the color. Valid colors are "red", "yellow", "blue", "green", + * "magenta" and "black". + */ + public void changeColor(String newColor) + { + color = newColor; + draw(); + } + + /* + * Draw the square with current specifications on screen. + */ + private void draw() + { + if(isVisible) { + Canvas canvas = Canvas.getCanvas(); + canvas.draw(this, color, + new Rectangle(xPosition, yPosition, width, height)); + canvas.wait(10); + } + } + + + /* + * Erase the square on screen. + */ + private void erase() + { + if(isVisible) { + Canvas canvas = Canvas.getCanvas(); + canvas.erase(this); + } + } +} diff --git a/Picture/package.bluej b/Picture/package.bluej index 4a5eed1..0af3d31 100644 --- a/Picture/package.bluej +++ b/Picture/package.bluej @@ -2,88 +2,100 @@ dependency1.from=Circle dependency1.to=Canvas dependency1.type=UsesDependency -dependency2.from=Picture -dependency2.to=Square +dependency2.from=Triangle +dependency2.to=Canvas dependency2.type=UsesDependency -dependency3.from=Picture -dependency3.to=Triangle +dependency3.from=Square +dependency3.to=Canvas dependency3.type=UsesDependency -dependency4.from=Picture -dependency4.to=Circle +dependency4.from=Rectangl +dependency4.to=Canvas dependency4.type=UsesDependency -dependency5.from=Triangle -dependency5.to=Canvas +dependency5.from=Picture +dependency5.to=Rectangl dependency5.type=UsesDependency -dependency6.from=Square -dependency6.to=Canvas +dependency6.from=Picture +dependency6.to=Square dependency6.type=UsesDependency -dependency7.from=PictureTest -dependency7.to=Picture +dependency7.from=Picture +dependency7.to=Triangle dependency7.type=UsesDependency -editor.fx.0.height=722 -editor.fx.0.width=800 -editor.fx.0.x=2086 -editor.fx.0.y=284 -objectbench.height=101 -objectbench.width=461 +dependency8.from=Picture +dependency8.to=Circle +dependency8.type=UsesDependency +dependency9.from=PictureTest +dependency9.to=Picture +dependency9.type=UsesDependency +editor.fx.0.height=0 +editor.fx.0.width=0 +editor.fx.0.x=0 +editor.fx.0.y=0 +objectbench.height=202 +objectbench.width=776 package.divider.horizontal=0.6 -package.divider.vertical=0.8007380073800738 -package.editor.height=427 -package.editor.width=674 -package.editor.x=239 -package.editor.y=118 +package.divider.vertical=0.6100746268656716 +package.editor.height=320 +package.editor.width=684 +package.editor.x=436 +package.editor.y=89 package.frame.height=600 package.frame.width=800 -package.numDependencies=7 -package.numTargets=6 +package.numDependencies=9 +package.numTargets=7 package.showExtends=true package.showUses=true project.charset=UTF-8 -readme.height=58 +readme.height=60 readme.name=@README -readme.width=47 +readme.width=48 readme.x=10 readme.y=10 target1.height=40 target1.name=Circle target1.showInterface=false target1.type=ClassTarget -target1.width=80 +target1.width=70 target1.x=110 target1.y=120 -target2.association=PictureTest -target2.height=40 -target2.name=Picture +target2.height=70 +target2.name=Rectangl target2.showInterface=false target2.type=ClassTarget -target2.width=80 -target2.x=420 -target2.y=160 +target2.width=120 +target2.x=430 +target2.y=132 target3.height=40 -target3.name=Canvas +target3.name=Picture target3.showInterface=false target3.type=ClassTarget -target3.width=80 -target3.x=20 -target3.y=180 +target3.width=70 +target3.x=50 +target3.y=20 target4.height=40 -target4.name=Triangle +target4.name=Canvas target4.showInterface=false target4.type=ClassTarget -target4.width=80 -target4.x=270 -target4.y=60 +target4.width=70 +target4.x=20 +target4.y=180 target5.height=40 -target5.name=Square +target5.name=Triangle target5.showInterface=false target5.type=ClassTarget -target5.width=80 -target5.x=190 -target5.y=90 +target5.width=70 +target5.x=270 +target5.y=60 target6.height=40 -target6.name=PictureTest +target6.name=Square target6.showInterface=false -target6.type=UnitTestTargetJunit4 -target6.width=80 -target6.x=450 -target6.y=130 +target6.type=ClassTarget +target6.width=70 +target6.x=190 +target6.y=90 +target7.height=70 +target7.name=PictureTest +target7.showInterface=false +target7.type=UnitTestTargetJunit4 +target7.width=120 +target7.x=130 +target7.y=10