From aa29c51bd85a5ce04908f5e649ec21f6409dac18 Mon Sep 17 00:00:00 2001 From: Christian Kroll Date: Thu, 24 Feb 2011 23:13:01 +0000 Subject: [PATCH] put Martin Herwegs source code into separate files --- animations/Makefile | 4 + animations/config.in | 2 +- animations/mherweg.c | 259 ++++++++++++++++++++++++++++++++++++++++++ animations/mherweg.h | 25 ++++ animations/programm.c | 176 ---------------------------- display_loop.c | 1 + pixel.c | 80 ------------- pixel.h | 12 +- 8 files changed, 294 insertions(+), 265 deletions(-) create mode 100644 animations/mherweg.c create mode 100644 animations/mherweg.h diff --git a/animations/Makefile b/animations/Makefile index e53c98d..344b16f 100644 --- a/animations/Makefile +++ b/animations/Makefile @@ -25,6 +25,10 @@ ifeq ($(ANIMATION_GAMEOFLIFE),y) SRC += gameoflife.c endif +ifeq ($(ANIMATION_MHERWEG),y) + SRC += mherweg.c +endif + ifeq ($(ANIMATION_BREAKOUT),y) SRC += breakout_demo.c endif diff --git a/animations/config.in b/animations/config.in index 6f64de5..2369f48 100644 --- a/animations/config.in +++ b/animations/config.in @@ -12,7 +12,7 @@ comment "Animations" dep_bool "Flying Dots" ANIMATION_FLYINGDOTS $RANDOM_SUPPORT dep_bool "Game of Life" ANIMATION_GAMEOFLIFE $RANDOM_SUPPORT dep_bool "Breakout Demo" ANIMATION_BREAKOUT $GAME_BREAKOUT - bool "Martin Herweg" ANIMATION_MHERWEG + bool "Martin Herweg" ANIMATION_MHERWEG $RANDOM_SUPPORT dep_bool "Langton Ant" ANIMATION_LTN_ANT $RANDOM_SUPPORT dep_bool_menu "Bitmap Scroller" ANIMATION_BMSCROLLER y $RANDOM_SUPPORT diff --git a/animations/mherweg.c b/animations/mherweg.c new file mode 100644 index 0000000..dcdef55 --- /dev/null +++ b/animations/mherweg.c @@ -0,0 +1,259 @@ +#include "../compat/pgmspace.h" +#include "../random/prng.h" +#include "../config.h" +#include "../pixel.h" +#include "../util.h" + + +#define RANDOM8(x) random8(x) +#define PGM(x) pgm_read_byte(&(x)) + + +// straight or non straight line from one point to the other +// value=brightness +static void line(pixel p1, pixel p2, unsigned char value) +{ + char dx, dy, stepx, stepy, fraction; + + dy = p2.y - p1.y; + dx = p2.x - p1.x; + + if (dy < 0) + { + dy = -dy; + stepy = -1; + } + else + { + stepy = 1; + } + + if (dx < 0) + { + dx = -dx; + stepx = -1; + } + else + { + stepx = 1; + } + + dx <<= 1; + dy <<= 1; + + setpixel(p1, value); + if (dx > dy) + { + fraction = dy - (dx >> 1); + while (p1.x != p2.x) + { + if (fraction >= 0) + { + p1.y += stepy; + fraction -= dx; + } + p1.x += stepx; + fraction += dy; + setpixel(p1, value); + } + } + else + { + fraction = dx - (dy >> 1); + while (p1.y != p2.y) + { + if (fraction >= 0) + { + p1.x += stepx; + fraction -= dy; + } + p1.y += stepy; + fraction += dx; + setpixel(p1, value); + } + } +} + + +// filled_rectangle p1=upper right corner, w=width, h=height , +// value=brightness +static void filled_rectangle(pixel p1, + unsigned char w, + unsigned char h, + unsigned char value) +{ + unsigned char y; + for (y = p1.y; y < (p1.y + h); y++) + { + line((pixel){p1.x,y}, (pixel){(p1.x+w-1),y}, value); + } +} + + +void checkbox() +{ + unsigned char x, delay = 250; + + // quadrat aus linien + line((pixel){0, 0}, (pixel){7, 0}, 3); + wait (delay); + line ((pixel){7, 0}, (pixel){7, 7}, 3); + wait (delay); + line ((pixel){7, 7}, (pixel){0, 7}, 3); + wait (delay); + line ((pixel){0, 7}, (pixel){0, 0}, 3); + wait (delay); + + // 2 diagonale lininen + line ((pixel){7, 7}, (pixel){0, 0}, 3); + wait (delay); + line ((pixel){0, 7}, (pixel){7, 0}, 3); + wait (delay * 3); + + for (x = NUM_COLS; x--;) + { + // shift image right + shift_pixmap_l (); + wait (30); + } +} + + +void movinglines() +{ + unsigned char x, y, n; + + line((pixel){NUM_COLS - 1, NUM_ROWS - 1}, (pixel){NUM_COLS - 1, 0}, 3); + + // linie wandert nach rechts + for (x = 0; x < NUM_COLS; x++) + { + shift_pixmap_l (); + wait (100); + } + + // von unten nach oben + for (y = NUM_ROWS; y--;) + { + line ((pixel){0, y}, (pixel){NUM_COLS - 1, y}, 3); + wait (100); + line ((pixel){0, y}, (pixel){NUM_COLS - 1, y}, 0); + //wait(10); + } + + // eine linie von rechts nach links und 1-8 mal von oben nach unten + // je nach display format das ganze 4 mal + for (n = 0; n < 4; n++) + { + for (x = 0; x < NUM_COLS - 1; x++) + { + y = x % NUM_ROWS; + line ((pixel){0, y}, (pixel){NUM_COLS - 1, y}, 3); + line ((pixel){x, 0}, (pixel){x, NUM_ROWS - 1}, 3); + wait (50); + + line ((pixel){0, y}, (pixel){NUM_COLS - 1, y}, 0); + line ((pixel){x, 0}, (pixel){x, NUM_ROWS - 1}, 0); + //wait(10); + } + } +} + + +//rechteckmuster mit helligkeitsstufen +void rectangle1() +{ + unsigned char x, value, xcenter, ycenter, size; + unsigned int delay = 500; + + xcenter = NUM_COLS / 2; + ycenter = NUM_ROWS / 2; + + clear_screen(0); + + size = NUM_ROWS; + value = 3; + + for (x = 8; x > 0; x--) + { + + if (value < NUMPLANE) + value++; + else + value = 0; + + filled_rectangle((pixel){(xcenter - x), (ycenter - x)}, + size, size, value); + wait (delay); + size -= 2; + } + + wait (delay * 3); +} + + +// zufallsrechtecke +void rectangles() +{ + unsigned char value, n, x, y, h, w; + clear_screen(0); + + for (n = 0; n < 60; n++) + { + x = RANDOM8() % NUM_COLS; + y = RANDOM8() % NUM_ROWS; + h = RANDOM8() % NUM_COLS / 2; + w = RANDOM8() % NUM_ROWS / 2; + value = RANDOM8() % (NUMPLANE + 1); + + filled_rectangle((pixel){x, y}, w, h, value); + wait (500 + RANDOM8 () % 3000); + } +} + + +// schräge linien die aufblitzen +void lines1() +{ + line((pixel){0, 15}, (pixel){15, 15}, 3); + wait(10000); + + unsigned char value, n, x, y, h, w; + unsigned int delay = 500; + clear_screen(0); + + for (n = 0; n < 200; n++) + { + x = RANDOM8() % NUM_COLS; + y = RANDOM8() % NUM_ROWS; + h = RANDOM8() % NUM_COLS; + w = RANDOM8() % NUM_ROWS; + value = RANDOM8() % (NUMPLANE + 1); + + line((pixel){x, y}, (pixel){w, h}, value); + wait (RANDOM8 () % delay); + line ((pixel){x, y}, (pixel){w, h}, 0); + } +} + + +// random dots +void dots1() +{ + unsigned char n, x, y; + clear_screen(0); + + for (n = 50; n--;) + { + x = RANDOM8() % NUM_COLS; + y = RANDOM8() % NUM_ROWS; + + static unsigned char const color[5] PROGMEM = {1, 2, 3, 2, 1}; + for (unsigned char i = 0; i < 5; ++i) + { + setpixel ((pixel){x, y}, PGM(color[i])); + wait(100); + } + wait ((RANDOM8 () % 255) * 10); + } +} diff --git a/animations/mherweg.h b/animations/mherweg.h new file mode 100644 index 0000000..ab1c62d --- /dev/null +++ b/animations/mherweg.h @@ -0,0 +1,25 @@ +#ifndef MHERWEG_H_ +#define MHERWEG_H_ + +void checkbox(); + + +void movinglines(); + + +//rechteckmuster mit helligkeitsstufen +void rectangle1(); + + +// zufallsrechtecke +void rectangles(); + + +// schräge linien die aufblitzen +void lines1(); + + +// random dots +void dots1(); + +#endif /* MHERWEG_H_ */ diff --git a/animations/programm.c b/animations/programm.c index fc9d3ec..72d0ef4 100644 --- a/animations/programm.c +++ b/animations/programm.c @@ -96,182 +96,6 @@ void test_palette2(){ #endif -#ifdef ANIMATION_MHERWEG - -void checkbox(){ - -unsigned char x, delay=250; - - -// quadrat aus linien -line((pixel){0,0}, (pixel){7,0} ,3); - wait(delay); - line((pixel){7,0}, (pixel){7,7} ,3); - wait(delay); -line((pixel){7,7}, (pixel){0,7} ,3); - wait(delay); - line((pixel){0,7}, (pixel){0,0} ,3); - wait(delay); - - // 2 diagonale lininen - line((pixel){7,7}, (pixel){0,0} ,3); - wait(delay); - line((pixel){0,7}, (pixel){7,0} ,3); - wait(delay); -wait(delay); -wait(delay); - - for (x=0;x0;x--){ - - if (value dy ) - { - fraction = dy - (dx >> 1); - while ( p1.x != p2.x ) - { - if ( fraction >= 0 ) - { - p1.y += stepy; - fraction -= dx; - } - p1.x += stepx; - fraction += dy; - setpixel(p1 , value ); - } - } - else - { - fraction = dx - (dy >> 1); - while ( p1.y != p2.y ) - { - if ( fraction >= 0 ) - { - p1.x += stepx; - fraction -= dy; - } - p1.y += stepy; - fraction += dx; - setpixel(p1 , value ); - - } - } -} - - -void filled_rectangle(pixel p1, unsigned char w, unsigned char h ,unsigned char value){ - -unsigned char y; - -for (y=p1.y;y<(p1.y+h);y++){ - line((pixel){p1.x,y}, (pixel){(p1.x+w-1),y} ,value); - - } - -} - -#endif /* ANIMATION_HERWEG */ - - //shifts pixmap left. It is really shifted right, but because col0 is left in the Display it's left. void shift_pixmap_l(){ unsigned char plane, row, byte; diff --git a/pixel.h b/pixel.h index e78567d..40678a9 100644 --- a/pixel.h +++ b/pixel.h @@ -30,27 +30,23 @@ static inline pixel next_pixel(pixel pix, direction dir){ return (pixel){pix.x + nDelta[dir], pix.y + nDelta[dir + 1]}; } + static inline unsigned char get_next_pixel(pixel p, direction dir){ return get_pixel(next_pixel(p, dir)); } + static inline direction direction_r(direction dir){ return (dir + 1) % 4; } void clear_screen(unsigned char value); + + void setpixel(pixel p, unsigned char value); #define clearpixel(p) setpixel(p, 0); -// straight or non straight line from one point to the other -// value=brightness -void line(pixel p1, pixel p2 ,unsigned char value); - -// filled_rectangle p1=upper right corner, w=width, h=height , -// value=brightness -void filled_rectangle(pixel p1, unsigned char w, unsigned char h ,unsigned char value); - void shift_pixmap_l();