Browse Source

simple plasma animation added

feature/2015
Christian Kroll 14 years ago
parent
commit
4993fe5194
  1. 4
      animations/Makefile
  2. 8
      animations/config.in
  3. 48
      animations/plasma.c
  4. 6
      animations/plasma.h
  5. 8
      display_loop.c

4
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

8
animations/config.in

@ -16,11 +16,13 @@ comment "Animations"
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

48
animations/plasma.c

@ -0,0 +1,48 @@
#include <math.h>
#include <stdint.h>
#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);
}
}

6
animations/plasma.h

@ -0,0 +1,6 @@
#ifndef PLASMA_H_
#define PLASMA_H_
void plasma(void);
#endif /* PLASMA_H_ */

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

Loading…
Cancel
Save