-
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
int
variables:startX
,startY
,endX
andendY
. void setup()
needs to:- Set the variables to an initial value
startX
to 0,startY
to 150,endX
to 0 andendY
to 150startX
to 0,startY
to 150,endX
to 0endY
to 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
while
loop that repeats the following steps until theendX
is 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
startX
equal toendX
- set
startY
equal toendY
- set
- set the
- Create a
void mousePressed()
method. The method needs to:- set
startX
,startY
,endX
,endY
back to their initial values.
- set
- You will need to modify
index.html
to 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!