Posted: Fri Sep 18
Due: Tuesday 9/22 10:00am
Submission name: w05_lightning
Important notes:
- On Tuesday, we will have a quiz, the quiz will cover:
- Variable types
- Writing functions
For this assignment, you may want to refer to:
- Processing’s documentation for
while - Processing’s documentation for
random- It is important to note that
randomreturns afloat, butlineonly works withintarguments. To convert you can do this:int(random(0, 10)).
- It is important to note that

Make a lightning function
Write drawLightning:
- Use the following function header:
void drawLightning(int x, int y, int numParts) - The function should draw
numPartsconnected lines starting at(x, y). - Each line should start at the previous
(x, y)coordinates and end at random coordinates with the following restrictions:- The next x coordinate should be an
intin the range[x - 5, x + 5). - The next y coordinate should add a random
intin the range[y + 5, y + 20).
- The next x coordinate should be an
- Use a
whileloop to draw the appropriate number of lines. Do not worry if your lightning bolt goes past the bottom of the screen or doesn’t make it all the way.
Write a setup function
setup should:
- Set the screen size to 500x500.
- Run
drawLightningat least 5 times.
Optional modifications
- Play around with
strokeandstrokeWeightto make better looking lightning bolts. - Use
randomin conjunction withstrokeandstokeWeight - Add other features to make the image more interesting.
- If you create an interesting lightning image, save it (as a
pngorjpeg), and share it on piazza, use the tagnextjourney.