mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-10 01:29:05 -04:00
Samoa, tula'i ma sisi ia lau fu'a, lou pale lea!
This commit is contained in:
parent
f9e18fa1ee
commit
fe7b6bbf89
135
src/demo/outro.c
135
src/demo/outro.c
@ -1,11 +1,52 @@
|
|||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include "demo.h"
|
#include "demo.h"
|
||||||
|
|
||||||
|
static int y;
|
||||||
|
static int targy;
|
||||||
|
static int xstart;
|
||||||
|
static struct ncplane* on;
|
||||||
|
static struct ncvisual* chncv;
|
||||||
|
|
||||||
|
static int
|
||||||
|
perframe(struct notcurses* nc, struct ncvisual* ncv __attribute__ ((unused))){
|
||||||
|
static int three = 3; // move up one every three callbacks
|
||||||
|
notcurses_render(nc);
|
||||||
|
if(y < targy){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
ncplane_move_yx(on, y, xstart);
|
||||||
|
if(--three == 0){
|
||||||
|
--y;
|
||||||
|
three = 3;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static void*
|
static void*
|
||||||
fadethread(void* vncp){
|
fadethread(void* vnc){
|
||||||
struct timespec fade = { .tv_sec = 5, .tv_nsec = 0, };
|
struct notcurses* nc = vnc;
|
||||||
ncplane_fadeout(vncp, &fade);
|
struct ncplane* ncp = notcurses_stdplane(nc);
|
||||||
return NULL;
|
struct timespec fade = { .tv_sec = 2, .tv_nsec = 0, };
|
||||||
|
ncplane_fadeout(ncp, &fade);
|
||||||
|
ncvisual_destroy(chncv);
|
||||||
|
int averr;
|
||||||
|
char* path = find_data("samoa.avi");
|
||||||
|
struct ncvisual* ncv = ncplane_visual_open(ncp, path, &averr);
|
||||||
|
free(path);
|
||||||
|
if(ncv == NULL){
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if(ncvisual_decode(ncv, &averr) == NULL){
|
||||||
|
ncvisual_destroy(ncv);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
ncvisual_stream(nc, ncv, &averr, perframe);
|
||||||
|
ncvisual_destroy(ncv);
|
||||||
|
ncplane_erase(ncp);
|
||||||
|
fade.tv_sec = 2;
|
||||||
|
fade.tv_nsec = 0;
|
||||||
|
nanosleep(&fade, NULL);
|
||||||
|
return vnc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct ncplane*
|
static struct ncplane*
|
||||||
@ -13,73 +54,74 @@ outro_message(struct notcurses* nc, int* rows, int* cols){
|
|||||||
const char str0[] = " ATL, baby! ATL! ";
|
const char str0[] = " ATL, baby! ATL! ";
|
||||||
const char str1[] = " throw your hands in the air ";
|
const char str1[] = " throw your hands in the air ";
|
||||||
const char str2[] = " hack on! —dank❤ ";
|
const char str2[] = " hack on! —dank❤ ";
|
||||||
int xstart = (*cols - (strlen(str1) + 4)) / 2;
|
int xs = (*cols - (strlen(str1) + 4)) / 2;
|
||||||
int ystart = *rows - 6;
|
int ystart = *rows - 6;
|
||||||
struct ncplane* on = notcurses_newplane(nc, 5, strlen(str1) + 4, ystart, xstart, NULL);
|
*cols = xs;
|
||||||
if(on == NULL){
|
struct ncplane* non = notcurses_newplane(nc, 5, strlen(str1) + 4, ystart, *cols, NULL);
|
||||||
|
if(non == NULL){
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
cell bgcell = CELL_SIMPLE_INITIALIZER(' ');
|
cell bgcell = CELL_SIMPLE_INITIALIZER(' ');
|
||||||
channels_set_bg_rgb(&bgcell.channels, 0x58, 0x36, 0x58);
|
channels_set_bg_rgb(&bgcell.channels, 0x58, 0x36, 0x58);
|
||||||
if(ncplane_set_default(on, &bgcell) < 0){
|
if(ncplane_set_default(non, &bgcell) < 0){
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
ncplane_dim_yx(on, rows, cols);
|
ncplane_dim_yx(non, rows, cols);
|
||||||
int ybase = 0;
|
int ybase = 0;
|
||||||
// bevel the upper corners
|
// bevel the upper corners
|
||||||
if(ncplane_set_bg_alpha(on, CELL_ALPHA_TRANSPARENT)){
|
if(ncplane_set_bg_alpha(non, CELL_ALPHA_TRANSPARENT)){
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if(ncplane_cursor_move_yx(on, ybase, 0)){
|
if(ncplane_cursor_move_yx(non, ybase, 0)){
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if(ncplane_putsimple(on, ' ') < 0 || ncplane_putsimple(on, ' ') < 0){
|
if(ncplane_putsimple(non, ' ') < 0 || ncplane_putsimple(non, ' ') < 0){
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if(ncplane_cursor_move_yx(on, ybase, *cols - 2)){
|
if(ncplane_cursor_move_yx(non, ybase, *cols - 2)){
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if(ncplane_putsimple(on, ' ') < 0 || ncplane_putsimple(on, ' ') < 0){
|
if(ncplane_putsimple(non, ' ') < 0 || ncplane_putsimple(non, ' ') < 0){
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
// ...and now the lower corners
|
// ...and now the lower corners
|
||||||
if(ncplane_cursor_move_yx(on, *rows - 1, 0)){
|
if(ncplane_cursor_move_yx(non, *rows - 1, 0)){
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if(ncplane_putsimple(on, ' ') < 0 || ncplane_putsimple(on, ' ') < 0){
|
if(ncplane_putsimple(non, ' ') < 0 || ncplane_putsimple(non, ' ') < 0){
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if(ncplane_cursor_move_yx(on, *rows - 1, *cols - 2)){
|
if(ncplane_cursor_move_yx(non, *rows - 1, *cols - 2)){
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if(ncplane_putsimple(on, ' ') < 0 || ncplane_putsimple(on, ' ') < 0){
|
if(ncplane_putsimple(non, ' ') < 0 || ncplane_putsimple(non, ' ') < 0){
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if(ncplane_set_fg_rgb(on, 0, 0, 0)){
|
if(ncplane_set_fg_rgb(non, 0, 0, 0)){
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if(ncplane_set_bg_rgb(on, 0, 180, 180)){
|
if(ncplane_set_bg_rgb(non, 0, 180, 180)){
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if(ncplane_set_bg_alpha(on, CELL_ALPHA_OPAQUE)){ // FIXME use intermediate
|
if(ncplane_set_bg_alpha(non, CELL_ALPHA_OPAQUE)){ // FIXME use intermediate
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if(ncplane_putstr_aligned(on, ++ybase, str0, NCALIGN_CENTER) < 0){
|
if(ncplane_putstr_aligned(non, ++ybase, str0, NCALIGN_CENTER) < 0){
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if(ncplane_putstr_aligned(on, ++ybase, str1, NCALIGN_CENTER) < 0){
|
if(ncplane_putstr_aligned(non, ++ybase, str1, NCALIGN_CENTER) < 0){
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if(ncplane_putstr_aligned(on, ++ybase, str2, NCALIGN_CENTER) < 0){
|
if(ncplane_putstr_aligned(non, ++ybase, str2, NCALIGN_CENTER) < 0){
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if(notcurses_render(nc)){
|
if(notcurses_render(nc)){
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
cell_release(on, &bgcell);
|
cell_release(non, &bgcell);
|
||||||
*rows = ystart;
|
*rows = ystart;
|
||||||
*cols = xstart;
|
*cols = xs;
|
||||||
return on;
|
return non;
|
||||||
}
|
}
|
||||||
|
|
||||||
int outro(struct notcurses* nc){
|
int outro(struct notcurses* nc){
|
||||||
@ -92,39 +134,36 @@ int outro(struct notcurses* nc){
|
|||||||
ncplane_dim_yx(ncp, &rows, &cols);
|
ncplane_dim_yx(ncp, &rows, &cols);
|
||||||
int averr = 0;
|
int averr = 0;
|
||||||
char* path = find_data("changes.jpg");
|
char* path = find_data("changes.jpg");
|
||||||
struct ncvisual* ncv = ncplane_visual_open(ncp, path, &averr);
|
chncv = ncplane_visual_open(ncp, path, &averr);
|
||||||
free(path);
|
free(path);
|
||||||
if(ncv == NULL){
|
if(chncv == NULL){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if(ncvisual_decode(ncv, &averr) == NULL){
|
if(ncvisual_decode(chncv, &averr) == NULL){
|
||||||
ncvisual_destroy(ncv);
|
ncvisual_destroy(chncv);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if(ncvisual_render(ncv, 0, 0, 0, 0)){
|
if(ncvisual_render(chncv, 0, 0, 0, 0)){
|
||||||
ncvisual_destroy(ncv);
|
ncvisual_destroy(chncv);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
int xstart = cols;
|
xstart = cols;
|
||||||
int ystart = rows;
|
int ystart = rows;
|
||||||
struct ncplane* on = outro_message(nc, &ystart, &xstart);
|
on = outro_message(nc, &ystart, &xstart);
|
||||||
|
y = ystart - 1;
|
||||||
|
void* ret = NULL; // thread result
|
||||||
if(on){
|
if(on){
|
||||||
|
ncplane_move_top(on);
|
||||||
pthread_t tid;
|
pthread_t tid;
|
||||||
// will fade across 5s
|
// will fade across 2s
|
||||||
pthread_create(&tid, NULL, fadethread, ncp);
|
targy = 3;
|
||||||
struct timespec iterts;
|
pthread_create(&tid, NULL, fadethread, nc);
|
||||||
int targy = rows / 2 - (rows - ystart);
|
pthread_join(tid, &ret);
|
||||||
ns_to_timespec(5000000000 / (ystart - targy), &iterts);
|
|
||||||
int y;
|
|
||||||
for(y = ystart - 1 ; y >= targy ; --y){
|
|
||||||
nanosleep(&iterts, NULL);
|
|
||||||
ncplane_move_yx(on, y, xstart);
|
|
||||||
notcurses_render(nc);
|
|
||||||
}
|
|
||||||
ncplane_fadeout(on, &demodelay);
|
ncplane_fadeout(on, &demodelay);
|
||||||
pthread_join(tid, NULL);
|
|
||||||
ncplane_destroy(on);
|
ncplane_destroy(on);
|
||||||
}
|
}
|
||||||
ncvisual_destroy(ncv);
|
if(ret == NULL){
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
return on ? 0 : -1;
|
return on ? 0 : -1;
|
||||||
}
|
}
|
||||||
|
@ -244,7 +244,7 @@ snake_thread(void* vnc){
|
|||||||
struct ncplane* n = notcurses_stdplane(nc);
|
struct ncplane* n = notcurses_stdplane(nc);
|
||||||
int dimy, dimx;
|
int dimy, dimx;
|
||||||
ncplane_dim_yx(n, &dimy, &dimx);
|
ncplane_dim_yx(n, &dimy, &dimx);
|
||||||
int snakecount = dimy / 15;
|
int snakecount = (dimy * dimx) / 800;
|
||||||
snake snakes[snakecount];
|
snake snakes[snakecount];
|
||||||
for(int s = 0 ; s < snakecount ; ++s){
|
for(int s = 0 ; s < snakecount ; ++s){
|
||||||
init_snake(&snakes[s], dimy, dimx);
|
init_snake(&snakes[s], dimy, dimx);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user