ParallelLines
Background:
In this lab, you will practice using nested for loops to recreate this image using the DrawingTool class:
To do this efficiently, there are a few suggestions to consider. First, there are eight rows each containing seven filled boxes. This suggests a nested for loop, like this:
for (int row = 0; row < 8; row++){ // calculate the start of the row of squares
// calculate and add a horizontal offset
for (int col = 0; col < 7; col++){
// draw the square
// calculate and position for the next square
}
// calculate the location and draw the line
}
Calculating the square position will take some work. You might want to make a quick sketch, with coordinates, to save frustration. Hint: there will be a negative x offset and a positive y offset to have the image start in the upper left corner as shown. The DrawingTool class includes a method for drawing filled rectangles:
fillRect(double width, double height)
For instance, with a DrawingTool called pen , the call pen.fillRect(40, 40) would create a 40x40 filled square centered about the current drawing position.
Assignment:
-
Using the information given in the Background section above, write a class using nested for loops to display the image shown above.
|