renamed project because it is to cool for stupid name
This commit is contained in:
commit
fe14b29d15
106 changed files with 16442 additions and 0 deletions
21
animations/Makefile
Normal file
21
animations/Makefile
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
TARGET = libanimations.a
|
||||
TOPDIR = ..
|
||||
|
||||
include $(TOPDIR)/defaults.mk
|
||||
|
||||
SRC = programm.c
|
||||
|
||||
ifeq ($(ANIMATION_SNAKE),y)
|
||||
SRC += snake.c
|
||||
endif
|
||||
|
||||
ifeq ($(ANIMATION_MATRIX),y)
|
||||
SRC += matrix.c
|
||||
endif
|
||||
|
||||
ifeq ($(ANIMATION_GAMEOFLIFE),y)
|
||||
SRC += gameoflife.c
|
||||
endif
|
||||
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
312
animations/gameoflife.c
Normal file
312
animations/gameoflife.c
Normal file
|
|
@ -0,0 +1,312 @@
|
|||
/**
|
||||
* Conways Game of life
|
||||
* Author: Daniel Otte
|
||||
* License: GPLv3
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <util/delay.h>
|
||||
#include <avr/sfr_defs.h> /* for debugging */
|
||||
#include "../config.h"
|
||||
#include "../random/prng.h"
|
||||
#include "../pixel.h"
|
||||
#include "../util.h"
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
#undef DEBUG
|
||||
|
||||
#define XSIZE NUM_COLS
|
||||
#define YSIZE NUM_ROWS
|
||||
|
||||
/*
|
||||
* last line is for debug information
|
||||
*/
|
||||
#ifdef DEBUG
|
||||
#undef YSIZE
|
||||
#define YSIZE (NUM_ROWS-1)
|
||||
#define DEBUG_ROW (NUM_ROWS-1)
|
||||
#define DEBUG_BIT(pos, val) \
|
||||
setpixel((pixel){(pos)%XSIZE,DEBUG_ROW+(pos)/XSIZE},(val)?3:0)
|
||||
#define DEBUG_BYTE(s,v) \
|
||||
DEBUG_BIT((s)*8+0, (v)&(1<<0)); \
|
||||
DEBUG_BIT((s)*8+1, (v)&(1<<1)); \
|
||||
DEBUG_BIT((s)*8+2, (v)&(1<<2)); \
|
||||
DEBUG_BIT((s)*8+3, (v)&(1<<3)); \
|
||||
DEBUG_BIT((s)*8+4, (v)&(1<<4)); \
|
||||
DEBUG_BIT((s)*8+5, (v)&(1<<5)); \
|
||||
DEBUG_BIT((s)*8+6, (v)&(1<<6)); \
|
||||
DEBUG_BIT((s)*8+7, (v)&(1<<7))
|
||||
#else
|
||||
#define DEBUG_BIT(s,v)
|
||||
#define DEBUG_BYTE(s,v)
|
||||
#endif
|
||||
|
||||
//#define GLIDER_TEST
|
||||
|
||||
#define BITSTUFFED
|
||||
#define LOOP_DETECT_BUFFER_SIZE 8
|
||||
|
||||
#ifndef GOL_DELAY
|
||||
#define GOL_DELAY 1 /* milliseconds */
|
||||
#endif
|
||||
|
||||
#ifndef GOL_CYCLES
|
||||
#define GOL_CYCLES (2*60*3)
|
||||
#endif
|
||||
|
||||
/******************************************************************************/
|
||||
/******************************************************************************/
|
||||
|
||||
typedef enum{dead=0, alive=1} cell_t;
|
||||
|
||||
#ifndef BITSTUFFED
|
||||
|
||||
#define FIELD_XSIZE XSIZE
|
||||
#define FIELD_YSIZE YSIZE
|
||||
|
||||
typedef cell_t field_t[FIELD_XSIZE][FIELD_YSIZE];
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
void setcell(field_t pf, int x, int y, cell_t value){
|
||||
pf[(x+FIELD_XSIZE)%FIELD_XSIZE][(y+FIELD_YSIZE)%FIELD_YSIZE] = value;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
cell_t getcell(field_t pf, int x, int y){
|
||||
return pf[(x+FIELD_XSIZE)%FIELD_XSIZE][(y+FIELD_YSIZE)%FIELD_YSIZE];
|
||||
}
|
||||
|
||||
#else /* BITSTUFFED */
|
||||
|
||||
#define FIELD_XSIZE ((XSIZE+7)/8)
|
||||
#define FIELD_YSIZE YSIZE
|
||||
|
||||
typedef uint8_t field_t[FIELD_XSIZE][FIELD_YSIZE];
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
void setcell(field_t pf, int x, int y, cell_t value){
|
||||
uint8_t t;
|
||||
x = (x+XSIZE) % XSIZE;
|
||||
y = (y+YSIZE) % YSIZE;
|
||||
|
||||
t = pf[x/8][y];
|
||||
if(value==alive){
|
||||
t |= 1<<(x&7);
|
||||
} else {
|
||||
t &= ~(1<<(x&7));
|
||||
}
|
||||
pf[x/8][y] = t;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
cell_t getcell(field_t pf, int x, int y){
|
||||
x = (x+XSIZE) % XSIZE;
|
||||
y = (y+YSIZE) % YSIZE;
|
||||
|
||||
return ((pf[x/8][y])&(1<<(x&7)))?alive:dead;
|
||||
}
|
||||
#endif
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
uint8_t countsurroundingalive(field_t pf, int x, int y){
|
||||
uint8_t ret=0;
|
||||
ret += (getcell(pf, x-1, y-1)==alive)?1:0;
|
||||
ret += (getcell(pf, x , y-1)==alive)?1:0;
|
||||
ret += (getcell(pf, x+1, y-1)==alive)?1:0;
|
||||
|
||||
ret += (getcell(pf, x-1, y )==alive)?1:0;
|
||||
ret += (getcell(pf, x+1, y )==alive)?1:0;
|
||||
|
||||
ret += (getcell(pf, x-1, y+1)==alive)?1:0;
|
||||
ret += (getcell(pf, x , y+1)==alive)?1:0;
|
||||
ret += (getcell(pf, x+1, y+1)==alive)?1:0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
void nextiteration(field_t dest, field_t src){
|
||||
int x,y;
|
||||
uint8_t tc;
|
||||
for(y=0; y<YSIZE; ++y){
|
||||
for(x=0; x<XSIZE; ++x){
|
||||
tc=countsurroundingalive(src,x,y);
|
||||
switch(tc){
|
||||
// case 0:
|
||||
// case 1:
|
||||
// /* dead */
|
||||
// setcell(dest, x,y, dead);
|
||||
case 2:
|
||||
/* keep */
|
||||
setcell(dest, x,y, getcell(src,x,y));
|
||||
break;
|
||||
case 3:
|
||||
/* alive */
|
||||
setcell(dest, x,y, alive);
|
||||
break;
|
||||
default:
|
||||
/* dead */
|
||||
setcell(dest, x,y, dead);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
void printpf(field_t pf){
|
||||
int x,y;
|
||||
for(y=0; y<YSIZE; ++y){
|
||||
for(x=0; x<XSIZE; ++x){
|
||||
setpixel((pixel){x,y},(getcell(pf,x,y)==alive)?3:0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
void pfcopy(field_t dest, field_t src){
|
||||
int x,y;
|
||||
for(y=0; y<YSIZE; ++y){
|
||||
for(x=0; x<XSIZE; ++x){
|
||||
setcell(dest,x,y,getcell(src,x,y));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
#ifndef BITSTUFFED
|
||||
uint8_t pfcmp(field_t dest, field_t src){
|
||||
int x,y;
|
||||
for(y=0; y<YSIZE; ++y){
|
||||
for(x=0; x<XSIZE; ++x){
|
||||
if (getcell(src,x,y) != getcell(dest,x,y))
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
uint8 pfempty(field_t src){ int x,y;
|
||||
for(y=0; y<YSIZE; ++y){
|
||||
for(x=0; x<XSIZE; ++x){
|
||||
if (getcell(src,x,y)==alive)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
uint8_t pfcmp(field_t dest, field_t src){
|
||||
int x,y;
|
||||
for(y=0; y<FIELD_YSIZE; ++y){
|
||||
for(x=0; x<FIELD_XSIZE; ++x){
|
||||
if (src[x][y] != dest[x][y])
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
uint8_t pfempty(field_t src){
|
||||
int x,y;
|
||||
for(y=0; y<FIELD_YSIZE; ++y){
|
||||
for(x=0; x<FIELD_XSIZE; ++x){
|
||||
if (src[x][y]!=0)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif
|
||||
/******************************************************************************/
|
||||
|
||||
void insertglider(field_t pf){
|
||||
/*
|
||||
* #
|
||||
* #
|
||||
* ###
|
||||
*/
|
||||
setcell(pf, 1, 0, alive);
|
||||
setcell(pf, 2, 1, alive);
|
||||
setcell(pf, 0, 2, alive); setcell(pf, 1, 2, alive); setcell(pf, 2, 2, alive);
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
int gameoflife(){
|
||||
DEBUG_BYTE(0,0); // set debug bytes to zero
|
||||
DEBUG_BYTE(1,0);
|
||||
field_t pf1,pf2;
|
||||
field_t ldbuf[LOOP_DETECT_BUFFER_SIZE]={{{0}}}; // loop detect buffer
|
||||
uint8_t ldbuf_idx=0;
|
||||
int x,y;
|
||||
uint16_t cycle;
|
||||
|
||||
//start:
|
||||
/* initalise the field with random */
|
||||
for(y=0;y<YSIZE;++y){
|
||||
for(x=0;x<XSIZE; ++x){
|
||||
setcell(pf1,x,y,(random8()&1)?alive:dead);
|
||||
}
|
||||
}
|
||||
#ifdef GLIDER_TEST
|
||||
/* initialise with glider */
|
||||
for(y=0;y<YSIZE;++y){
|
||||
for(x=0;x<XSIZE; ++x){
|
||||
setcell(pf1,x,y,dead);
|
||||
}
|
||||
}
|
||||
insertglider(pf1);
|
||||
#endif
|
||||
|
||||
/* the main part */
|
||||
printpf(pf1);
|
||||
for(cycle=1; cycle<GOL_CYCLES; ++cycle){
|
||||
DEBUG_BYTE(0,(uint8_t)(GOL_CYCLES-cycle)&0xff);
|
||||
DEBUG_BYTE(1, SREG);
|
||||
wait(GOL_DELAY);
|
||||
pfcopy(pf2,pf1);
|
||||
nextiteration(pf1,pf2);
|
||||
printpf(pf1);
|
||||
/* loop detection */
|
||||
if(!pfcmp(pf1, pf2)){
|
||||
insertglider(pf1);
|
||||
cycle=1;
|
||||
}
|
||||
if(pfempty(pf1)){
|
||||
/* kill game */
|
||||
return 0;
|
||||
}
|
||||
/* */
|
||||
uint8_t i;
|
||||
for(i=0; i<LOOP_DETECT_BUFFER_SIZE; ++i){
|
||||
if(!pfcmp(pf1, ldbuf[i])){
|
||||
insertglider(pf1);
|
||||
cycle=1;
|
||||
}
|
||||
}
|
||||
pfcopy(ldbuf[ldbuf_idx], pf1);
|
||||
ldbuf_idx = (ldbuf_idx+1)%LOOP_DETECT_BUFFER_SIZE;
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
14
animations/gameoflife.h
Normal file
14
animations/gameoflife.h
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
/**
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef GAMEOFLIFE_H_
|
||||
#define GAMEOFLIFE_H_
|
||||
|
||||
void gameoflife();
|
||||
|
||||
#endif /* GAMEOFLIFE_H_ */
|
||||
98
animations/matrix.c
Normal file
98
animations/matrix.c
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
|
||||
#include "../config.h"
|
||||
#include <stdint.h>
|
||||
#include "../random/prng.h"
|
||||
#include "../pixel.h"
|
||||
#include "../util.h"
|
||||
|
||||
|
||||
typedef struct{
|
||||
pixel start;
|
||||
unsigned char len;
|
||||
unsigned char decay;
|
||||
unsigned char index;
|
||||
unsigned char speed;
|
||||
} streamer;
|
||||
|
||||
typedef uint8_t pixel_matrix_t[NUM_COLS][NUM_ROWS/4];
|
||||
|
||||
inline static uint8_t get_bright(pixel_matrix_t *matrix, uint8_t x, uint8_t y){
|
||||
uint8_t ret;
|
||||
ret = (*matrix)[x][y/4];
|
||||
return 0x3&(ret>>(2*(y%4)));
|
||||
}
|
||||
|
||||
inline static void set_bright(pixel_matrix_t *matrix, uint8_t x, uint8_t y, uint8_t value){
|
||||
uint8_t t;
|
||||
t = (*matrix)[x][y/4];
|
||||
t &= ~(0x3<<(2*(y%4)));
|
||||
t |= value<<(2*(y%4));
|
||||
(*matrix)[x][y/4] = t;
|
||||
}
|
||||
|
||||
void matrix() {
|
||||
unsigned int counter = 500; /* run 500 cycles */
|
||||
streamer streamers[STREAMER_NUM];
|
||||
pixel_matrix_t matrix_bright;
|
||||
unsigned char x, y;
|
||||
unsigned char index = 0;
|
||||
unsigned char draw;
|
||||
unsigned char streamer_num = 0;
|
||||
|
||||
while(counter--){
|
||||
unsigned char i, j;
|
||||
/* initialise matrix-buffer */
|
||||
for(x=0;x<NUM_COLS;x++)
|
||||
for(y=0;y<NUM_ROWS/4;y++)
|
||||
matrix_bright[x][y]=0;
|
||||
|
||||
for(i=0;i<streamer_num;i++){
|
||||
streamer str = streamers[i];
|
||||
|
||||
unsigned char bright = 0xFF; draw = 0;
|
||||
for(j=(str.len/8);j!=0xFF;j--){ /* Draw streamer */
|
||||
if(j+str.start.y<NUM_ROWS){
|
||||
if(bright>>6) /* bright>>6 */
|
||||
draw = 1;
|
||||
if(bright > (get_bright(&matrix_bright, str.start.x, str.start.y+j)<<6) ){
|
||||
set_bright(&matrix_bright, str.start.x, str.start.y+j, bright>>6);
|
||||
|
||||
}
|
||||
}
|
||||
bright-=((bright>>5)*str.decay);
|
||||
}
|
||||
|
||||
str.len+=str.speed/2;
|
||||
streamers[i] = str;
|
||||
if(!draw){
|
||||
for(j=i;j<streamer_num-1;j++){
|
||||
streamers[j] = streamers[j+1];
|
||||
}
|
||||
streamer_num--;
|
||||
i--;
|
||||
}
|
||||
}
|
||||
|
||||
for(y=0;y<NUM_ROWS;y++)
|
||||
for(x=0;x<NUM_COLS;x++){
|
||||
setpixel((pixel){x,y}, get_bright(&matrix_bright,x,y));
|
||||
}
|
||||
|
||||
unsigned char nsc;
|
||||
for(nsc=0;nsc<6;nsc++){
|
||||
if(streamer_num<STREAMER_NUM){
|
||||
unsigned char sy = random8()%(2*NUM_ROWS);
|
||||
if (sy>NUM_ROWS-1) sy=0;
|
||||
streamers[streamer_num] = (streamer){{random8()%NUM_COLS, sy}, 0, (random8()%8)+12, index++,(random8()%16)+3};
|
||||
streamer_num++;
|
||||
}
|
||||
}
|
||||
wait(60);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
14
animations/matrix.h
Normal file
14
animations/matrix.h
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
/**
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef MATRIX_H_
|
||||
#define MATRIX_H_
|
||||
|
||||
void matrix();
|
||||
|
||||
#endif /* MATRIX_H_ */
|
||||
227
animations/programm.c
Normal file
227
animations/programm.c
Normal file
|
|
@ -0,0 +1,227 @@
|
|||
|
||||
#include "../config.h"
|
||||
#include "../random/prng.h"
|
||||
#include "../pixel.h"
|
||||
#include "../util.h"
|
||||
|
||||
#ifdef AVR
|
||||
#include <avr/io.h>
|
||||
#endif
|
||||
|
||||
#define RANDOM8() (random8())
|
||||
|
||||
#ifdef ANIMATION_TESTS
|
||||
void test1(){
|
||||
unsigned char x,y;
|
||||
for (y=0;y<NUM_ROWS;y++){
|
||||
for (x=0;x<NUM_COLS;x++){
|
||||
setpixel((pixel){x,y}, 3);
|
||||
wait(100);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void test_level1(){
|
||||
unsigned char x,y;
|
||||
for (y=0;y<NUM_ROWS;y++){
|
||||
for (x=0;x<NUM_COLS;x++){
|
||||
setpixel((pixel){x,y}, 1);
|
||||
wait(5);
|
||||
}
|
||||
}
|
||||
for(;;) wait(100);
|
||||
}
|
||||
|
||||
void test_level2(){
|
||||
unsigned char x,y;
|
||||
for (y=0;y<NUM_ROWS;y++){
|
||||
for (x=0;x<NUM_COLS;x++){
|
||||
setpixel((pixel){x,y}, 2);
|
||||
wait(5);
|
||||
}
|
||||
}
|
||||
for(;;) wait(100);
|
||||
}
|
||||
|
||||
void test_level3(){
|
||||
unsigned char x,y;
|
||||
for (y=0;y<NUM_ROWS;y++){
|
||||
for (x=0;x<NUM_COLS;x++){
|
||||
setpixel((pixel){x,y}, 3);
|
||||
wait(5);
|
||||
}
|
||||
}
|
||||
for(;;) wait(100);
|
||||
}
|
||||
|
||||
void test_levels(){
|
||||
unsigned char x,y,b;
|
||||
for(b=1;b<4;b++){
|
||||
for (y=0;y<NUM_ROWS;y++){
|
||||
for (x=0;x<NUM_COLS;x++){
|
||||
setpixel((pixel){x,y}, b);
|
||||
wait(5);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void test_palette(){
|
||||
unsigned char x,y,b;
|
||||
for (y=0;y<NUM_ROWS;y++){
|
||||
b=y%4;
|
||||
for (x=0;x<NUM_COLS;x++){
|
||||
setpixel((pixel){x,y}, b);
|
||||
wait(1);
|
||||
}
|
||||
}
|
||||
for(;;) wait(100);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ANIMATION_OFF
|
||||
void off()
|
||||
{
|
||||
clear_screen(0);
|
||||
|
||||
while(1)
|
||||
wait(100);
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ANIMATION_SPIRALE
|
||||
void spirale(unsigned int delay){
|
||||
clear_screen(0);
|
||||
|
||||
cursor cur;
|
||||
cur.dir = right;
|
||||
cur.mode = set;
|
||||
set_cursor (&cur, (pixel){NUM_COLS-1,0});
|
||||
|
||||
unsigned char clearbit=0;
|
||||
while(clearbit == 0){
|
||||
|
||||
clearbit = 1;
|
||||
while (!get_next_pixel(cur.pos, cur.dir)){
|
||||
clearbit = 0;
|
||||
walk(&cur, 1, delay);
|
||||
}
|
||||
cur.dir = direction_r(cur.dir);
|
||||
}
|
||||
|
||||
cur.mode = clear;
|
||||
set_cursor(&cur, (pixel){(NUM_COLS/2)-1,(NUM_ROWS/2)-1});
|
||||
|
||||
for(clearbit=0;clearbit==0;){
|
||||
if( get_next_pixel(cur.pos, direction_r(cur.dir)) ){
|
||||
cur.dir = direction_r(cur.dir);
|
||||
}
|
||||
if( get_next_pixel(cur.pos, cur.dir) == 1 ){
|
||||
walk(&cur , 1, delay);
|
||||
}else{
|
||||
clearbit = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ANIMATION_JOERN1
|
||||
void joern1(){
|
||||
unsigned char i, j, x;
|
||||
unsigned char rolr=0x01 , rol;
|
||||
clear_screen(3);
|
||||
for(i = 0; i< 80;i++){
|
||||
rol = rolr;
|
||||
for(j = 0 ;j < NUM_ROWS; j++){
|
||||
for(x=0;x<LINEBYTES;x++)
|
||||
pixmap[2][j][x] = rol;
|
||||
if((rol<<=1)==0)rol = 0x01;
|
||||
}
|
||||
if((rolr<<=1) == 0) rolr = 1;
|
||||
wait(100);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ANIMATION_SCHACHBRETT
|
||||
void schachbrett(unsigned char times){
|
||||
clear_screen(0);
|
||||
unsigned char j;
|
||||
for(j=0;j<times;j++){
|
||||
unsigned char i, x;
|
||||
for(i = 0; i<NUM_ROWS; i++){
|
||||
for(x=0;x<LINEBYTES;x++)
|
||||
pixmap[2][i][x] = 0x55<<(i&0x01);
|
||||
}
|
||||
wait(200);
|
||||
for(i = 0; i<NUM_ROWS; i++){
|
||||
for(x=0;x<LINEBYTES;x++)
|
||||
pixmap[2][i][x] = 0xAA>>(i&0x01);
|
||||
}
|
||||
wait(200);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef ANIMATION_FEUER
|
||||
#define FEUER_Y (NUM_ROWS + 3)
|
||||
|
||||
void feuer()
|
||||
{
|
||||
unsigned char y, x;
|
||||
unsigned int t;
|
||||
unsigned char world[NUM_COLS][FEUER_Y]; // double buffer
|
||||
|
||||
|
||||
for(t=0; t<800; t++) {
|
||||
// diffuse
|
||||
for(y=1; y<FEUER_Y; y++) {
|
||||
for(x=1; x<NUM_COLS-1; x++) {
|
||||
world[x][y-1] = (FEUER_N*world[x-1][y] + FEUER_S*world[x][y] + FEUER_N*world[x+1][y]) / FEUER_DIV;
|
||||
};
|
||||
|
||||
world[0][y-1] = (FEUER_N*world[NUM_COLS-1][y] + FEUER_S*world[0][y] + FEUER_N*world[1][y]) / FEUER_DIV;
|
||||
world[NUM_COLS-1][y-1] = (FEUER_N*world[0][y] + FEUER_S*world[NUM_COLS-1][y] + FEUER_N*world[NUM_COLS-2][y]) / FEUER_DIV;
|
||||
};
|
||||
|
||||
// update lowest line
|
||||
for(x=0; x<NUM_COLS; x++) {
|
||||
world[x][FEUER_Y-1] = RANDOM8();
|
||||
};
|
||||
|
||||
// copy to screen
|
||||
for(y=0; y<NUM_ROWS; y++) {
|
||||
for(x=0; x<NUM_COLS; x++) {
|
||||
setpixel( (pixel){x,y}, (world[x][y] >> 5) );
|
||||
}
|
||||
};
|
||||
|
||||
wait(FEUER_DELAY);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ANIMATION_RANDOM_BRIGHT
|
||||
/**
|
||||
* void random_bright(void)
|
||||
* by Daniel Otte
|
||||
*
|
||||
*
|
||||
*/
|
||||
void random_bright(unsigned cycles){
|
||||
uint8_t t,x,y;
|
||||
while(cycles--){
|
||||
for(y=0; y<NUM_ROWS; ++y)
|
||||
for(x=0; x<NUM_COLS/4; ++x){
|
||||
t=random8();
|
||||
setpixel((pixel){x*4+0, y}, 0x3&(t>>0));
|
||||
setpixel((pixel){x*4+1, y}, 0x3&(t>>2));
|
||||
setpixel((pixel){x*4+2, y}, 0x3&(t>>4));
|
||||
setpixel((pixel){x*4+3, y}, 0x3&(t>>6));
|
||||
}
|
||||
wait(200);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
22
animations/programm.h
Normal file
22
animations/programm.h
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#ifndef PROGRAMM_H_
|
||||
#define PROGRAMM_H_
|
||||
|
||||
void off();
|
||||
void spirale(unsigned int delay);
|
||||
void joern1();
|
||||
void joern2();
|
||||
void draw_line( unsigned char yabs, signed char delta);
|
||||
void schachbrett(unsigned char times);
|
||||
void test1();
|
||||
void test_level1();
|
||||
void test_level2();
|
||||
void test_level3();
|
||||
void test_levels();
|
||||
void test_palette();
|
||||
void snake();
|
||||
void matrix();
|
||||
void fadein();
|
||||
void feuer();
|
||||
void random_bright(unsigned cycles);
|
||||
|
||||
#endif /* PROGRAMM_H_ */
|
||||
249
animations/snake.c
Normal file
249
animations/snake.c
Normal file
|
|
@ -0,0 +1,249 @@
|
|||
|
||||
#include "../config.h"
|
||||
#include "../pixel.h"
|
||||
#include "../util.h"
|
||||
#include "../random/prng.h"
|
||||
#include "snake.h"
|
||||
#include "../joystick.h"
|
||||
|
||||
#define RANDOM8() (random8())
|
||||
|
||||
void snake(){
|
||||
pixel pixels[64];
|
||||
pixels[0] = (pixel){NUM_COLS/2, NUM_ROWS/2};
|
||||
pixels[1] = (pixel){NUM_COLS/2, (NUM_ROWS/2)-1};
|
||||
|
||||
pixel * head = &pixels[1];
|
||||
pixel * tail = &pixels[0];
|
||||
pixel old_head;
|
||||
|
||||
pixel apples[10];
|
||||
unsigned char apple_num = 0;
|
||||
|
||||
direction dir = up;
|
||||
|
||||
clear_screen(0);
|
||||
|
||||
unsigned char x=0, dead=0;
|
||||
while(1){
|
||||
x++;
|
||||
old_head = *head;
|
||||
if(++head == pixels + 64) head = pixels;
|
||||
|
||||
unsigned char dead_cnt=0;
|
||||
|
||||
unsigned char apple_found = 0, j;
|
||||
for(j=0;j<apple_num;j++){
|
||||
unsigned char i;
|
||||
for(i=0;i<4;i++){
|
||||
if ( (next_pixel(old_head, i).x == apples[j].x) && (next_pixel(old_head, i).y == apples[j].y) ){
|
||||
apple_found = 1;
|
||||
dir = i;
|
||||
for(;j<apple_num-1;j++){
|
||||
apples[j]=apples[j+1];
|
||||
}
|
||||
apple_num--;
|
||||
goto apple_se;
|
||||
}
|
||||
}
|
||||
}
|
||||
apple_se:
|
||||
|
||||
if(apple_found){
|
||||
|
||||
}else{
|
||||
while(get_next_pixel(old_head, dir)){
|
||||
if((dead_cnt++)==4){
|
||||
dead = 1;
|
||||
break;
|
||||
}
|
||||
dir = direction_r(dir);
|
||||
}
|
||||
}
|
||||
|
||||
if(!dead){
|
||||
*head = next_pixel(old_head, dir);
|
||||
setpixel(*head, 3);
|
||||
|
||||
if((RANDOM8()&0xff)<80){
|
||||
unsigned char j;
|
||||
unsigned char nextapple=0, distx, disty, shortdist=255, xy=0;
|
||||
if(!apple_num){
|
||||
dir = RANDOM8()%4;
|
||||
}else{
|
||||
for(j=0;j<apple_num;j++){
|
||||
if(head->x > apples[j].x){
|
||||
distx = head->x - apples[j].x;
|
||||
}else{
|
||||
distx = apples[j].x - head->x;
|
||||
}
|
||||
if(head->y > apples[j].y){
|
||||
disty = head->y - apples[j].y;
|
||||
}else{
|
||||
disty = apples[j].y - head->y;
|
||||
}
|
||||
if ((distx + disty) < shortdist){
|
||||
shortdist = distx + disty;
|
||||
nextapple = j;
|
||||
xy = (distx > disty)?1:0;
|
||||
}
|
||||
}
|
||||
if(xy){
|
||||
dir = (apples[nextapple].x > head->x)?left:right;
|
||||
}else{
|
||||
dir = (apples[nextapple].y > head->y)?down:up;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( (apple_num<9) && ((RANDOM8()&0xff)<10) ){
|
||||
pixel new_apple = (pixel){RANDOM8()%NUM_COLS,RANDOM8()%NUM_ROWS};
|
||||
if(!get_pixel(new_apple)){
|
||||
apples[apple_num++]=new_apple;
|
||||
}
|
||||
}
|
||||
|
||||
if(!apple_found){
|
||||
clearpixel(*tail);
|
||||
if(++tail == pixels + 64) tail = pixels;
|
||||
}
|
||||
}else{
|
||||
while(tail != head){
|
||||
clearpixel(*tail);
|
||||
if((++tail)>pixels+64) tail = pixels;
|
||||
wait (60);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
for(j=0;j<apple_num;j++){
|
||||
if(x%2){
|
||||
setpixel(apples[j], 3);
|
||||
}else{
|
||||
clearpixel(apples[j]);
|
||||
}
|
||||
}
|
||||
|
||||
wait (SNAKE_DELAY);
|
||||
}
|
||||
}
|
||||
|
||||
void snake_game() {
|
||||
pixel pixels[64] = {{4, 14},{4, 13}};
|
||||
pixel * head = &pixels[1];
|
||||
pixel * tail = &pixels[0];
|
||||
pixel old_head;
|
||||
pixel apples[10];
|
||||
uint8_t joy, joy_old=0xff, joy_cmd=0xff;
|
||||
|
||||
unsigned char x, y, dead = 0;
|
||||
unsigned char apple_num = 0;
|
||||
direction dir = up;
|
||||
|
||||
unsigned char apple_found = 0;
|
||||
unsigned char j;
|
||||
|
||||
clear_screen(0);
|
||||
|
||||
// zeichne Rahmen
|
||||
for (x = 0; x < NUM_COLS; x++) {
|
||||
for (y = 0; y < NUM_ROWS; y++) {
|
||||
if (((x == 0) || (x == NUM_COLS-1)) ||
|
||||
((y == 0) || (y == NUM_ROWS-1))) {
|
||||
setpixel((pixel) {x, y}, 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
x = 0;
|
||||
while (1) {
|
||||
|
||||
x++;
|
||||
old_head = *head;
|
||||
++head;
|
||||
if (head == pixels + 64)
|
||||
head = pixels;
|
||||
|
||||
if (joy_cmd == right) {
|
||||
dir = direction_r(dir);
|
||||
joy_cmd = 0xff;
|
||||
} else if (joy_cmd == left) {
|
||||
dir = direction_r(dir);
|
||||
dir = direction_r(dir);
|
||||
dir = direction_r(dir);
|
||||
joy_cmd = 0xff;
|
||||
}
|
||||
|
||||
// kopf einen weiter bewegen
|
||||
*head = next_pixel(old_head, dir);
|
||||
|
||||
apple_found = 0;
|
||||
|
||||
// prfen ob man auf nen Apfel drauf ist
|
||||
for (j = 0; j < apple_num; j++) {
|
||||
if ( ( head->x == apples[j].x) &&
|
||||
(head->y == apples[j].y) ){
|
||||
apple_found = 1;
|
||||
for(; j < apple_num - 1; j++) {
|
||||
apples[j] = apples[j+1];
|
||||
}
|
||||
apple_num--;
|
||||
goto apple_se;
|
||||
}
|
||||
}
|
||||
if (get_pixel(*head)) {
|
||||
dead = 1;
|
||||
}
|
||||
apple_se:
|
||||
|
||||
if (!dead) {
|
||||
setpixel(*head, 3);
|
||||
|
||||
// setze neue pfel
|
||||
if ( (apple_num < 9) && (random8() < 10) ) {
|
||||
pixel new_apple = (pixel) {(random8() % (NUM_COLS-2))+1,
|
||||
(random8() % (NUM_ROWS-2))+1};
|
||||
if (!get_pixel(new_apple)){
|
||||
apples[apple_num++] = new_apple;
|
||||
}
|
||||
}
|
||||
// lsche Ende
|
||||
if (!apple_found && !dead) {
|
||||
clearpixel(*tail);
|
||||
if (++tail == pixels + 64)
|
||||
tail = pixels;
|
||||
}
|
||||
} else {
|
||||
while (tail != head) {
|
||||
clearpixel(*tail);
|
||||
if ((++tail) > pixels + 64)
|
||||
tail = pixels;
|
||||
wait (60);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
for (j = 0; j < apple_num; j++) {
|
||||
if (x % 2) {
|
||||
setpixel(apples[j], 3);
|
||||
} else {
|
||||
clearpixel(apples[j]);
|
||||
}
|
||||
}
|
||||
for(j=0;j<20;j++){
|
||||
if(JOYISLEFT){
|
||||
joy = left;
|
||||
}else if(JOYISRIGHT){
|
||||
joy = right;
|
||||
}else{
|
||||
joy = 0xff;
|
||||
}
|
||||
if(joy != joy_old){
|
||||
joy_cmd = joy;
|
||||
}
|
||||
joy_old = joy;
|
||||
wait (5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
8
animations/snake.h
Normal file
8
animations/snake.h
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#ifndef SNAKE_H_
|
||||
#define SNAKE_H_
|
||||
|
||||
void snake();
|
||||
void snake_game();
|
||||
|
||||
|
||||
#endif /* SNAKE_H_ */
|
||||
Loading…
Add table
Add a link
Reference in a new issue