From 69772668d454946a41166f7f45703339f8924f32 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Fri, 3 Dec 2010 01:36:55 +0100 Subject: [PATCH] initial commit --- Makefile | 10 +++++ README | 5 +++ ledbar.c | 125 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 140 insertions(+) create mode 100644 Makefile create mode 100644 README create mode 100644 ledbar.c diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..3d0eb0d --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ +CFLAGS=$(shell sdl-config --cflags) -Wall +LDFLAGS=$(shell sdl-config --libs) + +all: ledbar + +ledbar: ledbar.c + gcc ledbar.c -o ledbar $(CFLAGS) $(LDFLAGS) + +clean: + rm -f ledbar diff --git a/README b/README new file mode 100644 index 0000000..9635e08 --- /dev/null +++ b/README @@ -0,0 +1,5 @@ +* http://brmlab.cz/project/ledbar + +* control with Q, W + +* quit with escape or close the window diff --git a/ledbar.c b/ledbar.c new file mode 100644 index 0000000..cf6f523 --- /dev/null +++ b/ledbar.c @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2010 Pavol Rusnak + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include +#include +#include + +#define min(x,y) ( (x)<(y) ? (x) : (y) ) +#define max(x,y) ( (x)>(y) ? (x) : (y) ) + +#define DEBUG 1 + +#define RESX 800 +#define RESY 600 +#define BPP 32 +#define BOXES 23 + +SDL_Rect rects[BOXES]; + +void (*program)(int i, int t, double *r, double *g, double *b); + +// rainbow +void programQ(int i, int t, double *r, double *g, double *b) +{ + double index = 1.0*i/BOXES; + double time = 0.01*t; + *r = (sin(M_PI*2*index+time)+1.0)/2; + *g = (sin(M_PI*2*index+time/1.618)+1.0)/2; + *b = (sin(M_PI*2*index+time*1.618)+1.0)/2; +} + + +// knight rider +void programW(int i, int t, double *r, double *g, double *b) +{ + static float pos = BOXES/2; + static float dir = 0.001; + *r = max(1 - fabsl((pos-i)/BOXES)*4, 0); + *g = 0; + *b = 0; + pos += dir; + if (pos < 0 || pos > BOXES) dir = -dir; +} + + +void drawScreen(SDL_Surface* screen, int t) +{ + int i; + double r, g, b; + + if(SDL_MUSTLOCK(screen) && SDL_LockSurface(screen) < 0) return; + + for (i=0; iformat, r*255, g*255, b*255)); + } + + if (SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen); + SDL_Flip(screen); +} + + +int main(int argc, char* argv[]) +{ + SDL_Surface *screen; + SDL_Event event; + int quit = 0; + int t = 0; + int size; + + if (SDL_Init(SDL_INIT_VIDEO) < 0) return 1; + if (!(screen = SDL_SetVideoMode(RESX, RESY, BPP, SDL_HWSURFACE))) { + SDL_Quit(); + return 1; + } + size = (RESX-(BOXES+1)*4)/BOXES; + for (t=0; t