commit: 4d19b25e5ae31c57ad08a0250aa191692de325ec
parent: e83814b9c40e8f0098e3e03315fb1d3155dafe9f
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Sun, 7 Oct 2018 20:59:38 +0200
src/lolcat.c: New Program
C replacement for the well-known lolcat program in ruby:
https://github.com/busyloop/lolcat
Diffstat:
2 files changed, 37 insertions(+), 0 deletions(-)
diff --git a/mkfile b/mkfile
@@ -19,3 +19,5 @@ clean:
rm -v $bins
%.c:
$CC $CFLAGS -o bin/$stem src/$stem.c
+lolcat.c:
+ $CC $CFLAGS -lm -o bin/lolcat src/lolcat.c
diff --git a/src/lolcat.c b/src/lolcat.c
@@ -0,0 +1,35 @@
+// Copyright 2018 Haelwenn (lanodan) Monnier <contact@hacktivis.me>
+// Distributed under the terms of the CC-BY-SA-4.0 license
+
+#include <stdio.h> /* getchar(), putchar(), snprintf(), printf() */
+#include <math.h> /* sin() */
+
+void rainbow(double freq, int i) {
+ int red, green, blue;
+ double pi = 3.14159;
+
+ red = sin(freq*i + 0) * 127 + 128;
+ green = sin(freq*i + 2*pi/3) * 127 + 128;
+ blue = sin(freq*i + 4*pi/3) * 127 + 128;
+
+ printf("[38;2;%02d;%02d;%02dm", red, green, blue);
+ // TODO: Replace to sprintf?
+}
+
+int main(void) {
+ int c, i;
+ double freq = 0.1;
+
+ i = 0;
+
+ while((c = getchar()) != EOF)
+ {
+ rainbow(freq, i);
+ i++;
+ putchar(c);
+ }
+
+ printf("[0m");
+
+ return 0;
+}