Lab8 Class
You will add code to the setup() method to create an array of various Shapes and code to the draw() method which will display all of these Shapes each frame.
- Declare an array variable of type Shape[]
- In setup()
- Allocate enough memory for your Shape array to store 4 Shapes.
- Initialize the elements of a shape array to contain two cirlces and two rectangles.
- Choose x and y coordinates, and width, height, and radius values that will fit within our 200x200 window.
-
In draw()
- Loop through each element of the Shape array, and call Shape's draw() on each one.
shapes[i].draw();
- Loop through each element of the Shape array, and call Shape's draw() on each one.
Note here that we are invoking the abstract draw method on each Shape, but Java is selecting the specific implementation to call from our Rectangle or Circle class at runtime.