Due: Friday 1/31 10:00am
Submission name: w01_pathShape
Step 0: Create your new work repository:
- Period 4: https://classroom.github.com/a/nqOH3GbS
- Period 5: https://classroom.github.com/a/kCC8e2Ba
Step 1: Code!
Create a class called PathShape
. A PathShape
will represent a shape made by connecting a series of points that will be contained in a square area (but may not take up the entire area).
- Start with the
PathShapeDriver
code available formthesource
repository.
A PathShape
will have the following instance variables:
ArrayList<PVector> points
; An ArrayList ofPVector
objects representing the vertices of the PathShape.- You can see more about PVectors here but at the moment, we only need to use the fact that they have
x
andy
instance variables.
- You can see more about PVectors here but at the moment, we only need to use the fact that they have
int numPoints
: The total number of vertices the shape should have.PVector corner
: (x, y) position of thew top-left area that will contain the shape.- int ShapeSize: The side length of the suqare area that will contain the shape.
color inside
: The fill color for the shape.
Fill in the following methods:
PathShape(int np, int cx, int cy, int ss)
:- Set
numPoints
to np. - Sets the corner to (cx, cy).
- Sets
shapeSize
toss
. - Sets
inside
to a color of your chosing. - Initializes
points
and callsmakeRandomShape()
(see below).
- Set
void makeRandomShape()
- Adds
np
random points topoints
by callingmakeRandomPoint()
- The shape need not be a polygon.
- Adds
PVector makeRandomPoint()
- Returns a new
PVector
object where the x and y values will always be within the square area that defines the callingPathShape
object.
- Returns a new
display()
- Use beginShape,
vertex
andendshape
to draw thePathShape
on the processing screen. - The shape use the instance variable colors accordingly.
- The shape should be closed, so that last point should connect to the first.
- Use beginShape,
If done correctly, the provided driver file that will create 4 PathShape objects to be displayed in a grid like so: