diff --git a/configure.ac b/configure.ac index 8101b2f..5684d12 100644 --- a/configure.ac +++ b/configure.ac @@ -30,6 +30,7 @@ AC_ARG_ENABLE(x11, AC_CHECK_HEADERS(inttypes.h endian.h) AC_CHECK_FUNCS(vsnprintf getenv putenv strcasecmp usleep Sleep) +AC_CHECK_LIB(m, sin, MATH_LIBS="${MATH_LIBS} -lm") CACA_DRIVERS="" @@ -120,6 +121,7 @@ else AC_MSG_RESULT([${CACA_DRIVERS}]) fi +AC_SUBST(MATH_LIBS) AC_SUBST(CACA_LIBS) # Optimizations diff --git a/examples/Makefile.am b/examples/Makefile.am index 555d81c..1774c5e 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -6,10 +6,10 @@ pkgdata_DATA = caca.txt EXTRA_DIST = caca.txt -bin_PROGRAMS = cacademo cacafire cacaball cacaview +bin_PROGRAMS = cacademo cacafire cacaball cacaplas cacaview cacademo_SOURCES = demo.c -cacademo_LDADD = ../src/libcaca.a @CACA_LIBS@ -lm +cacademo_LDADD = ../src/libcaca.a @CACA_LIBS@ @MATH_LIBS@ cacademo_CPPFLAGS = -I$(top_srcdir)/src -DDATADIR=\"$(pkgdatadir)\" cacafire_SOURCES = aafire.c @@ -17,9 +17,13 @@ cacafire_LDADD = ../src/libcaca.a @CACA_LIBS@ cacafire_CPPFLAGS = -I$(top_srcdir)/src -DLIBCACA=1 cacaball_SOURCES = cacaball.c -cacaball_LDADD = ../src/libcaca.a @CACA_LIBS@ +cacaball_LDADD = ../src/libcaca.a @CACA_LIBS@ @MATH_LIBS@ cacaball_CPPFLAGS = -I$(top_srcdir)/src +cacaplas_SOURCES = cacaplas.c +cacaplas_LDADD = ../src/libcaca.a @CACA_LIBS@ @MATH_LIBS@ +cacaplas_CPPFLAGS = -I$(top_srcdir)/src + cacaview_SOURCES = cacaview.c cacaview_LDADD = ../src/libcaca.a @CACA_LIBS@ cacaview_CPPFLAGS = -I$(top_srcdir)/src -DX_DISPLAY_MISSING=1 diff --git a/examples/cacaplas.c b/examples/cacaplas.c new file mode 100644 index 0000000..3eca61e --- /dev/null +++ b/examples/cacaplas.c @@ -0,0 +1,140 @@ +/* + * cacaplas plasma effect for libcaca + * Copyright (c) 2004 Sam Hocevar + * 1998 Bini Michele + * All Rights Reserved + * + * $Id$ + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This program 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA + */ + +#include "config.h" + +#include + +#ifndef M_PI +# define M_PI 3.14159265358979323846 +#endif + +#include "caca.h" + +/* Virtual buffer size */ +#define XSIZ 256 +#define YSIZ 256 + +#define TABLEX (XSIZ * 2) +#define TABLEY (YSIZ * 2) + +static unsigned char screen[XSIZ * YSIZ]; +static unsigned char table[TABLEX * TABLEY]; + +static void do_plasma(unsigned char *, + double, double, double, double, double, double); + +int main (int argc, char **argv) +{ + int red[256], green[256], blue[256], alpha[256]; + double r[3], R[6]; + struct caca_bitmap *bitmap; + int i, x, y, frame; + + if(caca_init() < 0) + return 1; + + caca_set_delay(10000); + + /* Fill various tables */ + for(i = 0 ; i < 256; i++) + red[i] = green[i] = blue[i] = alpha[i] = 0; + + for(i = 0; i < 3; i++) + r[i] = (double)(caca_rand(1, 1000)) / 30000 * M_PI; + + for(i = 0; i < 6; i++) + R[i] = (double)(caca_rand(1, 1000)) / 5000; + + for(y = 0 ; y < TABLEY ; y++) + for(x = 0 ; x < TABLEX ; x++) + { + double tmp = (((double)((x - (TABLEX / 2)) * (x - (TABLEX / 2)) + + (y - (TABLEX / 2)) * (y - (TABLEX / 2)))) + * (M_PI / (TABLEX * TABLEX + TABLEY * TABLEY))); + + table[x + y * TABLEX] = (1.0 + sin(12.0 * sqrt(tmp))) * 256 / 6; + } + + /* Create a libcaca bitmap */ + bitmap = caca_create_bitmap(8, XSIZ, YSIZ, XSIZ, 0, 0, 0, 0); + + /* Main loop */ + for(frame = 0; !caca_get_event(CACA_EVENT_KEY_PRESS); frame++) + { + for(i = 0 ; i < 256; i++) + { + double z = ((double)i) / 256 * 6 * M_PI; + + red[i] = (1.0 + cos(z + r[0] * frame)) / 2 * 0xfff; + green[i] = (1.0 + sin(z + r[1] * frame)) / 2 * 0xfff; + blue[i] = (1.0 + cos(z + r[2] * frame)) / 2 * 0xfff; + } + + /* Set the palette */ + caca_set_bitmap_palette(bitmap, red, green, blue, alpha); + + do_plasma(screen, + (1.0 + sin(((double)frame) * R[0])) / 2, + (1.0 + sin(((double)frame) * R[1])) / 2, + (1.0 + sin(((double)frame) * R[2])) / 2, + (1.0 + sin(((double)frame) * R[3])) / 2, + (1.0 + sin(((double)frame) * R[4])) / 2, + (1.0 + sin(((double)frame) * R[5])) / 2); + + caca_draw_bitmap(0, 0, caca_get_width() - 1, caca_get_height() - 1, + bitmap, screen); + caca_refresh(); + } + + caca_free_bitmap(bitmap); + caca_end(); + + return 0; +} + +static void do_plasma(unsigned char *pixels, double x_1, double y_1, + double x_2, double y_2, double x_3, double y_3) +{ + unsigned int X1 = x_1 * (TABLEX / 2), + Y1 = y_1 * (TABLEY / 2), + X2 = x_2 * (TABLEX / 2), + Y2 = y_2 * (TABLEY / 2), + X3 = x_3 * (TABLEX / 2), + Y3 = y_3 * (TABLEY / 2); + unsigned int y; + unsigned char * t1 = table + X1 + Y1 * TABLEX, + * t2 = table + X2 + Y2 * TABLEX, + * t3 = table + X3 + Y3 * TABLEX; + + for(y = 0; y < YSIZ; y++) + { + unsigned int x; + unsigned char * tmp = pixels + y * YSIZ; + unsigned int ty = y * TABLEX, tmax = ty + XSIZ; + for(x = 0; ty < tmax; ty++, tmp++) + tmp[0] = t1[ty] + t2[ty] + t3[ty]; + } +} +