-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfadein.c
70 lines (61 loc) · 2.31 KB
/
fadein.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* Routines to fade the first 16 palette colors to and from black,
using the Linux console routines. (See drivers/char/console.c, look
for ESpalette) */
#include <stdio.h> /* do we need this anymore? */
#include <unistd.h> /* ioperm */
/* the default colour table, for VGA+ colour systems */
int default_red[] = {0x00,0xaa,0x00,0xaa,0x00,0xaa,0x00,0xaa,0x55,0xff,0x55,0xff,0x55,0xff,0x55,0xff};
int default_grn[] = {0x00,0x00,0xaa,0x55,0x00,0x00,0xaa,0xaa,0x55,0x55,0xff,0xff,0x55,0x55,0xff,0xff};
int default_blu[] = {0x00,0x00,0x00,0x00,0xaa,0xaa,0xaa,0xaa,0x55,0x55,0x55,0x55,0xff,0xff,0xff,0xff};
unsigned int steps=64; /* How many steps to fade in. Can be decreased for
less smooth but quicker fading. */
/* Requires two args. One is boolean (true for fade in, false for fade out),
second is fading time in ms. A third, if provided, will be used as nubmer
of steps.*/
int main(int argc, char *argv[])
{
if (argc > 3) { steps=atoi(argv[3]); }
return ( atoi(argv[1]) ? fadein(atoi(argv[2])) : fadeout(atoi(argv[2])) );
}
int fadein(int fadetime)
{
unsigned long restsize;
unsigned int i;
unsigned char j, stepsize, red, green, blue;
stepsize=256/steps;
restsize=1000 * fadetime/steps;
for (i=0; i<=255; i+=stepsize) {
printf("\e[A\n"); /* Because we get no output w/o newlines */
for (j=1; j<=15; j++) {
red=default_red[j]*i/256;
green=default_grn[j]*i/256;
blue=default_blu[j]*i/256;
/* printf("P%1XR%dG%dB%d\t", j, red, green, blue); */
printf("\e]P%1X%02X%02X%02X",j,\
red, green, blue);
}
usleep(restsize);
}
printf("\e]R");
}
int fadeout(int fadetime)
{
unsigned long restsize;
int i;
unsigned char j, stepsize, red, green, blue;
steps=64;
stepsize=256/steps;
restsize=1000 * fadetime/steps;
for (i=256; i>=0; i-=stepsize) {
printf("\e[A\n"); /* Because we get no output w/o newlines */
for (j=1; j<=15; j++) {
red=default_red[j]*i/256;
green=default_grn[j]*i/256;
blue=default_blu[j]*i/256;
/* printf("P%1XR%dG%dB%d\t", j, red, green, blue); */
printf("\e]P%1X%02X%02X%02X",j,\
red, green, blue);
}
usleep(restsize);
}
}