Christian Kroll
11 years ago
8 changed files with 177 additions and 55 deletions
@ -0,0 +1,88 @@ |
|||
/**
|
|||
* \defgroup moire A moire like pattern. |
|||
* @{ |
|||
*/ |
|||
|
|||
/**
|
|||
* @file moire.c |
|||
* @brief Implementation of a simple moire like pattern. |
|||
* @author Christian Kroll |
|||
*/ |
|||
|
|||
#include "../config.h" |
|||
#include "../pixel.h" |
|||
#include "../util.h" |
|||
|
|||
/**
|
|||
* Number of pixels of the complete border. |
|||
*/ |
|||
#define NUMBER_OF_BORDER_PIXELS (2u * UNUM_COLS + 2u * (UNUM_ROWS - 2u)) |
|||
|
|||
/**
|
|||
* Draws a moire like pattern. Works best if the number of border pixels is a |
|||
* multiple of the size of the gradient color map. |
|||
*/ |
|||
void moire(void) |
|||
{ |
|||
// add rotating color map
|
|||
#if NUMPLANE == 3 |
|||
static unsigned char const gradient[] = {0, 1, 2, 3, 2, 1}; |
|||
#else |
|||
static unsigned char gradient[NUMPLANE * 2u] = {0}; |
|||
for (unsigned char i = 1; i <= NUMPLANE; ++i) |
|||
{ |
|||
gradient[i] = i; |
|||
gradient[(NUMPLANE * 2) - i] = i; |
|||
} |
|||
#endif |
|||
|
|||
unsigned int cycles = 30000; |
|||
unsigned char pos = 0, color_index = 0; |
|||
pixel p1 = (pixel){0 ,0}; |
|||
|
|||
while(cycles--) |
|||
{ |
|||
// walk around the border; do that by mapping a linear increasing value
|
|||
// to appropriate screen coordinates
|
|||
|
|||
// first pixel is between top right and top left corner
|
|||
if (pos < NUM_COLS) |
|||
{ |
|||
p1.x = pos; |
|||
} |
|||
// first pixel is between top left and bottom left corner
|
|||
else if (pos < (NUM_COLS + NUM_ROWS - 1)) |
|||
{ |
|||
p1.y = pos - (NUM_COLS - 1); |
|||
} |
|||
// first pixel is between bottom left and bottom right corner
|
|||
else if (pos < (2 * NUM_COLS + NUM_ROWS - 2)) |
|||
{ |
|||
p1.x = 2 * NUM_COLS + NUM_ROWS - 3 - pos; |
|||
} |
|||
// first pixel is between bottom right and top left corner
|
|||
else |
|||
{ |
|||
p1.y = 3 * NUM_COLS + NUM_ROWS - 4 - pos; |
|||
} |
|||
|
|||
// second pixel in opposite direction
|
|||
pixel const p2 = (pixel){NUM_COLS - 1 - p1.x, NUM_ROWS - 1 - p1.y}; |
|||
|
|||
// draw line right accross the display and switch to next color
|
|||
line(p1, p2, gradient[color_index++]); |
|||
|
|||
// if we have reached the origin, reset position, rotate color index and
|
|||
// wait for 40 ms (25 fps) to make the frame visible for human viewers
|
|||
if (++pos == NUMBER_OF_BORDER_PIXELS) |
|||
{ |
|||
pos = 0; |
|||
++color_index; |
|||
wait(40); |
|||
} |
|||
// ensure the color index keeps within bounds
|
|||
color_index %= (2u * NUMPLANE); |
|||
} |
|||
} |
|||
|
|||
/*@}*/ |
@ -0,0 +1,19 @@ |
|||
/**
|
|||
* \defgroup moire A moire like pattern. |
|||
* @{ |
|||
*/ |
|||
|
|||
/**
|
|||
* @file moire.h |
|||
* @brief Interface file for a moire pattern implementation. |
|||
* @author Christian Kroll |
|||
*/ |
|||
|
|||
#ifndef MOIRE_H_ |
|||
#define MOIRE_H_ |
|||
|
|||
void moire(void); |
|||
|
|||
#endif /* MOIRE_H_ */ |
|||
|
|||
/*@}*/ |
Loading…
Reference in new issue