Преглед на файлове

* examples/cacaballs.c:

+ Bigger metaballs, less metaballs.
    + Rotating palette.
  * examples/cacaplas.c:
    + Slightly decreased speed.
  * examples/cacacirc.c:
    + New effect.
tags/v0.99.beta14
Sam Hocevar sam преди 21 години
родител
ревизия
308beca482
променени са 4 файла, в които са добавени 183 реда и са изтрити 18 реда
  1. +5
    -1
      examples/Makefile.am
  2. +33
    -16
      examples/cacaball.c
  3. +144
    -0
      examples/cacacirc.c
  4. +1
    -1
      examples/cacaplas.c

+ 5
- 1
examples/Makefile.am Целия файл

@@ -6,7 +6,7 @@ pkgdata_DATA = caca.txt

EXTRA_DIST = caca.txt

bin_PROGRAMS = cacademo cacafire cacaball cacaplas cacaview
bin_PROGRAMS = cacademo cacafire cacaball cacaplas cacaview cacacirc

cacademo_SOURCES = demo.c
cacademo_LDADD = ../src/libcaca.a @CACA_LIBS@ @MATH_LIBS@
@@ -24,6 +24,10 @@ cacaplas_SOURCES = cacaplas.c
cacaplas_LDADD = ../src/libcaca.a @CACA_LIBS@ @MATH_LIBS@
cacaplas_CPPFLAGS = -I$(top_srcdir)/src

cacacirc_SOURCES = cacacirc.c
cacacirc_LDADD = ../src/libcaca.a @CACA_LIBS@ @MATH_LIBS@
cacacirc_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


+ 33
- 16
examples/cacaball.c Целия файл

@@ -28,6 +28,10 @@
#include <string.h>
#include <math.h>

#ifndef M_PI
# define M_PI 3.14159265358979323846
#endif

#include "caca.h"

/* Virtual buffer size */
@@ -35,10 +39,10 @@
#define YSIZ 256

#define METASIZE 100
#define METABALLS 24
#define METABALLS 16

/* Colour index where to crop balls */
#define CROPBALL 180
#define CROPBALL 160

static void create_ball(void);
static void draw_ball(unsigned int, unsigned int);
@@ -53,34 +57,23 @@ int main(int argc, char **argv)
unsigned int x[METABALLS], y[METABALLS];
struct caca_bitmap *caca_bitmap;
float i = 10.0, j = 17.0, k = 11.0;
int p;
int p, frame = 0;

if(caca_init())
return 1;

caca_set_delay(10000);
caca_set_delay(20000);

/* Make the palette eatable by libcaca */
for(p = 0; p < 256; p++)
{
r[p] = p < 0x40 ? 0 : p < 0xc0 ? (p - 0x40) * 0x20 : 0xfff;
g[p] = p < 0xc0 ? 0 : (p - 0xc0) * 0x40;
b[p] = p < 0x40 ? p * 0x40 : 0xfff;
a[p] = 0x0;
}

/* Crop the palette */
for(p = 0; p < CROPBALL; p++)
r[p] = g[p] = b[p] = a[p] = 0x0;
r[255] = g[255] = b[255] = 0xfff;

/* Create a libcaca bitmap smaller than our pixel buffer, so that we
* display only the interesting part of it */
caca_bitmap = caca_create_bitmap(8, XSIZ - METASIZE, YSIZ - METASIZE,
XSIZ, 0, 0, 0, 0);

/* Set the palette */
caca_set_bitmap_palette(caca_bitmap, r, g, b, a);

/* Generate ball sprite */
create_ball();

