Due: Friday 09/20 10:00am
Submission name: w07_lightning
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
random
returns afloat
, butline
only works withint
arguments. 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
numParts
connected 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
int
in the range[x - 5, x + 5)
. - The next y coordinate should add a random
int
in the range[y + 5, y + 20)
.
- The next x coordinate should be an
- Use a
while
loop 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
drawLightning
at least 5 times.
Optional modifications
- Play around with
stroke
andstrokeWeight
to make better looking lightning bolts. - Use
random
in conjunction withstroke
andstokeWeight
- Add other features to make the image more interesting.
- If you create an interesting lightning image, save it (as a
png
orjpeg
), and share it on piazza, use the tagnextjourney
.