Skip to content

Commit

Permalink
add some animations
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Nieß authored and Michael Nieß committed Apr 8, 2015
1 parent 25422b3 commit 658248e
Show file tree
Hide file tree
Showing 5 changed files with 202 additions and 126 deletions.
69 changes: 69 additions & 0 deletions main/anim_dice.c
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/


#include <stdlib.h>
#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);
}
}

44 changes: 25 additions & 19 deletions main/test_pixels.c → main/anim_swirl.c
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -19,26 +19,32 @@
*/


#include <stdlib.h>
#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);
}


108 changes: 104 additions & 4 deletions main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -18,16 +18,116 @@
* along with litepix. If not, see <http://www.gnu.org/licenses/>.
*/


#include <stdlib.h>
#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;
}
8 changes: 4 additions & 4 deletions main/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -18,12 +18,12 @@
* along with litepix. If not, see <http://www.gnu.org/licenses/>.
*/


#ifndef _MAIN_H_
#define _MAIN_H_

void test_pixels(void);
#include <stdint.h>

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
99 changes: 0 additions & 99 deletions main/test_transitions.c

This file was deleted.

0 comments on commit 658248e

Please sign in to comment.