integrated the black hole animation from the former borg simulator tree
This commit is contained in:
parent
1fb79e3dda
commit
6286a3ed25
|
@ -61,6 +61,10 @@ ifneq (,$(filter y,$(ANIMATION_PLASMA) $(ANIMATION_PSYCHEDELIC)))
|
||||||
SRC += fpmath_patterns.c
|
SRC += fpmath_patterns.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(ANIMATION_BLACKHOLE),y)
|
||||||
|
SRC += blackhole.c
|
||||||
|
endif
|
||||||
|
|
||||||
ifeq ($(ANIMATION_TIME),y)
|
ifeq ($(ANIMATION_TIME),y)
|
||||||
SRC += borg_time.c
|
SRC += borg_time.c
|
||||||
endif
|
endif
|
||||||
|
|
|
@ -0,0 +1,99 @@
|
||||||
|
#include <stdint.h>
|
||||||
|
#include "../config.h"
|
||||||
|
#include "../pixel.h"
|
||||||
|
#include "../util.h"
|
||||||
|
#include "../compat/pgmspace.h"
|
||||||
|
#include "blackhole.h"
|
||||||
|
|
||||||
|
// macro for simplifying flash memory access
|
||||||
|
#define PGM(x) pgm_read_byte(&(x))
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Integer variant of the sinus function which takes an integer based angle
|
||||||
|
* (range from 0 to 63) where sin_i(64) corresponds to sin(2 * M_PI) * 64 and
|
||||||
|
* sin_i(16) corresponds to sin(0.5 * M_PI) * 64 (each excluding the fractional
|
||||||
|
* part). It uses a lookup table which models one quarter of a full sinus period
|
||||||
|
* and calculates the rest of the function from that quarter.
|
||||||
|
* @param angle angle based on an integer (range from 0 to 63)
|
||||||
|
* @return result of the sinus function normalized to a range from -64 to 64
|
||||||
|
*/
|
||||||
|
static signed char sin_i(unsigned char angle) {
|
||||||
|
// the aforementioned lookup table
|
||||||
|
static signed char const sinus_table[] PROGMEM =
|
||||||
|
{0, 6, 12, 19, 24, 30, 36, 41, 45, 49, 53, 56, 59, 61, 63, 64};
|
||||||
|
|
||||||
|
// determine correct index for the lookup table depending on the given angle
|
||||||
|
angle %= 64u;
|
||||||
|
unsigned char index;
|
||||||
|
if (angle < 16) {
|
||||||
|
index = angle;
|
||||||
|
} else if (angle < 32) {
|
||||||
|
index = 32 - angle;
|
||||||
|
} else if (angle < 48) {
|
||||||
|
index = angle - 32;
|
||||||
|
} else {
|
||||||
|
index = 64 - angle;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (unsigned char)(PGM(sinus_table[index])) * (angle < 32 ? 1 : -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Integer variant of the cosinus function which takes an integer based angle
|
||||||
|
* (range from 0 to 63) where cos_i(64) corresponds to cos(2 * M_PI) * 64 and
|
||||||
|
* cos_i(16) corresponds to cos(0.5 * M_PI) * 64. It uses the sin_i function and
|
||||||
|
* shifts the given angle by 16 (which corresponds to 90 degrees).
|
||||||
|
* @param angle angle based on an integer (range from 0 to 63)
|
||||||
|
* @return result of the cosinus function normalized to a range from -64 to 64
|
||||||
|
*/
|
||||||
|
static signed char cos_i(unsigned char const angle) {
|
||||||
|
return sin_i(angle + 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#define NUM_CIRCLE 7
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draws a black hole like pattern (viewed from different perspectives).
|
||||||
|
*/
|
||||||
|
void blackhole(void) {
|
||||||
|
pixel circlePoints[NUM_CIRCLE][8];
|
||||||
|
unsigned char add = 0;
|
||||||
|
signed char firstRadius = 80, helpRadius, angle = 0, x, y;
|
||||||
|
// initialize data
|
||||||
|
for (int k = 0; k < 800; k++) {
|
||||||
|
if (k > 300)
|
||||||
|
add = k / 16;
|
||||||
|
helpRadius = firstRadius;
|
||||||
|
for (unsigned char i = 0; i < NUM_CIRCLE; i++) {
|
||||||
|
for (unsigned char j = 0; j < 8; j++) {
|
||||||
|
if (j & 1) {
|
||||||
|
circlePoints[i][j].x = 64
|
||||||
|
+ (cos_i(angle + j * 8) * helpRadius) / 64;
|
||||||
|
circlePoints[i][j].y = 64
|
||||||
|
+ (sin_i(angle + add + j * 8) * helpRadius) / 64;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
circlePoints[i][j].x = 64 +
|
||||||
|
(cos_i(angle + j * 8 + 4) * helpRadius) / 64;
|
||||||
|
circlePoints[i][j].y = 64 +
|
||||||
|
(sin_i(angle + add + j * 8 + 4) * helpRadius) / 64;
|
||||||
|
}
|
||||||
|
x = circlePoints[i][j].x / 8;
|
||||||
|
y = circlePoints[i][j].y / 8;
|
||||||
|
if (x < 16 && y < 16)
|
||||||
|
setpixel((pixel){x, y}, 3);
|
||||||
|
}
|
||||||
|
helpRadius = (helpRadius * 2) / 3;
|
||||||
|
}
|
||||||
|
wait(30);
|
||||||
|
clear_screen(0);
|
||||||
|
angle++;
|
||||||
|
firstRadius += 2;
|
||||||
|
if (firstRadius > 119)
|
||||||
|
firstRadius = 80;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
#ifndef BLACKHOLE_H_
|
||||||
|
#define BLACKHOLE_H_
|
||||||
|
|
||||||
|
void blackhole(void);
|
||||||
|
|
||||||
|
#endif /* BLACKHOLE_H_ */
|
|
@ -58,6 +58,7 @@ comment "Animations"
|
||||||
|
|
||||||
bool "Plasma" ANIMATION_PLASMA
|
bool "Plasma" ANIMATION_PLASMA
|
||||||
bool "Psychedelic" ANIMATION_PSYCHEDELIC
|
bool "Psychedelic" ANIMATION_PSYCHEDELIC
|
||||||
|
bool "Black Hole" ANIMATION_BLACKHOLE
|
||||||
|
|
||||||
comment "Special Animations"
|
comment "Special Animations"
|
||||||
bool "Test Animations" ANIMATION_TESTS
|
bool "Test Animations" ANIMATION_TESTS
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include "animations/28c3.h"
|
#include "animations/28c3.h"
|
||||||
#include "animations/fpmath_patterns.h"
|
#include "animations/fpmath_patterns.h"
|
||||||
#include "animations/mherweg.h"
|
#include "animations/mherweg.h"
|
||||||
|
#include "animations/blackhole.h"
|
||||||
#ifdef ANIMATION_TIME
|
#ifdef ANIMATION_TIME
|
||||||
#include "animations/borg_time.h"
|
#include "animations/borg_time.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -226,6 +227,11 @@ void display_loop(){
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef ANIMATION_BLACKHOLE
|
||||||
|
case 23:
|
||||||
|
blackhole();
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef ANIMATION_TESTS
|
#ifdef ANIMATION_TESTS
|
||||||
case 31:
|
case 31:
|
||||||
|
@ -276,6 +282,7 @@ void display_loop(){
|
||||||
case 43:
|
case 43:
|
||||||
menu();
|
menu();
|
||||||
mode = oldOldmode;
|
mode = oldOldmode;
|
||||||
|
break;
|
||||||
#else
|
#else
|
||||||
|
|
||||||
case 42:
|
case 42:
|
||||||
|
|
Loading…
Reference in New Issue