Assignments
-
Work 05: Organics
Due: Thursday 2/13 10:00am
Submission name: w05_organisms
Thursday 2/13 Update:
Use the class descriptions below, and by the end of Friday 2/14 you should have the following classes:
flowchart TD A[Organism] -->B[MovingOrganism] A --> C[CustomClass0] B --> D[CustomClass1] B --> E[CustomClass2]
Test your classes in your driver file.
Overview
Over the next few days, we will create an aquarium program. In this program we will have an
Tank
class, which will contain various subclasses of some root class (and possibly others). When the program is run, we will see the aquarium, and all of the animals in it moving about.Starter Classes
Here is the UML diagram for
Organism
which will be our main superclass:classDiagram class Organism { int size PVector position int health Organism(int s, int x, int y, int h) display() age() }
- Create the
Organism
superclass. - Make one subclass,
MovingOrganism
, which will be for any tank denizens that can move around. Add instance variables and methods as needed. - Make a subclass of
MovingOrganism
(we wont be creating instances ofMovingOrganism
). To start, the subclass may only differ fromMovingOrganism
in how it appears. - Make a subclass of
Organism
that would represent a living thing that does not move (like a plant or a coral…). - Create a driver file that tests your subclasses.
PImages
To start, have your
display()
methods use basic processing shapes. Once you get your classes working, you may want to use a picture indisplay()
. There is a processing class calledPImage
that you can use. Here is a simple example:PImage pic = loadImage("nemo.png"); //create the PImage object pic.resize(50, 50); //change the size (width, height) image(pic, 25, 10); //draw the image at pixel (25, 10) - upper-left
In order for this to work
nemo.png
must be a file that is in your sketch directory.
- Create the
-
Work 04: Kingdom Anamalia
Due: Tuesday 2/11 10:00am
Submission name: w04_aquarium-design.md
Overview
Over the next few days, we will create an aquarium program. In this program we will have an
Tank
class, which will contain various subclasses of some root class (and possibly others). When the program is run, we will see the aquarium, and all of the animals in it moving about.Class Diagrams
In class, you created inheritance and class diagrams for this program. Your job is to turn those diagrams into technical documentation using a diagram language called mermaid.
- You can find an example diagram using PathShape and its subclasses on theSource
- You can find documentation on how to make these diagrams here
- You can find a live editor here
- Finally, here is an example of mermaid code and resulting diagram:
classDiagram Animal <|-- Duck Animal <|-- Zebra class Animal { int age String gender isMammal() boolean mate() } class Duck{ String beakColor swim() quack() } class Zebra{ boolean is_wild run() }
Diagram:
classDiagram Animal <|-- Duck Animal <|-- Zebra class Animal { int age String gender isMammal() boolean mate() } class Duck{ String beakColor swim() quack() } class Zebra{ boolean is_wild run() }
-
Lab 00: So Many Shapes
Due: Monday 2/10 10:00am
Submission name: New GH Classroom Link
Read the instructions in the code and write the requested code.
GH Classroom Links:
- Period 4: https://classroom.github.com/a/gChr9DIE
- Period 5: https://classroom.github.com/a/xbkS-Es0
Skills Assessed
Skill Minimal Competency Developing Competency Competency Mastery 9. Writing Readable Code Uses descriptive identifiers. Uses indentation and newlines to create more readable code, and descriptive identifiers. Uses inline and block comments when appropriate. Uses indentation and newlines, and descriptive identifiers. Can take a large programming task and break it up into smaller functions. 15. Writing Classes Can design a class by grouping together ideas that should be encapsulated into a single class. Can separate out the fields from the methods while designing a class. Can write a class with fields, a single constructor and methods. Can write classes with fields, and overloaded methods and constructors. 23. Implementation of Inheritance Can extend a class. Can add new fields and methods to a subclass. Can override inherited methods and use super()
in constructors effectively.Can place fields and methods appropriately in a class hierarchy, reducing redundant code. 24. Polymorphism Can use variables of the appropriate type within a class hierarchy. Can use data structures to store and work with objects within a class hierarchy. Can explain which classes inherited functionality come from within a class hierarchy. Can design and explain an inheritance tree, including class diagrams.
-
Work 03: Finding Your Center
Due: Thursday 2/6 10:00am
Submission name: w03_centroid
Skills: 23, 24
A Little Geometry:
The centroid of a polygon is a formulaic way of identifying what we would consider the “center”, which is non-trivial for irregular polygons. To find the centroid you must iterate over all the vertices of the polygon.
- For each point from 0 to the number of points - 1, take the sum of the following, stored separately (like in
sumX
andsumY
variables):- \[(x_{i} + x_{i+1})(x_{i}y_{i+1} - x_{i+1}y_{i})\]
- \[(y_{i} + y_{i+1})(x_{i}y_{i+1} - x_{i+1}y_{i})\]
- When
i
gets to the last point, perform the calculations above replacing \(i + 1\) with0
. That is to say the correct calculation requires the last point to loop back around to the first.
- Take each of those sums and divide them by
6
times the signed area of the polygon.
Add Centroid to our Shapes
With all this in mind, add the following features to the
PathShape
class from last week:- 1 new instance variables:
PVector centroid
: an array to store thex
andy
values of the centroid.
- 1 new method
void setCentroid()
- Sets the
centroid
instance variable.
- Sets the
- 2 modified methods
display
- Draws a circle of diameter 5 at the centroid. Use a different color than the
inside
instance variable.
- Draws a circle of diameter 5 at the centroid. Use a different color than the
makeRandomShape()
or the Constructor- call
setCentroid()
aftersetArea()
- call
Create a
Septagon
ClassA
Septagon
is a seven sided polygon. Create aSeptagon
subclass ofPolygon
that only contains code that maintains the seven-sidedness of the polygons.
- For each point from 0 to the number of points - 1, take the sum of the following, stored separately (like in
-
Work 02: Area, but Harder
Due: Wednesday 2/5 10:00am
Submission name: w02_area
A Little Geometry:
The signed area of a polygon is a measure of how much space is enclosed by the shape. For a polygon with non intersecting sides, this is the same as the area, but it is also a measure that can be made for shapes with sides that intersect.
- The signed area can be found by iterating over the vertices of the polygon. For each point from 0 to the number of points - 1, take the sum of the following (this is known as the shoelace formula).
sum+=
\((x_{i} y_{i+1} - x_{i+1}y_{i})\)- When
i
gets to the last point, perform the calculations above replacing \(i + 1\) with0
. That is to say the correct calculation requires the last point to loop back around to the first. - At then end, take the cumulative sum and divide it by 2, this is the signed area.
Add Area to our Shapes
First, get the updated
PathShapeDriver
code fromthesource
(this includes updates from class today). Then add the following:- To
PathShape
- New instance variables:
float area
: stores the signed area.
- New method:
void setArea()
- Sets the
area
instance variable as defined above.
- Sets the
- Modified method:
void makeRandomShape()
- Call
setArea()
after the points are made. - Set
inside
to magenta (255, 0, 255) ifarea
is less thanshapeSize
and cyan (0, 255, 255) isarea
is greater thanshapeSize
.
- Call
- Verify that the above changes have been added to
Polygon
, if not, add code toPolygon
where needed.
- The signed area can be found by iterating over the vertices of the polygon. For each point from 0 to the number of points - 1, take the sum of the following (this is known as the shoelace formula).
-
Work 01: Shaping Your Path
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
. APathShape
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:
-
Work 00: Getting to Know You
Due: Thursday 1/30 10:00am
- Please fill out the student info form found here: https://forms.gle/guk6e8bcYMtGFAj99