-
Start by accepting the assignment. (Done if you are reading this).
-
Next clone the project on your laptop.
-
Work through Math.random worksheet first. I have blank print outs at my desk. Put any sample code you use to complete the worksheet inside of a class called RandomPractice.java of this project directory. Be sure to git commit this work along with our Lightning Bolt Project.
-
Work on the random walk assignment:
One way to simulate lightning is with a random walk. In this assignment you will create a program that uses a random walk to seemingly shoot lightning from one side of the screen to the other every time the mouse is pressed.
- Open the Lightning.pde file in Processing (it is located in the Lightning directory).
- At the top of the program, declare 4
intvariables:startX,startY,endXandendY. void setup()needs to:- Set the variables to an initial value
startXto 0,startYto 150,endXto 0 andendYto 150startXto 0,startYto 150,endXto 0endYto 150
- set the
strokeWeight()andbackground()of your app.
- Set the variables to an initial value
void draw()needs to do two things:- set the
stroke()color of the lightning bolt to some random value usingMath.random() - Create a
whileloop that repeats the following steps until theendXis off the screen (translate the following instructions to java code in the order for which they appear).- set
endX=startX+ a random integer from 0 to 9 - set
endY=startY+ a random integer from -9 to 9 - draw a
line()with endpointsstartX,startY,endX,endY - set
startXequal toendX - set
startYequal toendY
- set
- set the
- Create a
void mousePressed()method. The method needs to:- set
startX,startY,endX,endYback to their initial values.
- set
- You will need to modify
index.htmlto customize your website with it's own title, headline and footer. When you are happy with your program, push your finished project up to GitHub - The final step is to update your portfolio with references to this project, just like you did for
Coat of Arms
Your program needs to create a random walk using Math.random() for all random numbers in the assignment. Other than that, your lightning program doesn't have to work or look like any other. Have fun and be creative!