Just for fun, I made a very simple (i.e. bloat-free) implementation in C. No dependencies, except the C standard library. Here it is printing its own source code:
I don’t feel like implementing all the fancy features (bloat) that lolcat
has, I leave that as an exercise to the reader. It’s very rudimentary, doesn’t even concatenate files, doesn’t handle unicode, doesn’t handle ANSI codes, etc… but at least it doesn’t have 50 ruby dependencies…
Here is the source code as text
This is obsolete now, look below for updated versions.
// compile with: gcc atrazine.c -o atrazine -lm -O2
#include <math.h>
#include <stdio.h>
#define CSI "\033["
void rainbow(float phase) {
printf("%s38;2;%d;%d;%dm", CSI,
/* red */ (int) (sinf(phase + 0 ) * 127 + 128),
/* green */ (int) (sinf(phase + 2*M_PI/3) * 127 + 128),
/* blue */ (int) (sinf(phase + 4*M_PI/3) * 127 + 128));
}
int main() {
int nl_offset = 3;
float omega = 0.1f;
int t = 0;
int line = 0;
char c;
rainbow(omega*t);
while ((c = getchar()) != EOF) {
if (c == '\n') {
t = 0;
line++;
printf("%sm\n", CSI);
} else {
printf("%c", c);
}
rainbow(omega*((++t) + nl_offset * line));
}
printf("%sm\n", CSI);
}