2012-08-15 04:05:04 +00:00
|
|
|
/**
|
|
|
|
* \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"
|
|
|
|
|
2012-09-08 01:35:32 +00:00
|
|
|
#define STEP ((uint8_t)(NUMPLANE * 2u))
|
2012-08-19 13:14:27 +00:00
|
|
|
#define TICK 100
|
2012-08-15 04:05:04 +00:00
|
|
|
#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];
|
2012-09-04 01:39:56 +00:00
|
|
|
for (uint8_t i = 0; i < (NUMPLANE * 2); ++i) {
|
2012-08-15 04:05:04 +00:00
|
|
|
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) {
|
2012-09-08 01:35:32 +00:00
|
|
|
nColor += (uint8_t)(((x + nOffsets[nLayer]) / STEP) +
|
|
|
|
((y + nOffsets[nLayer] + STEP) / STEP)) % 2u;
|
2012-08-15 04:05:04 +00:00
|
|
|
}
|
|
|
|
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) {
|
2012-09-08 01:35:32 +00:00
|
|
|
nOffsets[i] = (uint8_t)(nOffsets[i] + random8()) % STEP;
|
2012-08-15 04:05:04 +00:00
|
|
|
}
|
|
|
|
// rotate color map
|
|
|
|
nColOffset = (nColOffset + 1) % (NUMPLANE * 2);
|
|
|
|
|
|
|
|
// pause for a moment to ensure that frame transitions are visible
|
|
|
|
wait(TICK);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*@}*/
|