import java.awt.Color; import java.util.*; import java.awt.Point; import uwcse.io.*; import uwcse.graphics.*; import javax.swing.*; /** * A class to create and manipulate graphics elements stored in an ArrayList */ public class GraphicsElements { /** Maximum number of wedges in a pie */ public static final int MAXIMUM_NUMBER_OF_PIE_WEDGES = 100; /** Maximum number of stripes of one color in the pattern of stripes */ public static final int MAXIMUM_NUMBER_OF_STRIPES = 15; /** Maximum number of divisions in a Koch snow flake */ public static final int MAXIMUM_NUMBER_OF_DIVISIONS = 5; // The window is 400 pixels wide and 300 pixels high /** * Create the view of a pie Use filled arcs. The color of each arc is * random. The pie should fill the window. Store the arcs in an ArrayList * and return that ArrayList. The number of pie wedges (= arcs) is given by * the user (use a dialog box). If that number is less than or equal to 0 or * greater than MAXIMUM_NUMBER_OF_PIE_WEDGES, display an error message (use * JOptionPane.showMessageDialog)and ask for it again. Make sure that no gap * appears in the pie when drawing it. */ public ArrayList createAPie() { ArrayList graphicsList = new ArrayList(); // Add your code here return graphicsList; } /** * Create a pattern of stripes as shown in the homework instructions. Store * the triangles in an ArrayList and return that ArrayList. Use two colors * only to paint the triangles. The pattern should cover most of the window. * The number of stripes (of one color) is given by the user (use a dialog * box). If that number is less than or equal to 0 or greater than * MAXIMUM_NUMBER_OF_STRIPES, display an error message (use * JOptionPane.showMessageDialog)and ask for it again. */ public ArrayList createStripes() { ArrayList graphicsList = new ArrayList(); // Add your code here return graphicsList; } /** * Create a Koch snow flake. Use the class java.awt.Point. Store the Points * in an ArrayList and return that ArrayList. Note that you can't set the * color of a point. The initial color of the lines making up the snow flake * is black. But, you can change the color in the method * changeColorOfSnowFlake below. The snow flake should cover most of the * window, and be always visible. The number of divisions of the initial * triangle is given by the user (use a dialog box). If that number is less * than 0 or greater than MAXIMUM_NUMBER_OF_DIVISIONS, display an error * message (use JOptionPane.showMessageDialog)and ask for it again. */ public ArrayList createASnowFlake() { ArrayList graphicsList = new ArrayList(); // Add your code here // Start with a triangle Point p1 = new Point(50, 30); Point p2 = new Point(350, 140); Point p3 = new Point(50, 250); graphicsList.add(p1); graphicsList.add(p2); graphicsList.add(p3); // Division ArrayList temp = new ArrayList(); for (int i = 0; i < graphicsList.size(); i++) { // Add 3 points between i and i + 1 Point p = (Point) graphicsList.get(i); Point q; if (i == graphicsList.size() - 1) { q= (Point) graphicsList.get(0); } else { q = (Point) graphicsList.get(i + 1); } Point a = new Point((int) (p.x + (q.x - p.x) / 3.0), (int) (p.y + (q.y - p.y) / 3.0)); Point c = new Point((int) (p.x + 2 * (q.x - p.x) / 3.0), (int) (p.y + 2 * (q.y - p.y) / 3.0)); Point b = new Point(); b.x = (int) (a.x + (c.x - a.x) * Math.cos(Math.PI / 3.0) + (c.y - a.y) * Math.sin(Math.PI / 3.0)); b.y = (int) (a.y - (c.x - a.x) * Math.sin(Math.PI / 3.0) + (c.y - a.y) * Math.cos(Math.PI / 3.0)); temp.add(p); temp.add(a); temp.add(b); temp.add(c); } graphicsList = temp; return graphicsList; } /** * Rotate the colors in the pie, in a clockwise direction. Precondition: * graphicsList describes a pie Return the updated ArrayList */ public ArrayList rotateColorsInPie(ArrayList graphicsList) { // Add your code here return graphicsList; } /** * Flip the 2 colors of the pattern of stripes Precondition: graphicsList * describes a pattern of stripes Return the updated ArrayList */ public ArrayList flipColorsInStripes(ArrayList graphicsList) { // Add your code here return graphicsList; } /** * Return the new color of the snow flake (select a new random color) Use * the Random class (in java.util) to select the new random color. The color * that you create and return in this method will automatically be assigned * to the snow flake. */ public Color changeColorOfSnowFlake() { return Color.red; // CHANGE THIS } }