Posted: Fri Nov 13

Due: Monday 11/16 10:00am

Submission name: w24_lightning

Test Monday:

Skills covered:

  • 14: Using Objects
  • 15: Writing Classes
  • 25: OOP Principles

Trip Down Memory Lane

Way back in September, you wrote a program that drew lightning bolts on the screen. Today, you’ll make it better with the power of ~friendship~ objects. You should start by looking back over the lightning code to refresh your memory of how we drew the lightning bolts.

Lightning class:

classDiagram class Lightning { -PVector[] points -int currentPoint +Lightning(int numPoints) -void populate() +void display() +void fullBolt() -boolean isComplete() }
  • PVector (https://processing.org/reference/PVector.html) is a processing provided class that can be3 used for many thigns. Right now though, it’s useful since it has two public fields, x and y. So we can treat a PVector object like a point.
  • points is an array that will store all the points of the bolt. numPoints in the constructor should be the size of the array.
  • currentPoint Should represent how far down the lightning bolt we are drawing. It should start at 0 and increase by 1 each time display is called.
  • populate should populate points with PVector objects. The first point should have a random x value and a y value of 0. Each subsequent point should:
    • Add a random value in the range [-15, 15] to the previous x value.
    • Add a random value in the range [5, 20] to the previous y value.
  • display should draw the lightning bolt up to currentPoint. Do not allow this method to generate an IndexOutOfBounds exception.
  • fullBolt should draw the entire bolt.
  • isComplete should return whether the entire bolt would be drawn when display is called.

Driver

The driver should have a single Lightning global variable with an object instantiated during setup. draw should draw the lightning bolt, and if the bolt is complete, make a new one.