Created
February 13, 2018 15:16
-
-
Save ledeuns/26a943f3a0673a399b71f8e817f17b36 to your computer and use it in GitHub Desktop.
AuvernIX wishes 2016
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* CACA_DRIVER=raw ./figfont "Happy New Year from AuvernIX ! We wish you many peerings & much bandwidth for 2016. A massive 'thank you' to our supportive members. We love you ! Contact us @AuvernIX or contact@auvernix.org if you'd like to join." | cacaserver */ | |
//#include "config.h" | |
#if !defined(__KERNEL__) | |
# include <stdio.h> | |
# include <stdlib.h> | |
#endif | |
#include "caca.h" | |
caca_canvas_t *create_srctxt(char *); | |
void copycanvas(caca_canvas_t *, caca_canvas_t *, unsigned int); | |
void drawbg(caca_canvas_t *); | |
void drawtree(caca_canvas_t *, unsigned int, unsigned int); | |
/* Convert a string to one-liner figlet canvas */ | |
caca_canvas_t *create_srctxt(char *txt) | |
{ | |
caca_canvas_t *fcv, *cvol; | |
static unsigned char const xmas[] = { | |
CACA_GREEN, CACA_LIGHTRED, CACA_WHITE, | |
CACA_LIGHTGREEN, CACA_RED, | |
}; | |
unsigned int x, y, w, h; | |
/* Init figlet cv */ | |
fcv = caca_create_canvas(0, 0); | |
if(caca_canvas_set_figfont(fcv, "/usr/share/figlet/mono12")) | |
return NULL; | |
/* Fill figlet cv */ | |
while(txt[0]) { | |
caca_put_figchar(fcv, txt++[0]); | |
} | |
w = caca_get_canvas_width(fcv); | |
h = caca_get_canvas_height(fcv); | |
/* Colorize with x-mas colors & convert to one-liner cv */ | |
cvol = caca_create_canvas(w*(h/10), 10); | |
for(y = 0; y < h; y++) | |
for(x = 0; x < w; x++) { | |
unsigned long int ch = caca_get_char(fcv, x, y); | |
if(ch != (unsigned char)' ') | |
caca_set_color_ansi(cvol, xmas[(x + y) % 5], CACA_TRANSPARENT); | |
else | |
caca_set_color_ansi(cvol, CACA_TRANSPARENT, CACA_TRANSPARENT); | |
caca_put_char(cvol, x+((y/10)*w), y%10, ch); | |
} | |
caca_free_canvas(fcv); | |
return cvol; | |
} | |
void copycanvas(caca_canvas_t *dst, caca_canvas_t *src, unsigned int pos) | |
{ | |
unsigned int x, y, w, h; | |
unsigned int wd, hd, ws, hs; | |
unsigned int xs; | |
ws = caca_get_canvas_width(src); | |
wd = caca_get_canvas_width(dst); | |
hs = caca_get_canvas_height(src); | |
hd = caca_get_canvas_height(dst); | |
/* Get smaller canvas so we can't overflow */ | |
h = hd>hs?hs:hd; | |
w = wd>ws?ws:wd; | |
/* Treat src as a rotating buffer */ | |
xs = pos%ws; | |
for(y = 0; y < h; y++) | |
for(x = 0; x < w; x++) { | |
caca_put_char(dst, x, y, caca_get_char(src, (x+xs)%ws, y%hs)); | |
caca_put_attr(dst, x, y, caca_get_attr(src, (x+xs)%ws, y%hs)); | |
} | |
} | |
void drawtree(caca_canvas_t *dst, unsigned int x, unsigned int y) | |
{ | |
unsigned int w, h; | |
w = caca_get_canvas_width(dst); | |
h = caca_get_canvas_height(dst); | |
if (x >= w-9) | |
return; | |
if (y >= h-7) | |
return; | |
caca_set_color_ansi(dst, CACA_BROWN, CACA_BROWN); | |
caca_put_char(dst, x+3, y+5, ' '); caca_put_char(dst, x+3, y+6, ' '); | |
caca_put_char(dst, x+4, y+5, ' '); caca_put_char(dst, x+4, y+6, ' '); | |
caca_put_char(dst, x+5, y+5, ' '); caca_put_char(dst, x+5, y+6, ' '); | |
caca_set_color_ansi(dst, CACA_GREEN, CACA_GREEN); | |
caca_put_char(dst, x+4, y, ' '); | |
caca_put_char(dst, x+3, y+1, ' '); | |
caca_put_char(dst, x+4, y+1, ' '); | |
caca_put_char(dst, x+5, y+1, ' '); | |
caca_put_char(dst, x+2, y+2, ' '); | |
caca_put_char(dst, x+3, y+2, ' '); | |
caca_put_char(dst, x+4, y+2, ' '); | |
caca_put_char(dst, x+5, y+2, ' '); | |
caca_put_char(dst, x+6, y+2, ' '); | |
caca_put_char(dst, x+1, y+3, ' '); | |
caca_put_char(dst, x+2, y+3, ' '); | |
caca_put_char(dst, x+3, y+3, ' '); | |
caca_put_char(dst, x+4, y+3, ' '); | |
caca_put_char(dst, x+5, y+3, ' '); | |
caca_put_char(dst, x+6, y+3, ' '); | |
caca_put_char(dst, x+7, y+3, ' '); | |
caca_put_char(dst, x, y+4, ' '); | |
caca_put_char(dst, x+1, y+4, ' '); | |
caca_put_char(dst, x+2, y+4, ' '); | |
caca_put_char(dst, x+3, y+4, ' '); | |
caca_put_char(dst, x+4, y+4, ' '); | |
caca_put_char(dst, x+5, y+4, ' '); | |
caca_put_char(dst, x+6, y+4, ' '); | |
caca_put_char(dst, x+7, y+4, ' '); | |
caca_put_char(dst, x+8, y+4, ' '); | |
} | |
void drawbg(caca_canvas_t *dst) | |
{ | |
unsigned int x, y, w, h; | |
w = caca_get_canvas_width(dst); | |
h = caca_get_canvas_height(dst); | |
for(y = h-3; y < h; y++) | |
for(x = 0; x < w; x++) { | |
caca_set_color_ansi(dst, CACA_WHITE, CACA_WHITE); | |
caca_put_char(dst, x, y, ' '); | |
} | |
drawtree(dst, 0, h-9); | |
drawtree(dst, 10, h-9); | |
drawtree(dst, 20, h-9); | |
drawtree(dst, 30, h-9); | |
drawtree(dst, 40, h-9); | |
drawtree(dst, 50, h-9); | |
drawtree(dst, 60, h-9); | |
drawtree(dst, 70, h-9); | |
} | |
#define SPEED 1 | |
int main(int argc, char *argv[]) | |
{ | |
caca_canvas_t *cv, *cvtxt; | |
caca_display_t *dp; | |
unsigned int pos; | |
cv = caca_create_canvas(80, 24); | |
if(cv == NULL) { | |
printf("cv == NULL\n"); | |
return -1; | |
} | |
dp = caca_create_display(cv); | |
if(dp == NULL) { | |
printf("dp == NULL\n"); | |
return -1; | |
} | |
caca_set_display_time(dp, 40000); | |
cvtxt = create_srctxt(argv[1]); | |
if(cvtxt == NULL) { | |
printf("cvtxt == NULL\n"); | |
return -1; | |
} | |
drawbg(cv); | |
pos = 0; | |
while(1) { | |
copycanvas(cv, cvtxt, pos); | |
caca_refresh_display(dp); | |
pos += SPEED; | |
} | |
caca_free_canvas(cvtxt); | |
caca_free_canvas(cv); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment