• Work 17: Adding Meaning

    Due: Thursday 4/24 10:00am

    Submission name: w17_wordGrid

    a17-wordgrid

    (the words in the above grid are [exosphere, croakiness, hagrope, bescurvy, mantrap, carbinol, biding, vats, hol, telega])

    4/24 Update

    If you have completed placing words horizontally/vertically then you can try the following problems (neither are necessary for a fully working program, but are fun challenges).

    • Placing words diagonally.
    • Placing words backwards.

    Word Placing!

    Add the ability to place words in your wordsearch grid. In order to do this, you will need a list of words, I have uploaded a very large list of words (~370k) to thesource. You can find it here: https://github.com/nextcs-dw/thesource/tree/main/Wordsearch.

    • You will need to use Processing’s loadStrings() function, which returns an array of strings from a plain text file.
    • Your end goal is to write a method void pickWords(int n) which will place n words in your word search grid.
      • The words should be placed either horizontally or vertically, going left->right or top->down.
      • Placement in the grid should be random.
      • Words should be at least 3 characters long.
      • Keep track of the words actually placed in the grid with an added instance variable in the WordGrid class.
      • You will need extra methods, and possible instance variables and constants to help in this process. Add them as you see fit.
      • For testing, only add words to your wordgrid (leave all other cells blank).

  • Work 16: Searching for Meaning

    Due: Tuesday 4/22 10:00am

    Submission name: w16_wordGrid

    a16-wordgrid

    Word Searching!

    Over the next few days we will be creating a word search program, the core of this will be the class WordGrid, which will contain a 2D array of char values, as well as other necessary fields. To start, write the WordGrid class as follows:

    • Fields
      • char[][] grid
      • int size
      • More to be added later
    • Methods
      • WordGrid(int s)
        • Set size to s.
        • Initialize grid to be a size x size array.
        • Call fillGrid()
      • void fillGrid()
        • Fill grid with random upper case letters.
      • void drawGrid
        • Display the contents of grid on the screen, taking up the full size.

    Write a driver file that:

    • Sets global constants for the size of each displayed character and the size of the word grid.
    • Sets the screen size to exactly fit the word grid.
    • Creates a new word grid using the size global variable.
    • Tests drawGrid.

  • Lab 04: DNAlysis

    Due: Tuesday 4/22 10:00am

    Read the instructions in the code and write the requested code.

    Big Test

    If you want to test your program on a much larger dataset, I have uploaded an 8000 nucleotide sample dna string in a plain text file on thesource.

    • To use it, save the file in the same directory as your processing sketch (like you would with an image). Then use processing’s loadStirngs method to load the file as a string.
    • You will need to decrease the value of NUC_SIZE in order to view all the data. It would also be useful to turn off displaying the letter in the boxes (adding a boolean parameter to drawBase is the best option here).

    l04-dna


  • Work 15: High-Protein Diet

    Due: Thursday 4/10 10:00am

    Submission name: w15_proteins

    Background Genetics Information

    DNA is made up of strands of nucleotides, of which there are 4 types: adenine, thymine, cytosine and guanine. Because of this, DNA sequences can be represented as strings like this:

    tcgcagctcgaaccactatg
    

    Generally, DNA is translated into RNA, and then RNA is used to create proteins using amino acids. In DNA, 3 nucleotides together represent a single amino acid. We refer to sequences of 3 nucleotides as codons. Additionally, the sequence atg represents the start of a protein, and taa, tga, and tag represent the end of a protein. We will be working on a processing program to help visualize different information about DNA strands.

    Useful Java Stuff

    • If you want to look at a working version of the previous assignment, check thesource.
    • indexOf(String sub) is a Java Sting method that returns either:
      • The index of the start of the first occurrence of sub in the calling string.
      • -1 if sub does not appear in the calling string.
    • substring() is a Java String method that returns a portion of a String, as a new String object. There are 2 versions of substring():
      1. s.substring(start)
        • Returns a String made from the characters in s starting at index start and going to the end of s.
      2. s.substring(start, end)
        • Returns a String made from the characters in s starting at index start and ending at index end-1.

    Task at Hand

    Create a copy of your work from yesterday, then add the following methods:

    • intFindProteinEnd(String strand)
      • Returns the index of the first end codon in strand.
      • Returns -1 if there is no end codon in strand.
    • boolean containsProtein(String dna)
      • Returns true if dna contains at least one full exon.
      • For our purposes, a DNA sequence contains an exon if:
        • It has a start codon
        • It has an end codon
        • The number of nucleotides between the start and end is a multiple of 3 (i.e. there are no nucleotides unattached to a codon)
        • It has at least 5 other codons between those 2. (this is not biologically accurate, in reality this is closer to 430 codons).
    • String getProtein(String dna)
      • Returns the first protein-encoding (exon) portion of dna. It should not include the start or end codons.
      • If there are no exons in dna, return the empyt string.

    Here are a series of useful test cases for this assignment:

    println("protein end in [" + protein1 + "] (21): " + findProteinEnd(protein1));
    println("protein end in [" + noProtein0 + "] (-1): " + findProteinEnd(noProtein0));
    println("protein end in [" + noProtein2 + "] (3): " + findProteinEnd(noProtein2));
    
    println("protein in [" + protein0 + "] (true): " + containsProtein(protein0));
    println("protein in [" + protein1 + "] (true): " + containsProtein(protein1));
    println("protein in [" + protein2 + "] (true): " + containsProtein(protein2));
    println("protein in [" + noProtein0 + "] (false): " + containsProtein(noProtein0));
    println("protein in [" + noProtein1 + "] (false): " + containsProtein(noProtein1));
    println("protein in [" + noProtein2 + "] (false): " + containsProtein(noProtein2));
    println("protein in [" + noProtein3 + "] (false): " + containsProtein(noProtein3));
    println("protein in [" + noProtein4 + "] (false): " + containsProtein(noProtein4));
    
    println();
    println("protein in [" + protein0 + "] " + getProtein(protein0));
    

  • Work 14: The Code of Life

    Due: Wednesday 4/9 10:00am

    Submission name: w14_drawDNA

    Background Genetics Information

    DNA is made up of strands of nucleotides, of which there are 4 types: adenine, thymine, cytosine and guanine. Because of this, DNA sequences can be represented as strings like this:

    tcgcagctcgaaccactatg
    

    When two strands of DNA match, then adenine is paired with thymine, and cytosine is paired with guanine. So the following two DNA strands match:

     tcgcagctcgaaccactatg
     agcgtcgagcttggtgatac
    

    Task at Hand

    Using the information above, write the following processing functions:

    • void drawBase(char base, int x, int y, int sz)
      • Draws a single base in a square at (x, y) with side length sz.
      • The squares should have no stroke, and each type of nucleotide should be given a distinct color.
      • The letter for the nucleotide should be displayed within the square in a color that is easy to see.
      • You may reuse code form yesterday’s assignment it you’d like.
    • void drawStrand(String dna, int x, int y, int sz)
      • Draws the entire dna strand starting at (x, y) using sz for the size of each square.
      • This method should call drawBase().

      a06_drawStrand

    • boolean basePairMatch(char b0, char b1)
      • Returns true if b0 and b1 are a correct base pair match (i.e a and t or c and g).
      • Returns false otherwise
    • boolean strandMatch(String strand0, String strand1)
      • Returns true if strand0 and strand1 match as described above.
      • This does not mean the strings are equal, but that the appropriate nucleotides are matched.
    • void strandCompare(String strand0, String strand1, int x, int y, int sz)
      • Draws strand0 directly above strand1.
      • If there is a nucleotide mismatch, draw a yellow border around the nucleotide.

      a06_strandCompare

    • The following global variables and setup() will test the above functions:
    String s0 = "tcgcagctcgaaccactatg";
    String s1 = "agcgtcgagcttggtgatac";
    String s2 = "atcgtccagctatgtgatac";
    String s3 = "caatcacctgagtatcgcga";
    
    int NUC_SIZE = 30;
    
    void setup() {
      size(800, 200);
      background(0);
      textAlign(CENTER, CENTER);
    
      strandCompare(s0, s1, 0, 0, NUC_SIZE);
    
      strandCompare(s0, s2, 0, NUC_SIZE*3, NUC_SIZE);
    
      //strandMatch tests
      println(strandMatch(s0, s1)); //correct match
      println(strandMatch(s0, s0)); //strand should not match itself
      println(strandMatch(s0, s2)); //mismatch
    }//setup
    

  • Work 13: What a Bunch of Characters

    Due: Tuesday 4/8 10:00am

    Submission name: w13_drawChar

    Write a processing program with the following functions

    • color charToColor(char c)
      • Create and return a color based on the value of c as follows:
      • Multiply c by 23, 41 and 67, respectively to to get red, green and blue values (you could use other numbers, but small, relatively prime numbers work best).
      • Don’t forget to make sure each color is within the range [0, 255]
    • void drawChar(char c, int x, int y)
      • Draw a square using the color from charToColor() at the given x and y location, using c as the side length.
      • Set textSize to the value of c.
      • Display c as a character inside the square.
    • setup()
      • Set the screen size to 600x400
      • Using a for loop controlled by a char variable, loop through the chars from 'A' to 'Z', calling drawChar() appropriately. Set x and y values as you see fit.

    Reference Image:

    abcs.png


  • Project 00: May The Force(s) Be With You

    Due: Monday 4/7 10:00am

    Project Description

    For this project, you may create teams of 2 people. Your mission is to destroy the Death Star create a Processing program that demonstrates different physical forces, building off of the framework we have been creating in class. Your program should do the following:

    • The ability to toggle on/off the wall bouncing behavior (which has been built in to all our physics programs from the start).
    • The ability to toggle on/off movement.
    • Reasonably model gravity (in the classical mechanics sense), drag, and the spring force. The force calculations for all three have already been done in class.
    • Add one more force. The force can be rooted in reality, or something of your own invention. Regardless, calculating the force should involve some combination of an orbs mass, velocity, acceleration and external factors (which may be another orb). Calculating the force should work the same way as the others, by adding a method that returns a PVector to the Orb class.
      • Instead of a force in the traditional sense, you can chose to model accurate orb-orb collisions. This is not the same as calculating a PVector and calling applyForce, but it will involve vector calculations between Orb objects.
    • Use both an array and a linked list amongst different simulations.
    • Produce 5 different simulations as follows:
      • A demonstration of gravity showing “planets” orbiting a central massive body. This one should use an array of orbs with a fixed central orb.
      • A demonstration of the spring force that includes at least 1 non moving orb. This should use a linked list of orbs.
      • A demonstration of drag that involves at least 2 or more orbs moving through at least 2 areas with different drag results.
      • A demonstration of your new force.
      • A demonstration that combines at least 3 of the forces.

    Interface Requirements

    Your program should be able to visually indicate:

    • Whether movement is on/off
    • Whether bouncing is on/off
    • Which force(s) are currently being applied. Your program should respond to the following keyboard commands:
    • ' ': movement on/off
    • 'b': wall bouncing on/off
    • '1': Setup simulation 1 (orbital gravity)
    • '2': Setup simulation 2 (spring)
    • '3': Setup simulation 3 (drag)
    • '3': Setup simulation 4 (custom)
    • '3': Setup simulation 5 (combination)

    Phase 0 - Analyze & Plan

    Due: Wednesday, 3/26 10:00am

    Fill in the README.md file created when you make your repository.

    Phase 1 - Feedback

    Due: Thursday, 3/28 10:00am

    Below, you will find links to all the project repositories. For this phase, I have made them publicly viewable.

    • Find your project on the list. You will be providing feedback for the three projects below you, wrapping back around to the top (i.e. the last group should look at the first three).
    • If you find an empty README, just move to the next one, but make sure to still look at 3.
    • For each project you are reviewing:
      • Read the README.md document that has been created.
      • Make note of anything that stands out to you. You will be specifically required to provide 2 of each of the following:
        • Things from the design that you really like. Explain why.
        • Clarifying questions, either something that does not quite make sense to you, or something that you think needs further explanation.
        • Suggestions, either things to add or ways to implement things already there.
      • You will provide this feedback using the “Issues” section of the project GitHub repository.
        • Title the issue Feedback from followed by your name(s).
        • Use the following markdown template to fill in your responses:
        Cool things:
        -
        -
        
        Clarifying Qs:
        -
        -
        
        Suggestions:
        -
        -
        
    • Once you have provided the feedback, look over the issues on your own repository. Create a new document in your project repository called changes.md. The purpose of this file is to track any changes between your design document and your finished project. If you decide to change some parts of your design based on the feedback you received (or from looking at the designs of others), add them to changes.md. It should be a markdown file, but you can organize it however you’d like.
    • Please leave your issues open until I tell you otherwise so that I can look at them easily.

    Phase 2 - Demos & Feedback

    Due: Wednesday, 4/2 10:00am

    In class on Wednesday, you should have a program that performs at least 3 of your proposed simulations. During class, other students will have a chance to run your code and provide feedback, so it is important that your project is in a state where it can work..

    Skills Grid:

    7. Controlling Program Speed Can set the frame rate for a processing program. Can set the frame rate based on a specified speed. Can control program output based on the current frame number. Can start and stop the action of a processing program.
    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.
    14. Using Objects Can declare and Object variable and instantiate an Object using a constructor. Can use multiple Objects in a program by calling methods on appropriately declared and instantiated Object variables. Can use Objects in a program, describe how reference variables work, and how they are different from primitive variables. Can use Objects and accurately make heap diagrams of Object variables and data.
    25. Linked Lists Can make a node-based object that contains references to other nodes. Can connect node-based objects linearly and traverse them using a node variable. Can create a linked list class with the ability to traverse the list and add/remove objects at either end. Can create a linked list with the ability to add and delete nodes in any position.
    26. Modeling Can create a framework for modeling forces in accordance with Newtonian mechanics. Can translate a equation of physical forces that involve a single body into a program model. Can translate a equation of physical forces that involve multiple bodies into a program model. Can create an accurate model of multiple physical forces and use it in a compelling demonstration.

  • Lab 03: Spring Has Sprung

    Due: Monday 3/24 10:00am

    Read the instructions in the code and write the requested code.


  • Work 12: Noddeing Off

    Due: Wednesday 3/19 10:00am

    Submission name: w12_orbnodes

    We will continue with the work started in class on using a node based Orb structure.

    • Start with the program developed in class from yesterday’s assignment.

    • Add the following to the driver file (it should still do all the things from the previous assignment).

      • The ability to calculate and apply earthGravity if that option is on.
      • The ability to add a random node to the front of the chain when '=' is pressed.
      • The ability to remove the front node of the chain when '-' is pressed.
      • For adding and removing, you may assume there is always at least 1 node.

  • Work 11: Nodular Design

    Due: Tuesday 3/18 10:00am

    Submission name: w11_orbnodes

    We will continue with the work started in class on using a node based Orb structure.

    • Start with the program developed in class.

    • OrbNode should also have the following methods
      • void display(int springLength)
        • Display the OrbNode.
        • If there is a next node, draw a line between this and the next OrbNode objects.
        • If there is a previous node, draw a line between this and the next OrbNode objects.
          • Move the endpoints for each of these lines a little bit so the lines dont directly overlap each other.
        • Make the color of the line related to the state of the spring (extended, compressed, neither).
      • void applySprings(int springLength, float springK)
        • Apply the spring force between the calling Orb and it’s next and previous neighbors when applicable.
    • Write a driver file that creates at least 3 OrbNodes and connects them. Then in draw
      • Use a while loop to display each OrbNode
      • Use a while loop to call applySprings on each OrbNode
      • Use a while loop to call run on each OrbNode
      • These loops should not be integer-counter based.

    Reference Image:

    a11-nodes


  • Lab 02: Spring Ahead!

    Due: Monday 3/17 10:00am

    Read the instructions in the code and write the requested code.


  • Work 10: Spring into Action

    Due: Wednesday 3/12 10:00am

    Submission name: w10_spring

    Spring Physics

    Relevant Physics to find the force a spring connecting \(A\) to \(B\), where \(B\) is a fixed point:

    • \[F = kx\hat{AB}\]
    • Where \(k\) is the spring constant,
    • \(x\) is the displacement, or difference of the distance between \(A\) and \(B\) and the length of the spring.
    • \(\hat{AB}\) is the normalized vector from \(A\) to \(B\).

    Spring Code

    • Start with the code for FixedOrbRunner in thesource
    • Add the method PVector getSpring(Orb o, int springLength, float springConstnat) to Orb
      • This should calculate the force felt on the calling object of a spring between the calling object and o.
      • The resulting force should pull the calling object towards o if the spring is extended past springLength and should push the calling object away from o if the spring is compressed to be less than springLength.
    • Create a driver file that tests the spring force. This should not have extra pieces. A single FixedOrb and regular Orb will suffice. Adding gravity (either as a constant downward force or using FixedOrb as discussed in class), can provided a constant “pulling” on the spring to help test.

    Reference Image:

    a10-spring


  • Work 09: Building a Better Simulator

    Due: Tuesday 3/11 10:00am

    Submission name: w09_simulation

    Making a more robust simulation.

    • First off, start with a working gravity simulation with 2 orbs (work 08).
    • Add the ability to turn the following features on and off:
      • The drag force
      • Gravity between Orbs
      • Wind (a constant push left or right)
      • Global gravity (a constant push up or down)
      • Bouncing on the walls
    • Include some visual indication of which features are currently active.
    • Once that is done, modify your code so that instead of 2 Orb objects, you have an array of orbs. All the forces should work on the orbs as before.

  • Work 08: The Gravity of the Situation

    Due: Friday 3/5 10:00am

    Submission name: w08_gravity

    Calculate Gravity

    Gravity is the attractive force exerted on an object by another object that has mass (something something curvature of spacetime something something). To find the force of gravity exerted on \(A\) by \(B\):

    • \[F = G \dfrac{mass_A mass_B}{r^2}\hat{AB}\]
    • Where \(r\) is the distance between \(A\) and \(B\). And \(\hat{AB}\) is the normalized vector from \(A\) to \(B\).
      • To calculate \({\overrightarrow AB}\), subtract \({\overrightarrow A}\) from \({\overrightarrow B}\) (in our code these are the center PVector fields).

    Let’s get gravity right.

    • Start with the latest Orb code from thesource, which will include the mass stuff.
    • Add the method PVector getGravity(Orb o, float G)
      • This should calculate the force of gravity exerted on the calling object by o. This means that we should be seeing how o attracts the calling object.
      • This should return a PVector representing the force of gravity exerted on the calling object by o.
    • Create a driver file that makes 2 orbs that exert gravity on each other.
      • Play around with distances, masses and G values. You will probably get strange behavior.

  • Work 07: What a Drag

    Due: Thursday 3/5 10:00am

    Submission name: w07_drag

    Calculate Drag

    Drag is a force that “pushes” opposite to velocity. In order to calculate the drag force we need to figure out the direction it will apply and the magnitude of the force. The (simplified) Formula for Drag is:

    \[{\overrightarrow F} = -\dfrac{1}{2} ||v||^2 C_d {\hat v}\]

    What is this?

    • \(v\) Is the magnitude of the velocity vector. Luckily, we can get the magnitude using velocity.mag(), which returns a float value.
    • \(C_d\) is the coefficient of drag, this is different depending on the material (air, water, honey…).
    • \({\hat v}\) is the normalized velocity vector. This has the same direction as the velocity vector, but the magnitude is 1. Once again, we have a nice method for this. vector.normalize() will normalize a vector (it will modify vector, so don’t do this directly on velocity).

    Add Drag

    Start with the work from yesterday (but make a new sketch and submission). Add drag to your simulation as follows:

    • Add PVector getDragForce(float coef) to the Orb class. It should calculate and return a PVector representing drag as described above.
    • draw()
      • When an Orb reaches a height of 200 or more, calculate and apply a drag force.
      • Draw a rectangle from (0, 200) that takes up the lower half of the screen to help see when the drag force should be applied.

    Reference Image:

    a08-drag


  • Work 06: That's Not How the Force Works

    Due: Wednesday 3/5 :00am

    Submission name: w06_forcerunner

    Use the Force

    Start with the code developed in class (available in thesource). You will modify the driver file to produce a more complex simulation as follows:

    • Create an array of Orb objects.
    • Create two forces as PVector objects, gravity and wind.
    • setup()
      • Make the gravity and wind forces <0, 0>.
      • Create at least 5 Orb objets. They should all have the same y coordinate, x values that keep them from overlapping and random sizes in the range [10, 60).
    • draw()
      • Display all the Orb objects in the array.
      • Display the current values of the gravity and wind forces.
      • If moving is true, apply gravity and wind to all the Orb objects, then call run() on each.
    • keyPressed()
      • Left/Right arrows: Change the x direction of wind in 0.1 incriments.
      • Up/Down arrows: Change the y direction of gravity in 0.1 incriments.
      • Space: Toggle moving on/off.

    Reference Image:

    a07-force


  • Lab 01: Something seems Fishy

    Due: Monday 3/3 10:00am

    Read the instructions in the code and write the requested code.

    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.
    14. Using Objects Can declare and Object variable and instantiate an Object using a constructor. Can use multiple Objects in a program by calling methods on appropriately declared and instantiated Object variables. Can use Objects in a program, describe how reference variables work, and how they are different from primitive variables. Can use Objects and accurately make heap diagrams of Object variables and data.
    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 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 of MovingOrganism). To start, the subclass may only differ from MovingOrganism 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 in display(). There is a processing class called PImage 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.


  • 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

    Read the instructions in the code and write the requested code.

    l00-shapes

    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 and sumY 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\) with 0. 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 the x and y values of the centroid.
    • 1 new method
      • void setCentroid()
        • Sets the centroid instance variable.
    • 2 modified methods
      • display
        • Draws a circle of diameter 5 at the centroid. Use a different color than the inside instance variable.
      • makeRandomShape() or the Constructor
        • call setCentroid() after setArea()

    Create a Septagon Class

    A Septagon is a seven sided polygon. Create a Septagon subclass of Polygon that only contains code that maintains the seven-sidedness of the polygons.

    a03-pathcentroid


  • 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\) with 0. 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 from thesource (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.
    • Modified method:
      • void makeRandomShape()
        • Call setArea() after the points are made.
        • Set inside to magenta (255, 0, 255) if area is less than shapeSize and cyan (0, 255, 255) is area is greater than shapeSize.
    • Verify that the above changes have been added to Polygon, if not, add code to Polygon where needed.

    a02-patharea


  • Work 01: Shaping Your Path

    Due: Friday 1/31 10:00am

    Submission name: w01_pathShape

    Step 0: Create your new work repository:

    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 form thesource repository.

    A PathShape will have the following instance variables:

    • ArrayList<PVector> points; An ArrayList of PVector 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 and y instance variables.
    • 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 to ss.
      • Sets inside to a color of your chosing.
      • Initializes points and calls makeRandomShape() (see below).
    • void makeRandomShape()
      • Adds np random points to points by calling makeRandomPoint()
      • The shape need not be a polygon.
    • PVector makeRandomPoint()
      • Returns a new PVector object where the x and y values will always be within the square area that defines the calling PathShape object.
    • display()
      • Use beginShape, vertex and endshape to draw the PathShape 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.

    If done correctly, the provided driver file that will create 4 PathShape objects to be displayed in a grid like so:

    a00-pathgrid


  • Work 00: Getting to Know You

    Due: Thursday 1/30 10:00am

    1. Please fill out the student info form found here: https://forms.gle/guk6e8bcYMtGFAj99