From 4993fe5194245f12d42881ee4b65e93543968755 Mon Sep 17 00:00:00 2001 From: Christian Kroll Date: Mon, 14 Mar 2011 10:34:16 +0000 Subject: [PATCH] simple plasma animation added --- animations/Makefile | 4 ++++ animations/config.in | 14 +++++++------ animations/plasma.c | 48 ++++++++++++++++++++++++++++++++++++++++++++ animations/plasma.h | 6 ++++++ display_loop.c | 8 ++++++++ 5 files changed, 74 insertions(+), 6 deletions(-) create mode 100644 animations/plasma.c create mode 100644 animations/plasma.h diff --git a/animations/Makefile b/animations/Makefile index 344b16f..1435566 100644 --- a/animations/Makefile +++ b/animations/Makefile @@ -53,4 +53,8 @@ ifeq ($(ANIMATION_LOGO_27C3),y) SRC += 27c3.c endif +ifeq ($(ANIMATION_PLASMA),y) + SRC += plasma.c +endif + include $(TOPDIR)/rules.mk diff --git a/animations/config.in b/animations/config.in index d873666..332e142 100644 --- a/animations/config.in +++ b/animations/config.in @@ -14,14 +14,16 @@ comment "Animations" dep_bool "Breakout Demo" ANIMATION_BREAKOUT $GAME_BREAKOUT bool "Martin Herweg" ANIMATION_MHERWEG $RANDOM_SUPPORT dep_bool "Langton Ant" ANIMATION_LTN_ANT $RANDOM_SUPPORT - + dep_bool_menu "Bitmap Scroller" ANIMATION_BMSCROLLER y $RANDOM_SUPPORT - dep_bool "LABOR Logo" ANIMATION_LABORLOGO $ANIMATION_BMSCROLLER - dep_bool "Amphibian" ANIMATION_AMPHIBIAN $ANIMATION_BMSCROLLER - dep_bool "27c3 Logo" ANIMATION_LOGO_27C3 $ANIMATION_BMSCROLLER + dep_bool "LABOR Logo" ANIMATION_LABORLOGO $ANIMATION_BMSCROLLER + dep_bool "Amphibian" ANIMATION_AMPHIBIAN $ANIMATION_BMSCROLLER + dep_bool "27c3 Logo" ANIMATION_LOGO_27C3 $ANIMATION_BMSCROLLER endmenu - + + bool "Plasma" ANIMATION_PLASMA + comment "Special Animations" bool "Test Animations" ANIMATION_TESTS bool "Display off mode" ANIMATION_OFF -endmenu \ No newline at end of file +endmenu diff --git a/animations/plasma.c b/animations/plasma.c new file mode 100644 index 0000000..b76d770 --- /dev/null +++ b/animations/plasma.c @@ -0,0 +1,48 @@ +#include +#include +#include "../config.h" +#include "../pixel.h" +#include "../util.h" +#include "plasma.h" + + +#define FRAME_TICK 80 +#define FRAME_COUNT 750 +#define PLASMA_X (1.0 / (NUM_COLS / (2.0 * M_PI))) + + +/** + * calculates the distance between two points + * @param x1 x coordinate of the first point + * @param y1 y coordinate of the first point + * @param x2 x coordinate of the second point + * @param y2 y coordinate of the second point + * @return distance between the points + */ +static double dist(double x1, double y1, double x2, double y2) +{ + return sqrt(((x1 - x2) * (x1 - x2)) + ((y1 - y2) * (y1 - y2))); +} + + +/** + * draws a simple plasma effect + */ +void plasma(void) +{ + for (double t = 0; t < (FRAME_COUNT / 10.0); t = t + 0.1) { + for (unsigned char x = 0; x < NUM_COLS; ++x) + { + for (unsigned char y = 0; y < NUM_ROWS; ++y) + { + double nColor1 = sin(x * PLASMA_X + t) + 1; + double nColor2 = sin(dist(x, y, NUM_COLS * sin(t) + NUM_COLS, + NUM_ROWS * cos(t) + NUM_ROWS) * PLASMA_X) + 1; + unsigned char nColor = + ((nColor1 + nColor2) * (NUMPLANE - 1)) / 2; + setpixel((pixel){x, y}, nColor); + } + } + wait(FRAME_TICK); + } +} diff --git a/animations/plasma.h b/animations/plasma.h new file mode 100644 index 0000000..40beb28 --- /dev/null +++ b/animations/plasma.h @@ -0,0 +1,6 @@ +#ifndef PLASMA_H_ +#define PLASMA_H_ + +void plasma(void); + +#endif /* PLASMA_H_ */ diff --git a/display_loop.c b/display_loop.c index 9b847a0..d65eedf 100644 --- a/display_loop.c +++ b/display_loop.c @@ -15,6 +15,7 @@ #include "animations/amphibian.h" #include "animations/laborlogo.h" #include "animations/27c3.h" +#include "animations/plasma.h" #include "animations/mherweg.h" #include "borg_hw/borg_hw.h" #include "can/borg_can.h" @@ -171,6 +172,13 @@ void display_loop(){ break; #endif +#ifdef ANIMATION_PLASMA + case 18: + plasma(); + break; +#endif + + #ifdef ANIMATION_TESTS case 31: test_level(1);