Skip to content

chandrunarayan/Lightning

Repository files navigation

Lightning Project for CPJava Class

Lightning Project Details

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 canvas to the other every time the mouse is pressed. We will create many variations of this assignment to shoot the lightning in multiple directions, it may not even be lightning, it could be a Light Sabre! We might get lightning to strike building with pointy roofs - the permutations are endless! You may find this presentation helpful in completing the Lightning Project

Suggested steps to start the assignment

  1. Sign up for a free GitHub account. You might have already done this, please check with me. Please send me your username for Github via Slack.

  2. Complete the Github and While Loops primer before attempting this project. It has important information that will be useful for this and future Procssing projects!

  3. Then fork this repository. The Fork Button is on the Top-Right of this page. The Java Processing Slideshow has details on how to fork this repository and edit files.

  4. Open the Lightning.pde file. Copy and paste the code into Processing.

  5. At the top of the program in Processing, declare 4 int variables startX, startY, endX and endY. Initialize startX to 0, startY to 150, endX to 0 and endY to 150

  6. void setup() needs to set the size(), strokeWeight() and background() of your program

  7. void draw() needs to do two things:

    A. set the stroke() color of the lightning bolt to some random value using Math.random()

    B. while loop that repeats the following until the endX is off the screen:

    • set endX to startX plus a random integer from 0 to 9
    • set endY to startY plus a random integer from -9 to 9
    • draw a line() with endpoints startX,startY,endX,endY
    • set startX equal to endX
    • set startY equal to endY
  8. void mousePressed() needs to set startX,startY,endX,endY back to their original values.

  9. When you are done with the program, copy and paste it back into GitHub

  10. You will also need to modify index.html to customize your website with it's own title, headline and footer.

  11. When you are happy with your program, push your finished project up to GitHub

  12. 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.

Student Submissions of Lightning Project

  • alt text
  • alt text
  • alt text
  • alt text

About

Lightning Project for CPJava

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages