From da9d0adc57ea4289ae1e2abddb690cb0583f8758 Mon Sep 17 00:00:00 2001 From: Stefan Kinzel Date: Thu, 14 Aug 2014 22:35:03 +0200 Subject: [PATCH] first version of the DNA-Animation --- src/animations/Makefile | 5 ++ src/animations/config.in | 2 + src/animations/dna.c | 145 +++++++++++++++++++++++++++++++++++++++ src/animations/dna.h | 14 ++++ src/display_loop.c | 7 ++ 5 files changed, 173 insertions(+) create mode 100644 src/animations/dna.c create mode 100644 src/animations/dna.h diff --git a/src/animations/Makefile b/src/animations/Makefile index 585edb9..8595a08 100644 --- a/src/animations/Makefile +++ b/src/animations/Makefile @@ -58,6 +58,11 @@ ifeq ($(ANIMATION_TIME),y) SRC += borg_time.c endif +ifeq ($(ANIMATION_DNA),y) +SRC += dna.c +endif + + include $(MAKETOPDIR)/rules.mk include $(MAKETOPDIR)/depend.mk diff --git a/src/animations/config.in b/src/animations/config.in index 7f9d88c..f41c9f3 100644 --- a/src/animations/config.in +++ b/src/animations/config.in @@ -63,6 +63,8 @@ comment "Animations" endmenu bool "Black Hole" ANIMATION_BLACKHOLE + + bool "DNA" ANIMATION_DNA $RANDOM_SUPPORT dep_bool "Squares" ANIMATION_SQUARES $RANDOM_SUPPORT diff --git a/src/animations/dna.c b/src/animations/dna.c new file mode 100644 index 0000000..22ab6b9 --- /dev/null +++ b/src/animations/dna.c @@ -0,0 +1,145 @@ +#include "../config.h" +#include +#include "../random/prng.h" +#include "../pixel.h" +#include "../util.h" + + +#define HEIGHT 12 +#define LINE_DISTANCE 4 +#define SIN_LENGTH 16 + +// uint8_t sin[SIN_LENGTH] = {0, 1, 2, 2, 3, 3, 4, 4, 4, 3, 3, 3, 2, 2, 1, 0}; + +uint8_t sintab[SIN_LENGTH] = { + 1, + 2, + 3, + 4, + 5, + 5, + 6, + 6, + 6, + 6, + 6, + 5, + 5, + 4, + 3, + 2, + }; + +/* +uint8_t sintab[SIN_LENGTH] = { +1, +1, +2, +2, +3, +3, +4, +4, +5, +5, +5, +5, +6, +6, +6, +6, +6, +6, +6, +6, +6, +5, +5, +5, +5, +4, +4, +3, +3, +2, +2, +1, +}; +*/ + +void dna(){ + uint8_t mid = NUM_COLS / 2; + uint8_t draw_line = 0; + + uint8_t top = 0; + uint8_t bottom = 0; + + uint8_t top_color = 3; + uint8_t bottom_color = 2; + + uint32_t c = 10000; + + uint8_t sinpos = 0; + + uint8_t direction = 1; + + while(c--){ + top = mid - sintab[sinpos]; + bottom = mid + sintab[sinpos]; + + setpixel((pixel){15,top}, top_color); + setpixel((pixel){15,bottom}, bottom_color); + + if(draw_line == 0){ + for(uint8_t linex = top+1; linex < bottom; linex++){ + setpixel((pixel){15, linex}, 1); + } + setpixel((pixel){15, mid}, 1); + } + + if(draw_line == 0){ + if(top <= 1){ + direction = 1; + } + if(bottom >= NUM_ROWS-1){ + direction = -1; + } + mid = mid + (random8() > 240) * direction; + } + + draw_line = (draw_line+1) % LINE_DISTANCE; + sinpos = (sinpos + 1) % SIN_LENGTH; + + if(sinpos == 0){ + uint8_t tmp_color = top_color; + top_color = bottom_color; + bottom_color = tmp_color; + } + + move(); + + wait(40); + } + + +} + +/** + * Shifts the Pixmap one px right + */ +void move(){ + unsigned char plane, row, byte; + + for(plane=0; plane<=NUMPLANE; plane++){ + for(row=NUM_COLS;row>0; row--){ + for(byte=0; byte < LINEBYTES; byte++){ + pixmap[plane][row][byte] = pixmap[plane][row][byte] >> 1; + if(byte < LINEBYTES-1){ + pixmap[plane][row][byte] = + pixmap[plane][row][byte] | + (pixmap[plane][row][byte+1] & 0b00000001) << 7; + } + } + } + } +} diff --git a/src/animations/dna.h b/src/animations/dna.h new file mode 100644 index 0000000..d54faee --- /dev/null +++ b/src/animations/dna.h @@ -0,0 +1,14 @@ +/* + * dna.h + * + * Created on: 15.07.2014 + * Author: stefan + */ + +#ifndef DNA_H_ +#define DNA_H_ + +void dna(); +void move(); + +#endif /* DNA_H_ */ diff --git a/src/display_loop.c b/src/display_loop.c index 42929e2..0735dd2 100644 --- a/src/display_loop.c +++ b/src/display_loop.c @@ -7,6 +7,7 @@ #include "animations/snake.h" #include "animations/program.h" #include "animations/matrix.h" +#include "animations/dna.h" #include "animations/gameoflife.h" #include "animations/stonefly.h" #include "animations/flyingdots.h" @@ -291,6 +292,12 @@ void display_loop(){ break; #endif +#ifdef ANIMATION_DNA + case 40: + dna(); + break; +#endif + #ifdef MENU_SUPPORT case 42: mode = 1;