Improved LCH support
This commit is contained in:
@ -1,7 +1,6 @@
|
||||
package color_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
@ -9,64 +8,71 @@ import (
|
||||
"git.akyoto.dev/go/color"
|
||||
)
|
||||
|
||||
func TestNoColors(t *testing.T) {
|
||||
func TestFprint(t *testing.T) {
|
||||
color.Terminal = true
|
||||
|
||||
color.RGB(1, 0, 0).Fprint(io.Discard, "red")
|
||||
color.RGB(0, 1, 0).Fprint(io.Discard, "green")
|
||||
color.RGB(0, 0, 1).Fprint(io.Discard, "blue")
|
||||
|
||||
color.Terminal = false
|
||||
testRGBColors(t)
|
||||
testLCHColors(t)
|
||||
|
||||
color.RGB(1, 0, 0).Fprint(io.Discard, "red")
|
||||
color.RGB(0, 1, 0).Fprint(io.Discard, "green")
|
||||
color.RGB(0, 0, 1).Fprint(io.Discard, "blue")
|
||||
}
|
||||
|
||||
func TestColors(t *testing.T) {
|
||||
color.Terminal = true
|
||||
testRGBColors(t)
|
||||
testLCHColors(t)
|
||||
}
|
||||
|
||||
func TestRainbow(t *testing.T) {
|
||||
func TestPrint(t *testing.T) {
|
||||
color.Terminal = true
|
||||
|
||||
for chroma := range 5 {
|
||||
for lightness := range 21 {
|
||||
for hue := range 80 {
|
||||
c := color.LCH(color.Value(lightness)*0.05, color.Value(chroma)*0.05, color.Value(hue)*4.5)
|
||||
c.Print("█")
|
||||
}
|
||||
color.RGB(1, 0, 0).Print("red\n")
|
||||
color.RGB(0, 1, 0).Print("green\n")
|
||||
color.RGB(0, 0, 1).Print("blue\n")
|
||||
|
||||
fmt.Println()
|
||||
}
|
||||
color.Terminal = false
|
||||
|
||||
fmt.Println()
|
||||
}
|
||||
color.RGB(1, 0, 0).Print("red\n")
|
||||
color.RGB(0, 1, 0).Print("green\n")
|
||||
color.RGB(0, 0, 1).Print("blue\n")
|
||||
}
|
||||
|
||||
func testRGBColors(t *testing.T) {
|
||||
func TestPrintln(t *testing.T) {
|
||||
color.Terminal = true
|
||||
|
||||
color.RGB(1, 0, 0).Println("red")
|
||||
color.RGB(0, 1, 0).Println("green")
|
||||
color.RGB(0, 0, 1).Println("blue")
|
||||
|
||||
color.Terminal = false
|
||||
|
||||
color.RGB(1, 0, 0).Println("red")
|
||||
color.RGB(0, 1, 0).Println("green")
|
||||
color.RGB(0, 0, 1).Println("blue")
|
||||
}
|
||||
|
||||
func TestRGB(t *testing.T) {
|
||||
color.Terminal = true
|
||||
|
||||
rgbColors := map[string]color.Color{
|
||||
"RGB.black": color.RGB(0.0, 0.0, 0.0),
|
||||
"RGB.white": color.RGB(1.0, 1.0, 1.0),
|
||||
"RGB.red": color.RGB(1.0, 0.0, 0.0),
|
||||
"RGB.green": color.RGB(0.0, 1.0, 0.0),
|
||||
"RGB.blue": color.RGB(0.0, 0.0, 1.0),
|
||||
"black": color.RGB(0, 0, 0),
|
||||
"white": color.RGB(1, 1, 1),
|
||||
"gray": color.RGB(0.5, 0.5, 0.5),
|
||||
"red": color.RGB(1, 0, 0),
|
||||
"green": color.RGB(0, 1, 0),
|
||||
"blue": color.RGB(0, 0, 1),
|
||||
"cyan": color.RGB(0, 1, 1),
|
||||
"yellow": color.RGB(1, 1, 0),
|
||||
"orange": color.RGB(1, 0.5, 0),
|
||||
"magenta": color.RGB(1, 0, 1),
|
||||
}
|
||||
|
||||
for name, c := range rgbColors {
|
||||
testColor(t, c, name)
|
||||
testColorRange(t, c)
|
||||
c.Println("█ " + name)
|
||||
}
|
||||
}
|
||||
|
||||
func testLCHColors(t *testing.T) {
|
||||
lchColors := map[string]color.Color{
|
||||
"LCH.black": color.LCH(0.0, 0.0, 0.0),
|
||||
"LCH.white": color.LCH(1.0, 0.0, 0.0),
|
||||
"LCH.red": color.LCH(0.6, 0.5, 20.0),
|
||||
"LCH.green": color.LCH(0.6, 0.5, 161.0),
|
||||
"LCH.blue": color.LCH(0.6, 0.5, 240.0),
|
||||
}
|
||||
|
||||
for name, c := range lchColors {
|
||||
testColor(t, c, name)
|
||||
}
|
||||
}
|
||||
|
||||
func testColor(t *testing.T, c color.Color, name string) {
|
||||
func testColorRange(t *testing.T, c color.Color) {
|
||||
assert.True(t, c.R >= 0.0)
|
||||
assert.True(t, c.G >= 0.0)
|
||||
assert.True(t, c.B >= 0.0)
|
||||
@ -74,8 +80,4 @@ func testColor(t *testing.T, c color.Color, name string) {
|
||||
assert.True(t, c.R <= 1.0)
|
||||
assert.True(t, c.G <= 1.0)
|
||||
assert.True(t, c.B <= 1.0)
|
||||
|
||||
c.Fprint(io.Discard, name)
|
||||
c.Print(name)
|
||||
c.Println(name)
|
||||
}
|
||||
|
Reference in New Issue
Block a user