From 90e2e053d25feabd2dcf384dfc262a8bcdbe3ab8 Mon Sep 17 00:00:00 2001 From: Cody Hiar Date: Sat, 5 Mar 2022 12:53:15 -0700 Subject: Initial Commit --- cli_lolcat/hello.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 cli_lolcat/hello.go (limited to 'cli_lolcat/hello.go') diff --git a/cli_lolcat/hello.go b/cli_lolcat/hello.go new file mode 100644 index 0000000..1a46da8 --- /dev/null +++ b/cli_lolcat/hello.go @@ -0,0 +1,38 @@ +package main + +import ( + "bufio" + "fmt" + "io" + "math" + "os" +) + +func rgb(i int) (int, int, int) { + var f = 0.1 + return int(math.Sin(f*float64(i)+0)*127 + 128), + int(math.Sin(f*float64(i)+2*math.Pi/3)*127 + 128), + int(math.Sin(f*float64(i)+4*math.Pi/3)*127 + 128) +} + + +func main() { + info, _ := os.Stdin.Stat() + + if info.Mode()&os.ModeCharDevice != 0 { + fmt.Println("The command is intended to work with pipes.") + fmt.Println("Usage: command | gorainbow") + } + + reader := bufio.NewReader(os.Stdin) + j := 0 + for { + input, _, err := reader.ReadRune() + if err != nil && err == io.EOF { + break + } + r, g, b := rgb(j) + fmt.Printf("\033[38;2;%d;%d;%dm%c\033[0m", r, g, b, input) + j++ + } +} -- cgit v1.2.3