From 663443055c826b8c9d12485c318ba3b8af29191b Mon Sep 17 00:00:00 2001 From: Christian Kroll Date: Wed, 15 Aug 2012 04:05:04 +0000 Subject: [PATCH] Added basic square pattern animation. Unfortunately, it did not turn out to be as beautiful as intended. Borg displays can be limiting at times... --- animations/Makefile | 4 +++ animations/config.in | 2 ++ animations/squares.c | 67 ++++++++++++++++++++++++++++++++++++++++++++ animations/squares.h | 19 +++++++++++++ display_loop.c | 7 +++++ 5 files changed, 99 insertions(+) create mode 100644 animations/squares.c create mode 100644 animations/squares.h diff --git a/animations/Makefile b/animations/Makefile index 88b1a80..c775a28 100644 --- a/animations/Makefile +++ b/animations/Makefile @@ -69,6 +69,10 @@ ifeq ($(ANIMATION_BLACKHOLE),y) SRC += blackhole.c endif +ifeq ($(ANIMATION_SQUARES),y) + SRC += squares.c +endif + ifeq ($(ANIMATION_TIME),y) SRC += borg_time.c endif diff --git a/animations/config.in b/animations/config.in index d8992d2..9f49617 100644 --- a/animations/config.in +++ b/animations/config.in @@ -70,6 +70,8 @@ comment "Animations" bool "Black Hole" ANIMATION_BLACKHOLE + dep_bool "Squares" ANIMATION_SQUARES $RANDOM_SUPPORT + comment "Special Animations" bool "Test Animations" ANIMATION_TESTS bool "Display off mode" ANIMATION_OFF diff --git a/animations/squares.c b/animations/squares.c new file mode 100644 index 0000000..c915bc7 --- /dev/null +++ b/animations/squares.c @@ -0,0 +1,67 @@ +/** + * \defgroup squares Square patterns for the Borg. + * @{ + */ + + +/** + * @file squares.c + * @brief Moves layers of translucent checker boards over each other. + * @author Christian Kroll + */ + + +#include +#include +#include "../config.h" +#include "../util.h" +#include "../pixel.h" +#include "../random/prng.h" +#include "squares.h" + +#define STEP_WIDTH (NUMPLANE * 2u) +#define TICK 150 +#define CYCLES 200u + +/** + * Moves layers of translucent checker boards over each other. + */ +void squares(void) { + // add a rotating color map for smooth transitions + uint8_t nColorMap[NUMPLANE * 2]; + for (uint8_t i = 0; i < (((NUMPLANE + 1) * 2) - 1); ++i) { + if (i < (NUMPLANE + 1)) { + nColorMap[i] = i; + } else { + nColorMap[i] = (NUMPLANE * 2) - i; + } + } + + uint8_t nOffsets[NUMPLANE] = {0}; + uint8_t nColOffset = 0; + for (uint8_t nCount = CYCLES; nCount--;) { + for (uint8_t x = 0; x < NUM_COLS ; ++x) { + for (uint8_t y = 0; y < NUM_ROWS; ++y) { + uint8_t nColor = 0; + for (uint8_t nLayer = 0; nLayer < NUMPLANE; ++nLayer) { + nColor += (((x + nOffsets[nLayer]) / STEP_WIDTH) + ((y + + nOffsets[nLayer] + STEP_WIDTH) / STEP_WIDTH)) % 2u; + } + setpixel((pixel){x, y}, + nColorMap[(nColOffset + nColor) % (2* NUMPLANE)]); + } + } + + // add randomly calculated offsets to each layer starting points + for (uint8_t i = 0; i < NUMPLANE; ++i) { + nOffsets[i] = (nOffsets[i] + random8()) & STEP_WIDTH; + } + // rotate color map + nColOffset = (nColOffset + 1) % (NUMPLANE * 2); + + // pause for a moment to ensure that frame transitions are visible + wait(TICK); + } +} + +/*@}*/ diff --git a/animations/squares.h b/animations/squares.h new file mode 100644 index 0000000..6c211c4 --- /dev/null +++ b/animations/squares.h @@ -0,0 +1,19 @@ +/** + * \addtogroup squares + * @{ + */ + +/** + * @file squares.h + * @brief Moves layers of translucent checker boards over each other. + * @author Christian Kroll + */ + +#ifndef SQUARES_H_ +#define SQUARES_H_ + +void squares(void); + +#endif /* SQUARES_H_ */ + +/*@}*/ diff --git a/display_loop.c b/display_loop.c index 4549def..db3e36f 100644 --- a/display_loop.c +++ b/display_loop.c @@ -20,6 +20,7 @@ #include "animations/fpmath_patterns.h" #include "animations/mherweg.h" #include "animations/blackhole.h" +#include "animations/squares.h" #ifdef ANIMATION_TIME #include "animations/borg_time.h" #endif @@ -240,6 +241,12 @@ void display_loop(){ break; #endif +#ifdef ANIMATION_SQUARES + case 25: + squares(); + break; +#endif + #ifdef ANIMATION_TESTS case 31: test_level(1);