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 twopublicfields,xandy. So we can treat aPVectorobject like a point.pointsis an array that will store all the points of the bolt.numPointsin the constructor should be the size of the array.currentPointShould represent how far down the lightning bolt we are drawing. It should start at0and increase by1each timedisplayis called.populateshould populatepointswithPVectorobjects. The first point should have a randomxvalue and ayvalue of0. Each subsequent point should:- Add a random value in the range
[-15, 15]to the previousxvalue. - Add a random value in the range
[5, 20]to the previousyvalue.
- Add a random value in the range
displayshould draw the lightning bolt up tocurrentPoint. Do not allow this method to generate anIndexOutOfBoundsexception.fullBoltshould draw the entire bolt.isCompleteshould return whether the entire bolt would be drawn whendisplayis 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.