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.
- Start by forking this repo.
- Watch this Shiffman video about the random() function.
- Open the Lightning.pde file. 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 sketchvoid draw()needs to do two things:
- set the
stroke()color of the lightning bolt to some random value usingrandom() - a
whileloop 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
startXequal toendX - set
startYequal toendY
- set
void mousePressed()needs to setstartX,startY,endX,endYback to their original values.- This is one of the most important steps! If we all stopped here, everybody's lightning would look the same. That's no fun. In this step you'll make your lightning unique. Take your time on this step, be creative, and make yours look different from anyone else's! Below are some examples of other students' work. Browse those for ideas.
- When you've got a good draft, ask a colleague for feedback. Incorporate that feedback and give that person credit with a comment in your code.
- Submit your assignment. (How? Click here.)
Michelle
Janet
Elton
Clovis
Wilson
Edmund
Gina
Gordon
Sophie
Brandon
Amanda
Kevin
Robert
Jenny
Eric
Darren
Sam
Maxwell
Desmond
Michelle
Vivian
Brandon
Jenna
Otto
Lydia
Victor
Ben
Elias
Steven
Andrea
Nicolas
Kenneth
Schuyler
Nghi
Jonathan
Erica
Aaron
Kendra
Heath
Brandon
Oliva
Emily
Joanna
Kirby
Michael
Jun
Makoi
Emma
Andrew
Nicolas
Kyle
Dean
Nathan
Hannah
Yolanda
Colin
Samantha
Jenny
Preston
Thanawat
Ryan
Kenny
Bryan
Andrew
Felix
Steven
Yev
Andrew
Mike
Jalen
Jessica
Kelly
Raymond
Wilson
Bryce
Garvin
Mi-Ka
Tatiana
Karen
Mikayla
Eric
Katie
Joshua