Basic Lightning Theory

03 Apr 2015

Tags: lightning theory visual python pygame

Introduction

Every good game needs good visual effects. Here is how to do basic lightning. This only covers 2D lightning, but you could easily extend this to 3D.

The Good Stuff

Define 2 points, A and B.

A B Sorry, your browser does not support inline SVG.

Draw a line to link the 2 points up.

A B Sorry, your browser does not support inline SVG.

Find the middle of the line AB, and mark it (M).

A B M Sorry, your browser does not support inline SVG.

Add a displacement to the coordinates of M (should be random), then link AM and MB together. In this case, M is displaced (-18, -13) to create M’.

A B M M' Sorry, your browser does not support inline SVG.

Are You Done?

Congratulations! You’ve got the basics! Now, just rinse and repeat with your new lines AM’ and M’B! Recursion works wonders, doesn’t it! Here is an implementation of this basic lightning thingy in Python and pygame!

This little thing has the lightning originate from the middle of the window and arc out to attack your cursor if you click on the screen. I made this to test the lightning concept for a tower defense game that I was inspired to create.