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 and the Math.random worksheet helpful. Here are some steps to get you started:
- Start by forking this repository.
- Open the Lightning.pde file. You'll need to add some code
At the top of the program, declare 4
endXto 0 and
void setup()needs to set the
background()of your applet
void draw()needs to do two things:
stroke()color of the lightning bolt to some random value using
whileloop that repeats the following until the
endXis off the screen:
startXplus a random integer from 0 to 9
startYplus a random integer from -9 to 9
- draw a
void mousePressed()needs to set
endYback to their original values.
- You will need to modify
index.htmlto 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 submit the URL for your website to google classroom. Don't hesitate to ask for help if your aren't sure how something is suppose to work.
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!
Samples of Student Work