You will extend your animal editor.
Create a sketch that allows you to draw an animal with the keyboard and/or mouse controlling the parameters. Like the previous recursive tree, you will greate a tree-like structure for the limbs of your animal. The Root node represents the torso, and there will be a number of arms/legs that are connected to the torso. Consider that each articulated body part in the tree is an instance of a class that has the visual and geometric properties of the body. The mouse and/or keyboard interaction allows you to control some of the appearance of each part.
You need to create a structure that stores info about the current body part, and has pointers/references to child instances. You need to store information about the bounding box of each drawable part of the animal so that you can select it and edit it. You will need to use PVectors for this, because PVector allows you to do things like
PVector v1 = new PVector( 10.0, 5.0 );
v1.rotate( HALF_PI );
With a limb selected, you should have a little control panel in your editor to adjust the appearance of it. Appearance could mean color or angle, or anything suitable.
You are provided with two jar files: interfacelib.jar and reflections.jar (available via Canvas). These are similar to core.jar and controlP5.jar. You are required to add these libraries to your Netbeans project.
interfacelib.jar provides two interfaces: Scrubbable and CreatureFactory.
Your Animal component(s) must impelemnt the Scrubbable interface. The Scrubbale interface provides following functions:
String getName()This method should return the unique name of the component. Every animal component should have a name. For example, if you create a class called Leg for an Animal with four legs, the names for the legs can be "Leg1", "Leg2", "Leg3", and "Leg4"
void setName(String name)This method should set the name of the component to value in name
String[] getProperties()This method returns an array of the names of the parameters that are settable/gettable above
void setParameter( String name, float value )This method takes a String that names a parameter in your base class, and sets that parameter to the value in value.
float getParameter( String name )This method takes a String that names a parameter in your base class, returns the value of that variable.
void draw()This method recursively draws the component. You probably already have this method in your components
Scrubbable pick(int mouseX, int mouseY)This method takes the x and y coordinates for the mouse and checks if a component or a child component of a component was selected. If yes, returns the animal component that was clicked. If nothing was clicked/selected, this method returns null
IteratorThis method returns an iterator for the Scrubbable class.createIterator()
You will also create a single class which implements the CreatureFactory Interface. This interface has one method
public Scrubbable getCreature(PApplet p)This method returns your animal, i.e. the root of the animal. This is the method where you will create/construct the Animal object. A class implementing this interface should not have any contructor.
For the createIterator() function from the Scrubbable interface, you need to create an Iterator that iterates through the structure of your creature.
boolean hasNext()this returns true if there is more animal parts left, else false
Object next()this returns the next item in the traversal. To fit with Java's specification, you should cast the next item to Object. The client of the iterator can cast it to your parent class.
void remove()just create a stub for this method.
You can use our solution to Assignment 2 to build your animal.