From e4bd478c01c776fdccb17d7fdf4d7177241e315c Mon Sep 17 00:00:00 2001 From: Hans-Gert Dahmen Date: Sun, 27 Dec 2009 00:55:03 +0000 Subject: [PATCH] added improved flyingdots to repo --- animations/flyingdots.c | 73 +++++++++++++++++++++++++++++++++++++++++ animations/flyingdots.h | 7 ++++ 2 files changed, 80 insertions(+) create mode 100644 animations/flyingdots.c create mode 100644 animations/flyingdots.h diff --git a/animations/flyingdots.c b/animations/flyingdots.c new file mode 100644 index 0000000..041e460 --- /dev/null +++ b/animations/flyingdots.c @@ -0,0 +1,73 @@ +#include +#include "../config.h" +#include "../random/prng.h" +#include "../pixel.h" +#include "../util.h" + +//dots flying from left to right +void flyingdots() +{ + uint8_t rowbuffer[NUM_ROWS], i, j; + pixel p; + + clear_screen(0); + + //set the pixels to the leftmost columns + p.x = NUM_COLS-1; + + //clear rowbuffer + for(i = 0; i < NUM_ROWS; i++) + { + rowbuffer[i] = 0; + } + + //produce 200 dots + for (i = 0; i < 200; i++) + { + //the idea is to use a buffer for one row + //first all pixels that are in the rowbuffer + //will be reduced in brightness + //(as you can assume that they were + // drawn in the last round and need to be dimmed + // to produce the trail effect) + //and then a new one will be added + //finally the rowbuffer is drawn + + //loop through all pixels in our rowbuffer + for(j = 0; j < NUM_ROWS; j++) + { + //add a trail or remove the pixel, if it was bright enough + if(rowbuffer[j] > 0) + { + rowbuffer[j]--; + } + } + + //choose row and brightness + p.y = random8() % NUM_ROWS; + rowbuffer[p.y] += (random8() % (NUMPLANE)) + 1; + + //cap max brightness + if(rowbuffer[p.y] > NUMPLANE) + { + rowbuffer[p.y] = NUMPLANE; + } + + //draw all pixels in our rowbuffer + for(j = 0; j < NUM_ROWS; j++) + { + if(rowbuffer[j] > 0) + { + p.y = j; + setpixel(p, rowbuffer[j]); + } + } + + //shift the picture right + //(yes, shift_pixmap_l shifts the picture right) + shift_pixmap_l(); + + //wait a bit + wait(100); + } +} diff --git a/animations/flyingdots.h b/animations/flyingdots.h new file mode 100644 index 0000000..3ab73ab --- /dev/null +++ b/animations/flyingdots.h @@ -0,0 +1,7 @@ +#ifndef FLYINGDOTS_H_ +#define FLYINGDOTS_H_ + +// dots fly from left to right +void flyingdots(); + +#endif /* FLYINGDOTS_H_ */