first version of the DNA-Animation

This commit is contained in:
Stefan Kinzel 2014-08-14 22:35:03 +02:00
parent 1dff4f3885
commit da9d0adc57
5 changed files with 173 additions and 0 deletions

View File

@ -58,6 +58,11 @@ ifeq ($(ANIMATION_TIME),y)
SRC += borg_time.c SRC += borg_time.c
endif endif
ifeq ($(ANIMATION_DNA),y)
SRC += dna.c
endif
include $(MAKETOPDIR)/rules.mk include $(MAKETOPDIR)/rules.mk
include $(MAKETOPDIR)/depend.mk include $(MAKETOPDIR)/depend.mk

View File

@ -64,6 +64,8 @@ comment "Animations"
bool "Black Hole" ANIMATION_BLACKHOLE bool "Black Hole" ANIMATION_BLACKHOLE
bool "DNA" ANIMATION_DNA $RANDOM_SUPPORT
dep_bool "Squares" ANIMATION_SQUARES $RANDOM_SUPPORT dep_bool "Squares" ANIMATION_SQUARES $RANDOM_SUPPORT
comment "Special Animations" comment "Special Animations"

145
src/animations/dna.c Normal file
View File

@ -0,0 +1,145 @@
#include "../config.h"
#include <stdint.h>
#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;
}
}
}
}
}

14
src/animations/dna.h Normal file
View File

@ -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_ */

View File

@ -7,6 +7,7 @@
#include "animations/snake.h" #include "animations/snake.h"
#include "animations/program.h" #include "animations/program.h"
#include "animations/matrix.h" #include "animations/matrix.h"
#include "animations/dna.h"
#include "animations/gameoflife.h" #include "animations/gameoflife.h"
#include "animations/stonefly.h" #include "animations/stonefly.h"
#include "animations/flyingdots.h" #include "animations/flyingdots.h"
@ -291,6 +292,12 @@ void display_loop(){
break; break;
#endif #endif
#ifdef ANIMATION_DNA
case 40:
dna();
break;
#endif
#ifdef MENU_SUPPORT #ifdef MENU_SUPPORT
case 42: case 42:
mode = 1; mode = 1;