From 658248e20097b34f7054fc50ee9f125767ca059e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Nie=C3=9F?= Date: Wed, 8 Apr 2015 21:09:02 +0000 Subject: [PATCH] add some animations --- main/anim_dice.c | 69 +++++++++++++++++ main/{test_pixels.c => anim_swirl.c} | 44 ++++++----- main/main.c | 108 ++++++++++++++++++++++++++- main/main.h | 8 +- main/test_transitions.c | 99 ------------------------ 5 files changed, 202 insertions(+), 126 deletions(-) create mode 100644 main/anim_dice.c rename main/{test_pixels.c => anim_swirl.c} (51%) delete mode 100644 main/test_transitions.c diff --git a/main/anim_dice.c b/main/anim_dice.c new file mode 100644 index 0000000..c9e8357 --- /dev/null +++ b/main/anim_dice.c @@ -0,0 +1,69 @@ +/* + * anim_dice.c + * This file is part of litepix + * + * Copyright (C) 2015 - Michael Nieß + * + * litepix is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * litepix is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with litepix. If not, see . + */ + + +#include +#include "main.h" +#include "core/timer.h" +#include "core/pix.h" +#include "util/transitions.h" +#include "util/setter.h" + +//Create a Dice Number on a 9x9 Panel +static void fillNumber(uint8_t* canvas, uint8_t number, uint8_t *color, uint8_t *bg_color){ + set_full(canvas, bg_color); + if(number % 2 == 1){ + set_pixel(canvas,4,color); + } + if(number != 1){ + set_pixel(canvas,0,color); + set_pixel(canvas,8,color); + } + if(number >= 4){ + set_pixel(canvas,2,color); + set_pixel(canvas,6,color); + } + if(number == 6){ + set_pixel(canvas,3,color); + set_pixel(canvas,5,color); + } +} + +//Count from 1 to 6 +void anim_dice(uint32_t duration_fade, uint32_t duration_hold, uint8_t *color, uint8_t *bg_color) { + + uint8_t buffer[PIX_NUM_BYTES]; + uint8_t i; + + + + for (i = 1 ; i <= 6; i += 1) + { + fillNumber(buffer,i,color,bg_color); + tr_fade_p(buffer,duration_fade,NULL); + + t_timer timer = TIMER_INIT(duration_hold); + while(!timer_test(&timer, duration_hold)){}; + + set_full(buffer,bg_color); + tr_fade_p(buffer,duration_fade,NULL); + } +} + diff --git a/main/test_pixels.c b/main/anim_swirl.c similarity index 51% rename from main/test_pixels.c rename to main/anim_swirl.c index 02eb45d..93cc751 100644 --- a/main/test_pixels.c +++ b/main/anim_swirl.c @@ -1,8 +1,8 @@ /* - * test_pixels.c + * anim_swirl.c * This file is part of litepix * - * Copyright (C) 2015 - Florian Rommel + * Copyright (C) 2015 - Michael Nieß * * litepix is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,26 +19,32 @@ */ +#include #include "main.h" -#include "core/timer.h" #include "core/pix.h" +#include "util/transitions.h" +#include "util/setter.h" +//dim the current color +static void dim_color(uint8_t *color){ + color[0] = color[0] / 1.4; + color[1] = color[1] / 1.4; + color[2] = color[2] / 1.4; +} -void test_pixels(void) { - uint16_t x = PIX_NUM_BYTES-3; - - t_timer timer = TIMER_INIT(0); - - while (1) { - if (timer_test(&timer, 100)) { - pix_canvas[x++] = 0; - pix_canvas[x++] = 0; - pix_canvas[x++] = 0; - if (x >= PIX_NUM_BYTES) x = 0; - pix_canvas[x] = 255; - pix_canvas[x+1] = 255; - pix_canvas[x+2] = 255; - pix_render(); - } +//make a snake with fading colors +void anim_swirl(uint8_t *color, uint32_t duration, uint8_t start) { + uint8_t buffer[PIX_NUM_BYTES]; + uint8_t i; + uint8_t orig[] = {color[0], color[1], color[2]}; + uint8_t a[] = {0,1,2,5,8,7,6,3}; + for (i = start; i < start+8; i += 1) + { + set_pixel(buffer,a[i%8],orig); + dim_color(orig); } + set_pixel(buffer,4,orig); + tr_fade_p(buffer,duration,NULL); } + + diff --git a/main/main.c b/main/main.c index 2ae1b94..797b26b 100644 --- a/main/main.c +++ b/main/main.c @@ -2,7 +2,7 @@ * main.c * This file is part of litepix * - * Copyright (C) 2015 - Florian Rommel + * Copyright (C) 2015 - Florian Rommel, Michael Nieß * * litepix is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,16 +18,116 @@ * along with litepix. If not, see . */ - +#include #include "core/init.h" +#include "core/timer.h" #include "main.h" +#include "util/setter.h" +#include "util/transitions.h" +//do nothing for some milliseconds +static void pause(uint32_t milliseks){ + t_timer timer = TIMER_INIT(milliseks); + while(!timer_test(&timer, 0)){}; +} int main(void) { init_pix(); init_clock(); - test_transitions(); - + uint8_t i,j; + uint8_t buffer[PIX_NUM_BYTES]; + //Some predefined Colors + uint8_t rainbow[][3] = {{255,255,000}, //0 yellow + {255,125,000}, //1 orange + {255,000,000}, //2 red + {255,000,125}, //3 pink + {255,000,255}, //4 purple + {125,000,255}, //5 half-blue + {000,000,255}, //6 blue + {000,125,255}, //7 lightblue + {000,255,255}, //8 turkish + {000,255,125}, //9 half-green + {000,255,000}, //10 green + {125,255,000}}; //11 light green + uint8_t black[] = {0,0,0}; + + uint8_t warmwhite[] = {255,255,220}; + uint8_t blacklight[]= {10,0,10}; + + //Mask direkt to save program-space + uint8_t mask_fife[TR_MASK_SIZE] = {85,255}; + uint8_t mask_not_fife[TR_MASK_SIZE] = {170,0}; + + while(1){ + + //DO Swirlanimation with every color in every direction + for (j = 0; j < 9; j += 2) //15 + { + for (i = 0; i < 12; i++) + { + anim_swirl(rainbow[i],2500,j); + } + } + //Pink Dice + anim_dice(1000,2000,rainbow[3],black); + //Dissolve Rainbowcolor + for (i = 0; i < 12; i++) //12 + { + set_full(buffer,rainbow[i%12]); + tr_dissolve_p(buffer,6000); + } + //Green Dice + anim_dice(1000,2000,rainbow[11],black); + //Random Dissolve + for (i = 0; i < 10; i++) //10 + { + set_random(buffer); + tr_dissolve_p(buffer,6000); + + pause(1000); + + set_random(buffer); + tr_fade_p(buffer,2000,NULL); + + pause(2000); + } + //Another Dice + anim_dice(1000,2000,rainbow[8],black); + + //Mask random fade + for (i = 0; i < 10; i++) //10 + { + uint8_t randCol[] = {rand()%256,rand()%256,rand()%256}; + set_full(buffer,randCol); + tr_fade_p(buffer,1000,mask_fife); + + pause(2000); + + uint8_t randCol2[] = {rand()%256,rand()%256,rand()%256}; + set_full(buffer,randCol2); + tr_fade_p(buffer,1000,mask_not_fife); + + pause(2000); + } + //White Dice + anim_dice(1000,2000,warmwhite,blacklight); + //Random blink + for (i = 0; i < 10; i++) //10 + { + uint8_t randCol[] = {rand()%256,rand()%256,rand()%256}; + uint8_t randIndex = rand() % PIX_NUM_PIXELS; + + set_pixel(buffer,randIndex,randCol); + tr_fade_p(buffer,1500,NULL); + + pause(1500); + + set_full(buffer,black); + tr_fade_p(buffer,1500,NULL); + + pause(500); + } + } return 0; } diff --git a/main/main.h b/main/main.h index af3405a..21082eb 100644 --- a/main/main.h +++ b/main/main.h @@ -2,7 +2,7 @@ * main.h * This file is part of litepix * - * Copyright (C) 2015 - Florian Rommel + * Copyright (C) 2015 - Florian Rommel, Michael Nieß * * litepix is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,12 +18,12 @@ * along with litepix. If not, see . */ - #ifndef _MAIN_H_ #define _MAIN_H_ -void test_pixels(void); +#include -void test_transitions(void); +void anim_dice(uint32_t duration_fade, uint32_t duration_hold, uint8_t *color, uint8_t *bg_color); +void anim_swirl(uint8_t color[3],uint32_t duration, uint8_t start); #endif diff --git a/main/test_transitions.c b/main/test_transitions.c deleted file mode 100644 index 3c0423d..0000000 --- a/main/test_transitions.c +++ /dev/null @@ -1,99 +0,0 @@ -/* - * test_transitions.c - * This file is part of litepix - * - * Copyright (C) 2015 - Florian Rommel - * - * litepix is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * litepix is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with litepix. If not, see . - */ - - -#include -#include "main.h" -#include "core/pix.h" -#include "util/transitions.h" - - -static void fill(uint8_t* canvas, uint8_t r, uint8_t g, uint8_t b) { - uint8_t i; - uint8_t* p = canvas; - for (i = 0; i < PIX_NUM_PIXELS; i++) { - *p++ = g; - *p++ = r; - *p++ = b; - } -} - - -static void fill_random(uint8_t* canvas) { - uint8_t i; - uint8_t* p = canvas; - for (i = 0; i < PIX_NUM_PIXELS; i++) { - *p++ = rand() % 256; - *p++ = rand() % 256; - *p++ = rand() % 256; - } -} - - -void test_transitions(void) { - // TODO -> no fixed number - srand(46721); - - uint8_t buffer[PIX_NUM_BYTES]; - - uint8_t mask[TR_MASK_SIZE] = {0}; - uint8_t i; - for (i = 0; i < PIX_NUM_PIXELS; i += 3) { - bitmap_set(mask, i); - } - - while (1) { - fill_random(buffer); - tr_dissolve_p(buffer, 2000, NULL); - - fill(buffer, 0, 0, 0); - tr_fade_p(buffer, 1000, mask); - - fill(buffer, 0, 0, 0); - tr_fade_p(buffer, 1000, NULL); - - fill(buffer, 100, 50, 100); - tr_dissolve_p(buffer, 2000, mask); - - fill_random(buffer); - tr_dissolve_p(buffer, 2000, mask); - - tr_dissolve_p(buffer, 2400, NULL); - - fill(buffer, 255, 0, 0); - tr_roll_p(buffer, 1400, tr_left_right, NULL); - - fill(buffer, 10, 0, 10); - tr_roll_p(buffer, 1400, tr_right_left, NULL); - - fill(buffer, 0, 0, 0); - tr_dissolve_p(buffer, 2000, mask); - - fill(buffer, 0, 0, 255); - tr_fade_p(buffer, 2000, NULL); - - fill(buffer, 20, 0, 30); - tr_fade_p(buffer, 5000, NULL); - - fill(buffer, 0, 0, 0); - tr_roll_p(buffer, 2000, tr_bottom_top, NULL); - } -} -