Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this assignment, you will be creating your own custom quilt. The quilt will be composed of two separate tile designs arranged in a checkerboard

In this assignment, you will be creating your own custom quilt. The quilt will be composed of two separate tile
designs arranged in a checkerboard formation. Below is an example quilt:
Start with the ColorfulQuilt class from Canvas. You will be writing three methods that together will create
a quilt formation such as the one displayed above. The first method will draw a single copy of your first tile
design:
public static void drawTileA(Graphics g, int x, int y, int size)
g is the Graphics object that will draw shapes on your behalf.
x and y represent the upper left corner of the tile. All coordinate calculations should use x,y as a
starting point as shown in class so that tiles can be drawn at any location in the drawing window.
size represents the width/height of the square tile.
The CYAN/BLACK/DARK_GRAY tile above is an example tile drawn by this method. The tile should be square
and meet the following minimum requirements:
At least 3 colors
At least 3 triangles
At least 1 circle
At least 1 rectangle
The second method will draw a single copy of your second tile design:
public static void drawTileB(Graphics g, int x, int y, int size)
The GRAY/RED/BLACK tile above is an example tile drawn by this method. The tile should be square and has
the same minimum requirements as the drawTileA method (at least 3 colors, 3 triangles, 1 circle, 1
rectangle). However, Tile B has the following additional requirements:
The number of shapes should be different from Tile A. For example, my Tile A design above has 6
shapes (1 black border rectangle, 4 cyan triangles, 1 dark gray circle) and my Tile B design above has 9
shapes (1 dark gray background rectangle, 4 red circles, 4 light gray triangles).
The number or shade of the colors should differ. For example, Tile A above has 3 colors (CYAN,
DARK_GRAY, BLACK) and Tile B has 3 colors (LIGHT_GRAY, DARK_GRAY, RED). This follows the rule
since the two tiles differ in their color shades. It is also okay if colors are reused but one tile has more
colors than the other.
The tester will test both tile methods to check for these minimum requirements. It will also try drawing tiles at
different locations in the drawing window to make sure the point calculations work regardless of tile location.
I recommend sketching your tiles out on paper and determining the points needed for each shape before
writing the code for the tile methods. After writing the code for the tile methods, run the tester to make sure
they follow the requirements before moving on to the last method.
The last method will use loops to draw an entire quilt in a checkerboard formation:
public static void drawQuilt(Graphics g, int x, int y, int tileSize,
int rows, int columns)
g is the Graphics object that will draw shapes on your behalf
x and y represent the upper left corner of the entire quilt
tileSize represents the width/height of a single tile of the quilt
rows and columns represent the number of rows and columns of tiles in the quilt
The method should use a nested loop and alternate between your drawTileA and drawTileB methods to
achieve a checkerboard. The tester expects that your inner loop draws a row and the outer loop repeats the
inner loop to draw multiple rows.
The tester will try drawing multiple copies of your quilt at different locations in the drawing window with
different tileSize values and different rows and columns.
Javas Graphics library does not contain a fillTriangle method. For convenience, I have included one for you in
the starter code for the assignment:
public static void fillTriangle(Graphics g, Color c, int x1, int y1,
int x2, int y2, int x3, int y3){
int[] xs ={x1, x2, x3};
int[] ys ={y1, y2, y3};
g.setColor(c);
g.fillPolygon(xs, ys,3);
}
Since this is a custom method defined by me, it is called a little differently than the built-in graphics methods.
The built-in methods are called using the syntax g.methodName(...);
Example: g.fillOval(x + size /4, y + size /4, size /2, size /2);
The fillTriangle method is called using the syntax fillTriangle(g,...);
Example: fillTriangle(g, Color.CYAN, x + size /2, y + size, x + size,
y + size, x + size, y + size /2);
A tester program will be made available on Canvas. Please make sure you run it! It will tell you if there are
problems with your program which could impact your grade for the assignment! If your program doesnt
compile (red X), you may not earn any points. Submit the file ColorfulQuilt.java to the Canvas
assignment when complete

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced Oracle Solaris 11 System Administration

Authors: Bill Calkins

1st Edition

0133007170, 9780133007176

More Books

Students also viewed these Databases questions