import java.awt.*; import java.applet.Applet; import java.util.*; public class AutumnLeaves extends PictureWorld { Color brown = new Color(200,100,50); // (red, green, blue) public void initializePictureChoices() { // Define your pictures here and in auxiliary methods. // Add your pictures to the menu via "addPictureChoice(String name, Picture pic);" addPictureChoice("autumnLeaves", autumnLeaves()); addPictureChoice("autumnLeaves2", autumnLeaves2()); addPictureChoice("branch4()", branch4()); addPictureChoice("branch3()", branch3()); addPictureChoice("branch2()", branch2()); addPictureChoice("twoLeaves(Color.red)", twoLeaves(Color.green)); addPictureChoice("twoLeaves(Color.orange)", twoLeaves(Color.orange)); addPictureChoice("twoLeaves(Color.yellow)", twoLeaves(Color.yellow)); addPictureChoice("twoLeaves(brown)", twoLeaves(brown)); } public Picture autumnLeaves () { return rotations(branch4()); } public Picture autumnLeaves2 () { return rotations(URNest(twoLeaves(Color.red), URNest(twoLeaves(brown), URNest(twoLeaves(Color.orange), twoLeaves(Color.yellow))))); } public Picture branch4 () { return URNest(twoLeaves(Color.red), branch3()); } public Picture branch3 () { return URNest(twoLeaves(brown), branch2()); } public Picture branch2 () { return URNest(twoLeaves(Color.orange), twoLeaves(Color.yellow)); } // Auxiliary methods public Picture fourPics (Picture p1, Picture p2, Picture p3, Picture p4) { return above(beside(p1,p2),beside(p3,p4)); } public Picture fourSame (Picture p) { return fourPics(p,p,p,p); } public Picture rotations (Picture p) { return fourPics(clockwise270(p),p,clockwise180(p),clockwise90(p)); } public Picture URNest (Picture whole, Picture upperRight) { return overlay(fourPics(empty(), upperRight, empty(), empty()), whole); } public Picture twoLeaves (Color c) { Line branch = new Line(0.0, 0.0, 0.5, 0.5, c); Poly leaf1 = new Poly(c, true); // Add points in counterclockwise fashion. // Two consecutive points will be connected by a line. leaf1.addPoint(0.0, 0.0); leaf1.addPoint(0.5, 0.0); leaf1.addPoint(1.0, 0.25); leaf1.addPoint(0.5, 0.25); Poly leaf2 = new Poly(c, true); // Add points in counterclockwise fashion. // Two consecutive points will be connected by a line. leaf2.addPoint(0.25, 0.25); leaf2.addPoint(0.5, 0.625); leaf2.addPoint(0.5, 1.0); leaf2.addPoint(0.25, 0.625); // Challenge: instead of defining leaf1 and leaf2 from scratch, // it is possible to define them both in terms of a single leaf picture. // Can you figure out how? return overlay(leaf1, overlay(leaf2, branch)); } }