summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjaseg <git@jaseg.net>2020-12-25 14:47:15 +0100
committerjaseg <git@jaseg.net>2020-12-25 14:47:15 +0100
commite6d44801456103141cc5361dbb0cf1056b1dbaba (patch)
treece0108656e67f451b321a4370ce15cc02c90b67c
parent2f5d7ab8c0d5b8bbad97c6caa4bddc4f1bbebe9d (diff)
downloadlolcat-e6d44801456103141cc5361dbb0cf1056b1dbaba.tar.gz
lolcat-e6d44801456103141cc5361dbb0cf1056b1dbaba.tar.bz2
lolcat-e6d44801456103141cc5361dbb0cf1056b1dbaba.zip
Make rgb rainbow match xterm palette more closely
-rwxr-xr-xlolcat.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/lolcat.c b/lolcat.c
index 0759079..ccfe77c 100755
--- a/lolcat.c
+++ b/lolcat.c
@@ -140,8 +140,6 @@ int main(int argc, char** argv)
}
}
- if (rgb)
- freq_h /= 10;
int rand_offset = 0;
if (random) {
srand(time(NULL));
@@ -191,12 +189,18 @@ int main(int argc, char** argv)
if (c == '\n') {
l++;
i = 0;
+
} else {
if (rgb) {
- uint8_t red = sin(((i += wcwidth(c)) * freq_h + l * freq_v) + 0 ) * 127 + 128;
- uint8_t green = sin(((i += wcwidth(c)) * freq_h + l * freq_v) + 2 * M_PI / 3 ) * 127 + 128;
- uint8_t blue = sin(((i += wcwidth(c)) * freq_h + l * freq_v) + 4 * M_PI / 3 ) * 127 + 128;
+ i += wcwidth(c);
+ float theta = i * freq_h / 5.0f + l * freq_v;
+ float offset = 0.1;
+
+ uint8_t red = lrintf((offset + (1.0f - offset) * (0.5f + 0.5f * sin(theta + 0 ))) * 255.0f);
+ uint8_t green = lrintf((offset + (1.0f - offset) * (0.5f + 0.5f * sin(theta + 2 * M_PI / 3 ))) * 255.0f);
+ uint8_t blue = lrintf((offset + (1.0f - offset) * (0.5f + 0.5f * sin(theta + 4 * M_PI / 3 ))) * 255.0f);
wprintf(L"\033[38;2;%d;%d;%dm", red, green, blue);
+
} else {
int ncc = offx * ARRAY_SIZE(codes) + (int)((i += wcwidth(c)) * freq_h + l * freq_v);
if (cc != ncc)