2023-02-25 22:57:53 +05:30
|
|
|
/*
|
|
|
|
Rainbow Text (rbtext)
|
|
|
|
$ gcc -o rbtext rbtext.c
|
|
|
|
Created by Seelenlos <samoyo@protonmail.com>
|
|
|
|
|
|
|
|
NO WARRANTY OF ANY KIND.
|
|
|
|
NO LIABILITY TO CREATOR FOR ANY TYPE OF DAMAGE.
|
|
|
|
I DON'T CARE HOW YOU USE OR CONFIGURE THIS PROGRAM.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <memory.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2023-02-25 22:57:54 +05:30
|
|
|
// How many milliseconds the program will wait until the next print ( DEFAULT = 100 )
|
|
|
|
#define CONF_SLEEP_TIMEMS 100
|
|
|
|
// How many times a color should be shown before switching to the next ( DEFAULT = 2 )
|
2023-02-25 22:57:55 +05:30
|
|
|
#define CONF_COLOR_LAG 2
|
2023-02-25 22:57:54 +05:30
|
|
|
|
2023-02-25 22:57:53 +05:30
|
|
|
// BEWARE RICERS
|
|
|
|
// If you add extra colors make sure to
|
2023-02-25 22:57:54 +05:30
|
|
|
// a) Add it to the color enum
|
2023-02-25 22:57:53 +05:30
|
|
|
// b) Add the case to the switch statement in the genColors function
|
|
|
|
// c) Update the COLORS definition with the new amount of colors
|
|
|
|
// FORMAT
|
|
|
|
// #define COLOR "R;G;B"
|
|
|
|
#define RED "193;71;87"
|
|
|
|
#define ORANGE "193;116;71"
|
|
|
|
#define YELLOW "193;177;71"
|
|
|
|
#define GREEN "149;193;71"
|
|
|
|
#define CYAN "71;193;161"
|
|
|
|
#define BLUE "71;165;193"
|
|
|
|
#define PURPLE "155;71;193"
|
|
|
|
#define PINK "193;71;153"
|
|
|
|
#define COLORS 8
|
2023-02-25 22:57:54 +05:30
|
|
|
|
|
|
|
enum color {
|
|
|
|
red,orange,yellow,green,cyan,blue,purple,pink
|
|
|
|
};
|
|
|
|
|
2023-02-25 22:57:54 +05:30
|
|
|
#define addcase(enum, defin)\
|
|
|
|
case enum:\
|
|
|
|
cstr = "\e[38;2;"defin"m";\
|
|
|
|
break;
|
|
|
|
|
2023-02-25 22:57:54 +05:30
|
|
|
unsigned long long t = 0;
|
2023-02-25 22:57:53 +05:30
|
|
|
void genColors(char *s) {
|
2023-02-25 22:57:55 +05:30
|
|
|
char *cstr = malloc(20 * sizeof(char));
|
2023-02-25 22:57:54 +05:30
|
|
|
for (int i = 0; i < strlen(s); i++) {
|
2023-02-25 22:57:55 +05:30
|
|
|
enum color c = (((t + i) / CONF_COLOR_LAG) % COLORS);
|
2023-02-25 22:57:53 +05:30
|
|
|
|
|
|
|
switch (c) {
|
2023-02-25 22:57:54 +05:30
|
|
|
//addcase(enum value, #define name)
|
|
|
|
addcase(red, RED);
|
|
|
|
addcase(orange, ORANGE);
|
|
|
|
addcase(yellow, YELLOW);
|
|
|
|
addcase(green, GREEN);
|
|
|
|
addcase(cyan, CYAN);
|
|
|
|
addcase(blue, BLUE);
|
|
|
|
addcase(purple, PURPLE);
|
|
|
|
addcase(pink, PINK);
|
2023-02-25 22:57:53 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
printf("%s%c",cstr,s[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int carg, char **varg) {
|
|
|
|
if (carg < 2) {
|
2023-02-25 22:57:54 +05:30
|
|
|
printf("\e[1;31m[ERROR]\e[0m No arguments given.\n\tUSAGE: \e[34m%s \e[33m<text>\e[0m\n",varg[0]);
|
2023-02-25 22:57:53 +05:30
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2023-02-25 22:57:55 +05:30
|
|
|
char *text = malloc(1024 * sizeof(char));
|
|
|
|
|
2023-02-25 22:57:55 +05:30
|
|
|
// Similar to pythons str.join(' ') method
|
2023-02-25 22:57:53 +05:30
|
|
|
// Adds all the arguments together with spaces seperating them
|
|
|
|
// EG: ./rbtext hello world > "hello world"
|
2023-02-25 22:57:55 +05:30
|
|
|
for (int i = 1, j = 0; i < carg; i++) {
|
|
|
|
for (int k = 0; k < strlen(varg[i]); k++, j++) {
|
|
|
|
text[j] = varg[i][k];
|
2023-02-25 22:57:53 +05:30
|
|
|
}
|
2023-02-25 22:57:55 +05:30
|
|
|
|
|
|
|
text[j] = ' ';
|
|
|
|
j++;
|
2023-02-25 22:57:53 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
while (1) {
|
2023-02-25 22:57:55 +05:30
|
|
|
printf("\r\e[2K");
|
2023-02-25 22:57:53 +05:30
|
|
|
genColors(text);
|
2023-02-25 22:57:55 +05:30
|
|
|
printf("\e[0m");
|
2023-02-25 22:57:53 +05:30
|
|
|
fflush(stdout);
|
|
|
|
usleep(CONF_SLEEP_TIMEMS*1000);
|
2023-02-25 22:57:54 +05:30
|
|
|
t += 1;
|
2023-02-25 22:57:53 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2023-02-25 22:57:55 +05:30
|
|
|
}
|