Added HSL and HSV colors

This commit is contained in:
2025-03-11 14:24:41 +01:00
parent 1b0b4cb28f
commit f75ff8da5a
14 changed files with 153 additions and 48 deletions

View File

@ -4,11 +4,11 @@ import (
"fmt"
)
// Color represents an RGB color.
// Color represents an sRGB color.
type Color struct {
R Value
G Value
B Value
R byte
G byte
B byte
}
// Print writes the text in the given color to standard output.
@ -18,7 +18,7 @@ func (c Color) Print(args ...any) {
return
}
fmt.Printf("\x1b[38;2;%d;%d;%dm%s\x1b[0m", byte(c.R*255), byte(c.G*255), byte(c.B*255), fmt.Sprint(args...))
fmt.Printf("\x1b[38;2;%d;%d;%dm%s\x1b[0m", c.R, c.G, c.B, fmt.Sprint(args...))
}
// Printf formats according to a format specifier and writes the text in the given color to standard output.
@ -28,7 +28,7 @@ func (c Color) Printf(format string, args ...any) {
return
}
fmt.Printf("\x1b[38;2;%d;%d;%dm%s\x1b[0m", byte(c.R*255), byte(c.G*255), byte(c.B*255), fmt.Sprintf(format, args...))
fmt.Printf("\x1b[38;2;%d;%d;%dm%s\x1b[0m", c.R, c.G, c.B, fmt.Sprintf(format, args...))
}
// Println writes the text in the given color to standard output and appends a newline.
@ -38,5 +38,5 @@ func (c Color) Println(args ...any) {
return
}
fmt.Printf("\x1b[38;2;%d;%d;%dm%s\n\x1b[0m", byte(c.R*255), byte(c.G*255), byte(c.B*255), fmt.Sprint(args...))
fmt.Printf("\x1b[38;2;%d;%d;%dm%s\n\x1b[0m", c.R, c.G, c.B, fmt.Sprint(args...))
}