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. You may find the PowerPoint sides 142 to 170 of the apjava1.pptx presentation helpful. Here are some steps to get you started:
- Fork and clone down the repository. You should now have a Lightning folder in your apjava folder. Open the Lightning folder in Sublime.
- Click on Lightning.pde. You'll need to add some code
At the top of the program, declare 4
intvariablesstartX,startY,endXandendY. InitializestartXto 0,startYto 150,endXto 0 andendYto 150 void setup()needs to set thestrokeWeight()andbackground()of your appletvoid draw()needs to do two things:
-set thestroke()color of the lightning bolt to some random value usingMath.random()
-awhileloop that repeats the following until theendXis off the screen:- set
endXtostartXplus a random integer from 0 to 9 - set
endYtostartYplus a random integer from -9 to 9 - draw a
line()with endpointsstartX,startY,endX,endY - set
startXto equalendXandstartYto equalendY
- set
void mousePressed()needs to setstartX,startY,endX,endYback to their original values.- You will need to modify
index.htmlto customize your website with it's own title, header and footer. When you are happy with your program, push your finished project up to GitHub - The final step is to submit the URL for your website via the "drop box" for the assignment on School Loop. Don't hesitate to ask for help if your aren't sure how something is suppose to work.
Jeanette
Aliya
Skylar
Thien
Winnie
Jessie
Eric
Aidan
Helen
Yang
Ivan
Brian
Leif
David
Brandon
Dexter
Rebecca
Sammy
Lawrence
Andrew
Melody
Marvin
Matthew
Alicia
Elliott
Evan
Reesa
Stephan
Caleb
Steven
Justin
Abhay
Skylar
Anthony