Lab 6: Shapes and Houses¶
For this lab, we will make use StdDraw.java developed by Robert Sedgewick and Kevin Wayne at Princeton University. This class provides a set of methods for creating simple drawings. You can find the complete documentation online, but today we will focus on the following methods:
StdDraw reference
-
circle
(double x, double y, double radius)
Draws a circle of the specified radius, centered at (x, y). -
filledCircle
(double x, double y, double radius)
Draws a filled circle of the specified radius, centered at (x, y). -
rectangle
(double x, double y, double halfWidth, double halfHeight)
Draws a rectangle of the specified size, centered at (x, y). -
filledRectangle
(double x, double y, double halfWidth, double halfHeight)
Draws a filled rectangle of the specified size, centered at (x, y). -
line
(double x0, double y0, double x1, double y1)
Draws a line segment between (x0, y0) and (x1, y1). -
setPenColor
(int red, int green, int blue)
Sets the pen color to the specified RGB color.
Part 1: Getting Started¶
-
Download and move the following JAR file into your
lib
folder: -
Create a
lab06
folder (undersrc/labs
) and download the following files: -
Open DrawDemo.java and take a minute to read over the code. Then run the program.
-
At the end of
main()
, set the pen color to 69 red, 0 green, and 132 blue.- These are the official RGB values for JMU Purple.
-
Modify DrawDemo.java to draw a small, purple filled rectangle in the lower-right corner.
- The location (0, 0) is in the lower-left corner of the
StdDraw
window. - The location (1, 1) is in the upper-right corner of the
StdDraw
window.
- The location (0, 0) is in the lower-left corner of the
Please show your modified DrawDemo.java to the instructor or TA before moving on.
Part 2: Drawing Houses¶
-
Open Houses.java and take a minute to read over the code. Then run the program.
-
Add a new method
drawHouse(double x, double y)
that draws the following shape:- The total width of the house should be
0.2
. - The total height of the house should be
0.3
. The rectangle at the bottom should have a height of0.2
, and the roof should have a height of0.1
. - The rectangle that forms the bottom part of the house should be centered at (x, y). In other words, the location of the house should be determined by the parameter values.
- The method should include a call to
drawDoor()
. DO NOT COPY THE CONTENTS OFdrawDoor()
INTOdrawHouse()
!
- The total width of the house should be
-
Modify your
main()
method to include three calls todrawHouse()
. The houses should be drawn at (0.2, 0.5), (0.5, 0.5), and (0.8, 0.5). The result should look like this:
If You Have Time¶
-
Add a
drawWindow()
method that you can call from yourdrawHouse()
method. Your house should have at least two windows. -
Add a
drawStreet()
method that you can call from yourmain()
method. The street should be drawn in front of the houses.
Submission¶
Upload the following two files to Canvas:
-
Houses.java – Your code should use methods properly to receive full credit. No javadocs or checkstyle required, but your code should be easy to read.
-
Houses.png – Save the image generated by your program, even if it is empty. You can save the image from the "File" menu of the StdDraw drawing window.