@@ -95,6 +88,30 @@ int main(int argc, char **argv)
/* Go ! */
while(!caca_get_event(CACA_EVENT_KEY_PRESS))
{
frame++;

/* Crop the palette */
for(p = CROPBALL; p < 255; p++)
{
int t1, t2, t3;
t1 = p < 0x40 ? 0 : p < 0xc0 ? (p - 0x40) * 0x20 : 0xfff;
t2 = p < 0xe0 ? 0 : (p - 0xe0) * 0x80;
t3 = p < 0x40 ? p * 0x40 : 0xfff;

r[p] = (1.0 + sin((double)frame * M_PI / 60)) * t1 / 4
+ (1.0 + sin((double)(frame + 40) * M_PI / 60)) * t2 / 4
+ (1.0 + sin((double)(frame + 80) * M_PI / 60)) * t3 / 4;
g[p] = (1.0 + sin((double)frame * M_PI / 60)) * t2 / 4
+ (1.0 + sin((double)(frame + 40) * M_PI / 60)) * t3 / 4
+ (1.0 + sin((double)(frame + 80) * M_PI / 60)) * t1 / 4;
b[p] = (1.0 + sin((double)frame * M_PI / 60)) * t3 / 4
+ (1.0 + sin((double)(frame + 40) * M_PI / 60)) * t1 / 4
+ (1.0 + sin((double)(frame + 80) * M_PI / 60)) * t2 / 4;
}

/* Set the palette */
caca_set_bitmap_palette(caca_bitmap, r, g, b, a);

/* Silly paths for our balls */
for(p = 0; p < METABALLS; p++)
{


+ 144
- 0
examples/cacacirc.c Целия файл

@@ -0,0 +1,144 @@
/*
* cacacirc circle effect for libcaca
* Copyright (c) 2004 Sam Hocevar <sam@zoy.org>
* 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 <math.h>
#include <string.h>

#include "caca.h"

/* Virtual buffer size */
#define XSIZ 256
#define YSIZ 256

#define DISCSIZ 512
#define DISCTHICKNESS 64

static unsigned char screen[XSIZ * YSIZ];
static unsigned char disc[DISCSIZ * DISCSIZ];

static void put_disc(int, int);
static void draw_disc(int, char);
static void draw_line(int, int, char);

int main (int argc, char **argv)
{
int red[256], green[256], blue[256], alpha[256];
struct caca_bitmap *bitmap;
int i, x, y, frame;

if(caca_init() < 0)
return 1;

caca_set_delay(20000);

/* Fill various tables */
for(i = 0 ; i < 256; i++)
red[i] = green[i] = blue[i] = alpha[i] = 0;

red[0] = green[0] = blue[0] = 0x777;
red[1] = green[1] = blue[1] = 0xfff;

/* Fill the circle */
for(i = DISCSIZ * 2; i > 0; i -= DISCTHICKNESS)
draw_disc(i, (i / DISCTHICKNESS) % 2);

/* 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++)
{
memset(screen, 0, XSIZ * YSIZ);

/* Set the palette */
red[0] = 0.5 * (1 + sin(0.05 * frame)) * 0xfff;
green[0] = 0.5 * (1 + cos(0.07 * frame)) * 0xfff;
blue[0] = 0.5 * (1 + cos(0.06 * frame)) * 0xfff;

red[1] = 0.5 * (1 + sin(0.07 * frame + 5.0)) * 0xfff;
green[1] = 0.5 * (1 + cos(0.06 * frame + 5.0)) * 0xfff;
blue[1] = 0.5 * (1 + cos(0.05 * frame + 5.0)) * 0xfff;

caca_set_bitmap_palette(bitmap, red, green, blue, alpha);

/* Draw circles */
x = cos(0.07 * frame + 5.0) * 128.0 + (XSIZ / 2);
y = sin(0.11 * frame) * 128.0 + (YSIZ / 2);
put_disc(x, y);

x = cos(0.13 * frame + 2.0) * 64.0 + (XSIZ / 2);
y = sin(0.09 * frame + 1.0) * 64.0 + (YSIZ / 2);
put_disc(x, y);

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 put_disc(int x, int y)
{
char *src = disc + (DISCSIZ / 2 - x) + (DISCSIZ / 2 - y) * DISCSIZ;
int i, j;

for(j = 0; j < YSIZ; j++)
for(i = 0; i < XSIZ; i++)
{
screen[i + XSIZ * j] ^= src[i + DISCSIZ * j];
}
}

static void draw_disc(int r, char color)
{
int t, dx, dy;

for(t = 0, dx = 0, dy = r; dx <= dy; dx++)
{
draw_line(dx / 3, dy / 3, color);
draw_line(dy / 3, dx / 3, color);

t += t > 0 ? dx - dy-- : dx;
}
}

static void draw_line(int x, int y, char color)
{
if(x == 0 || y == 0 || y > DISCSIZ / 2)
return;

if(x > DISCSIZ / 2)
x = DISCSIZ / 2;

memset(disc + (DISCSIZ / 2) - x + DISCSIZ * ((DISCSIZ / 2) - y),
color, 2 * x - 1);
memset(disc + (DISCSIZ / 2) - x + DISCSIZ * ((DISCSIZ / 2) + y - 1),
color, 2 * x - 1);
}


+ 1
- 1
examples/cacaplas.c Целия файл

@@ -55,7 +55,7 @@ int main (int argc, char **argv)
if(caca_init() < 0)
return 1;

caca_set_delay(10000);
caca_set_delay(20000);

/* Fill various tables */
for(i = 0 ; i < 256; i++)


Зареждане…
Отказ
Запис