Browse Source

Merge pull request #2 from stefanctdo/master

fixed DNA-Animation for variable screen sizes
feature/2015
Christian Kroll 10 years ago
parent
commit
74e19084cc
  1. 85
      src/animations/dna.c

85
src/animations/dna.c

@ -3,36 +3,35 @@
#include "../random/prng.h" #include "../random/prng.h"
#include "../pixel.h" #include "../pixel.h"
#include "../util.h" #include "../util.h"
#include "../compat/pgmspace.h"
#define HEIGHT 12
#define LINE_DISTANCE 4 #define LINE_DISTANCE 4
#define SIN_LENGTH 18 #define SINTAB_LENGTH 16
#define SIN_MAX 6 #define SIN_MAX 6
// uint8_t sin[SIN_LENGTH] = {0, 1, 2, 2, 3, 3, 4, 4, 4, 3, 3, 3, 2, 2, 1, 0}; // lolshield etc.
#define SMALL (NUM_ROWS < 10)
uint8_t sintab[SIN_LENGTH] = { #define PGM(x) pgm_read_byte(&(x))
0,
1, uint8_t sintab_base[SINTAB_LENGTH] =
2, {
3, 0, // 0
4, 14,
5, 18, // 1
5, 24,
6, 28, // 2
6, 32,
6, 36, // 2
6, 42,
6, 44, // 3
5, 46,
5, 50, // 3
4, 52,
3, 56, // 4
2, 60,
1, 62, // 4
}; 64
};
/** /**
* Shifts the Pixmap one px right * Shifts the Pixmap one px right
@ -54,8 +53,18 @@ static void move(){
} }
} }
void dna(){ void dna(){
uint8_t mid = NUM_COLS / 2;
uint8_t height = NUM_ROWS * 3 / 4 ;
// small screen: bigger helix
if(SMALL){
height = NUM_ROWS;
}
uint8_t sin_length = 16;
uint8_t mid = NUM_ROWS / 2;
uint8_t draw_line = 0; uint8_t draw_line = 0;
uint8_t top = 0; uint8_t top = 0;
@ -65,13 +74,27 @@ void dna(){
uint8_t bottom_color = 2; uint8_t bottom_color = 2;
uint32_t c = 600; uint32_t c = 600;
uint8_t sintab[sin_length];
uint8_t sinpos = 0; uint8_t sinpos = 0;
int8_t direction = 1; int8_t direction = 1;
// disable up- and down-movement on small screens
if(SMALL){
direction = 0;
}
clear_screen(0); clear_screen(0);
/* calculate sinus wave */
for(int i = 0; i < sin_length / 2; i++){
int index = i * SINTAB_LENGTH * 2 / sin_length;
sintab[i] = sintab_base[index] * height / 128;
sintab[sin_length - i - 1] = sintab[i];
}
while(c--){ while(c--){
top = mid - sintab[sinpos]; top = mid - sintab[sinpos];
bottom = mid + sintab[sinpos]; bottom = mid + sintab[sinpos];
@ -86,18 +109,18 @@ void dna(){
setpixel((pixel){NUM_COLS-1, mid}, 1); setpixel((pixel){NUM_COLS-1, mid}, 1);
} }
if(sinpos == 0){ if(sinpos == sin_length-1){
if(mid-SIN_MAX <= 0){ if(mid-SIN_MAX <= 0 && direction){
direction = 1; direction = 1;
} }
if(mid+SIN_MAX >= NUM_ROWS-1){ if(mid+SIN_MAX >= NUM_ROWS-1 && direction){
direction = -1; direction = -1;
} }
mid = mid + (random8() > 200) * direction; mid = mid + (random8() > 200) * direction;
} }
draw_line = (draw_line+1) % LINE_DISTANCE; draw_line = (draw_line+1) % LINE_DISTANCE;
sinpos = (sinpos + 1) % SIN_LENGTH; sinpos = (sinpos + 1) % sin_length;
if(sinpos == 0){ if(sinpos == 0){
uint8_t tmp_color = top_color; uint8_t tmp_color = top_color;

Loading…
Cancel
Save