Comet Tail
In this lesson we will make a pattern of light like a comet tail. The comet will consist of about 5 to 10 pixels in a row and move across the strip by shifting the offset by a single pixel and then redrawing the comet.
The Draw Comet Tail Function
Our first task is to draw a single comet tail that will make the head of the comet bright (225) and slowly decrease the brightness behind the head of the comet. In general, each pixel will be half as bright and the prior pixel.
The "levels" of brightness can be stored in a list or calculated. Our list will look like this:
1 2 |
|
Our function will have three parameters:
- The offset from pixel 0
- The color to draw the pixel as a tuple of three integers
- The delay between the draws which will control the speed that the comet appears to move down the strip
Here is an example of this function:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
The most complex line is this one:
1 |
|
This line sets the RGB values of the target. It must take the color values that are passed in as parameters and scale them for the current brightness of the tail of the comet. After it does the multiplication, it must use the int()
function to round the value to the nearest integer.
Full Program
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
|