2008-12-03 05:40:16 +00:00
|
|
|
|
|
|
|
#include "../config.h"
|
2011-10-28 23:42:20 +00:00
|
|
|
#include <stdint.h>
|
2008-12-03 05:40:16 +00:00
|
|
|
#include "../random/prng.h"
|
|
|
|
#include "../pixel.h"
|
|
|
|
#include "../util.h"
|
|
|
|
|
2011-10-28 23:42:20 +00:00
|
|
|
#ifndef MATRIX_CYCLES
|
|
|
|
#define MATRIX_CYCLES 500
|
|
|
|
#endif
|
|
|
|
#ifndef MATRIX_STREAMER_NUM
|
|
|
|
#define MATRIX_STREAMER_NUM 30
|
|
|
|
#endif
|
2011-12-04 08:03:19 +00:00
|
|
|
#ifndef MATRIX_DELAY
|
|
|
|
#define MATRIX_STREAMER_NUM 60
|
|
|
|
#endif
|
2008-12-03 05:40:16 +00:00
|
|
|
|
|
|
|
typedef struct{
|
|
|
|
pixel start;
|
|
|
|
unsigned char len;
|
|
|
|
unsigned char decay;
|
|
|
|
unsigned char index;
|
|
|
|
unsigned char speed;
|
|
|
|
} streamer;
|
|
|
|
|
|
|
|
typedef uint8_t pixel_matrix_t[NUM_COLS][NUM_ROWS/4];
|
|
|
|
|
|
|
|
inline static uint8_t get_bright(pixel_matrix_t *matrix, uint8_t x, uint8_t y){
|
|
|
|
uint8_t ret;
|
|
|
|
ret = (*matrix)[x][y/4];
|
|
|
|
return 0x3&(ret>>(2*(y%4)));
|
|
|
|
}
|
|
|
|
|
|
|
|
inline static void set_bright(pixel_matrix_t *matrix, uint8_t x, uint8_t y, uint8_t value){
|
|
|
|
uint8_t t;
|
|
|
|
t = (*matrix)[x][y/4];
|
|
|
|
t &= ~(0x3<<(2*(y%4)));
|
|
|
|
t |= value<<(2*(y%4));
|
|
|
|
(*matrix)[x][y/4] = t;
|
|
|
|
}
|
|
|
|
|
|
|
|
void matrix() {
|
2011-10-28 23:42:20 +00:00
|
|
|
unsigned int counter = MATRIX_CYCLES;
|
|
|
|
streamer streamers[MATRIX_STREAMER_NUM];
|
2008-12-03 05:40:16 +00:00
|
|
|
pixel_matrix_t matrix_bright;
|
|
|
|
unsigned char x, y;
|
|
|
|
unsigned char index = 0;
|
|
|
|
unsigned char draw;
|
|
|
|
unsigned char streamer_num = 0;
|
|
|
|
|
|
|
|
while(counter--){
|
|
|
|
unsigned char i, j;
|
|
|
|
/* initialise matrix-buffer */
|
|
|
|
for(x=0;x<NUM_COLS;x++)
|
|
|
|
for(y=0;y<NUM_ROWS/4;y++)
|
|
|
|
matrix_bright[x][y]=0;
|
2011-10-28 23:42:20 +00:00
|
|
|
|
2008-12-03 05:40:16 +00:00
|
|
|
for(i=0;i<streamer_num;i++){
|
|
|
|
streamer str = streamers[i];
|
2011-10-28 23:42:20 +00:00
|
|
|
|
2008-12-03 05:40:16 +00:00
|
|
|
unsigned char bright = 0xFF; draw = 0;
|
|
|
|
for(j=(str.len/8);j!=0xFF;j--){ /* Draw streamer */
|
|
|
|
if(j+str.start.y<NUM_ROWS){
|
|
|
|
if(bright>>6) /* bright>>6 */
|
|
|
|
draw = 1;
|
|
|
|
if(bright > (get_bright(&matrix_bright, str.start.x, str.start.y+j)<<6) ){
|
|
|
|
set_bright(&matrix_bright, str.start.x, str.start.y+j, bright>>6);
|
2011-10-28 23:42:20 +00:00
|
|
|
|
2008-12-03 05:40:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
bright-=((bright>>5)*str.decay);
|
|
|
|
}
|
2011-10-28 23:42:20 +00:00
|
|
|
|
2008-12-03 05:40:16 +00:00
|
|
|
str.len+=str.speed/2;
|
|
|
|
streamers[i] = str;
|
|
|
|
if(!draw){
|
|
|
|
for(j=i;j<streamer_num-1;j++){
|
|
|
|
streamers[j] = streamers[j+1];
|
|
|
|
}
|
|
|
|
streamer_num--;
|
|
|
|
i--;
|
2011-10-28 23:42:20 +00:00
|
|
|
}
|
2008-12-03 05:40:16 +00:00
|
|
|
}
|
2011-10-28 23:42:20 +00:00
|
|
|
|
2011-01-30 22:47:44 +00:00
|
|
|
for(y=NUM_ROWS;y--;)
|
|
|
|
for(x=NUM_COLS;x--;){
|
2008-12-03 05:40:16 +00:00
|
|
|
setpixel((pixel){x,y}, get_bright(&matrix_bright,x,y));
|
|
|
|
}
|
2011-10-28 23:42:20 +00:00
|
|
|
|
2008-12-03 05:40:16 +00:00
|
|
|
unsigned char nsc;
|
|
|
|
for(nsc=0;nsc<6;nsc++){
|
2011-10-28 23:42:20 +00:00
|
|
|
if(streamer_num<MATRIX_STREAMER_NUM){
|
2008-12-03 05:40:16 +00:00
|
|
|
unsigned char sy = random8()%(2*NUM_ROWS);
|
|
|
|
if (sy>NUM_ROWS-1) sy=0;
|
|
|
|
streamers[streamer_num] = (streamer){{random8()%NUM_COLS, sy}, 0, (random8()%8)+12, index++,(random8()%16)+3};
|
2011-10-28 23:42:20 +00:00
|
|
|
streamer_num++;
|
2008-12-03 05:40:16 +00:00
|
|
|
}
|
|
|
|
}
|
2011-10-28 23:42:20 +00:00
|
|
|
wait(60);
|
|
|
|
|
2008-12-03 05:40:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|