Microsoft Word - Document1
ALL CODE MUST BE DONE IN PROCESSING SOFTWARE, FREE SOFTWARE
DOWNLOAD ON processing.org
MUST WRITE NOTES EXPLAINING EACH STEP OF CODE
PLEASE SUBMIT A ZIPPED FILE of the folder containing
1. Egg.pde
2. EggHunt.pde
Points will be taken off if submitted as individual files.
Let us play Egg Hunt with Processing :)
Write code to create a class Egg with following fields/properties/attributes :
• x - to store x coordinate of center of Egg - data type - float
• y - to store y coordinate of center of Egg - data type - float
• clr - color of the Egg - data type - color
• shape - instead of candy inside the egg, there is a shape - data type - int
• a value 1 co
esponds to a rectangle
• a value 2 co
esponds to a square
• a value 3 co
esponds to a circle
• a value 4 co
esponds to a ellipse
• a value 5 co
esponds to a triangle
Class Egg implements the following methods (write code for the following methods) :
1. Only one Constructor that :
• takes 2 arguments - both as data type float - for x & y coordinates of
where Egg should be placed.
• Steps to be done inside constructor :
• assign the 2 incoming arguments to appropriate attributes.
• assign random color to the attribute clr.
• assign a random integer value between 1 through 5 -
co
esponding shapes are given while this field was described
above.
2. show
• does not return anything
• no input arguments
• goal is to draw an ellipse (100 by 150) with it's color (why ellipse?
ecause this is an egg that we are creating in canvas).
3. open
o does not return anything
o no input arguments
o if this instance of Egg is clicked : (can use dist() function - doing this
for ease of use - it won't be perfect)
o call show()
o fill with a color that is in contrast with the color of this Egg and
then depending on the value of shape, draw the co
esponding shape
to appear inside it
Usage file - file that uses Egg - name it as EggHunt :
Needs to maintain an a
ay of Egg.
Inside setup(),
• define the size of the egg hunt playing ground (size of the canvas :) )
• make background to be green (to simulate grass).
• use a loop that runs 50 times : (Basically we are creating 50 Eggs on the ground)
• create a new Egg (Egg need to be placed randomly across the canvas)
• append this new Egg to a
ay of Eggs
• call show() of this newly created Egg.
Inside mousePressed(), use a loop to call open() of each Egg in the a
ay.
draw() does not have any code in it as there is no need to animate anything.
Lavf XXXXXXXXXX