pointtools

Simple point utilities to hold text presentations.
git clone git://r-36.net/pointtools
Log | Files | Refs | README | LICENSE

commit 94fa04f4132f7db25a681f1d52f294351b58c7ca
parent e56e6e57aa64f7695dca271de1755794489b2dc6
Author: Christoph Lohmann <20h@r-36.net>
Date:   Sat, 10 Aug 2024 10:27:59 +0200

Add slide effects.

Diffstat:
MREADME.md | 4++++
Aslide-effects/fade.sh | 37+++++++++++++++++++++++++++++++++++++
Aslide-effects/interpolate.c | 86+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aslide-effects/random-animation.sh | 14++++++++++++++
4 files changed, 141 insertions(+), 0 deletions(-)

diff --git a/README.md b/README.md @@ -26,6 +26,10 @@ To view the examples: % dir2point . +Slide effects: + + % catpoint-wrap slide-effects/fade.sh *.txt + There are not many formatting options for now, but it’s enough for daily usage. If you need any graph or formatting, use troff(1) and all the diff --git a/slide-effects/fade.sh b/slide-effects/fade.sh @@ -0,0 +1,37 @@ +#!/bin/sh + +set -e + +clear + +fg_rgb() { + printf "\033[38;2;%d;%d;%dm" $1 $2 $3 +} + +def() { + printf "\033[0m" +} + +from=$1 +to=$2 + +home() { + printf "\033[;H" +} + +i=255 +while [ $i -gt 0 ]; do + fg_rgb $i $i $i + home + cat "$from" + i=$((i-1)) +done + +clear + +while [ $i -lt 255 ]; do + fg_rgb $i $i $i + home + cat "$to" + i=$((i+1)) +done diff --git a/slide-effects/interpolate.c b/slide-effects/interpolate.c @@ -0,0 +1,86 @@ +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <unistd.h> + +#define STEPS 32 + +/* SLEEPTIME in microseconds */ +#define SLEEPTIME 100 + +int +main(int argc, char *argv[]) +{ + FILE *from, *to; + int i, j, k; + int width, height; + int fromn, ton; + size_t linesize; + ssize_t r; + char **fromlines, **tolines, *line; + char fromc, toc; + + if (argc < 3) + return 1; + + if (!(from = fopen(argv[1], "r"))) + return 1; + + if (!(to = fopen(argv[2], "r"))) + return 1; + + line = NULL; + linesize = 0; + width = 0; + + fromn = 0; + fromlines = NULL; + while ((r = getline(&line, &linesize, from)) != -1) { + if (line[r-1] == '\n') + line[--r] = '\0'; + fromn++; + fromlines = realloc(fromlines, fromn * sizeof(*fromlines)); + fromlines[fromn-1] = strdup(line); + if (r > width) + width = r; + } + fclose(from); + + ton = 0; + tolines = NULL; + while ((r = getline(&line, &linesize, to)) != -1) { + if (line[r-1] == '\n') + line[--r] = '\0'; + ton++; + tolines = realloc(tolines, ton * sizeof(*tolines)); + tolines[ton-1] = strdup(line); + if (r > width) + width = r; + } + fclose(to); + + height = ton > fromn ? ton : fromn; + + printf("\033[2J"); + for (k = 0; k <= STEPS; k++) { + printf("\033[;H"); + for (i = 0; i < height; i++) { + for (j = 0; j < width; j++) { + fromc = ' '; + toc = ' '; + if (i < fromn && j < strlen(fromlines[i])) + fromc = fromlines[i][j]; + if (i < ton && j < strlen(tolines[i])) + toc = tolines[i][j]; + if (toc & 128) + putchar(toc); + else + putchar(fromc + (toc - fromc) * k / STEPS); + } + putchar('\n'); + } + usleep(SLEEPTIME); + } + + return 0; +} diff --git a/slide-effects/random-animation.sh b/slide-effects/random-animation.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +randomanimation() { + printf '%s\n' beams binarypath blackhole bouncyballs bubbles burn \ + colorshift crumble decrypt errorcorrect expand fireworks \ + middleout orbittingvolley overflow pour print rain \ + randomsequence rings scattered slice slide spotlights spray \ + swarm synthgrid unstable vhstape waves wipe \ + | sort -R | head -n 1 +} + +# From: https://github.com/ChrisBuilds/terminaltexteffects +exec tte --frame-rate 400 --input-file "$1" "$(randomanimation)" +