diff options
author | Cody Hiar <cody@hiar.ca> | 2022-03-05 12:53:15 -0700 |
---|---|---|
committer | Cody Hiar <cody@hiar.ca> | 2022-03-05 12:53:15 -0700 |
commit | 90e2e053d25feabd2dcf384dfc262a8bcdbe3ab8 (patch) | |
tree | 8e2799822b4de29014b86ca708123c1dfc8f45f5 /cli_lolcat/hello.go |
Diffstat (limited to 'cli_lolcat/hello.go')
-rw-r--r-- | cli_lolcat/hello.go | 38 |
1 files changed, 38 insertions, 0 deletions
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++ + } +} |