Added basic square pattern animation. Unfortunately, it did not turn out to be as beautiful as intended. Borg displays can be limiting at times...

This commit is contained in:
Christian Kroll 2012-08-15 04:05:04 +00:00
parent 96ff16629c
commit 663443055c
5 changed files with 99 additions and 0 deletions

View File

@ -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

View File

@ -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

67
animations/squares.c Normal file
View File

@ -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 <assert.h>
#include <stdint.h>
#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);
}
}
/*@}*/

19
animations/squares.h Normal file
View File

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

View File

@ -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);