refactor white constructors
This commit is contained in:
parent
dc4159550c
commit
7c27d173f4
60
color.go
60
color.go
@ -29,22 +29,42 @@ type (
|
|||||||
NamedColor string
|
NamedColor string
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
WhiteCandlelight = 1500
|
||||||
|
WhiteSunset = 2000
|
||||||
|
WhiteUltraWarm = 2500
|
||||||
|
WhiteIncandescent = 2700
|
||||||
|
WhiteWarm = 3000
|
||||||
|
WhiteCool = 4000
|
||||||
|
WhiteCoolDaylight = 4500
|
||||||
|
WhiteSoftDaylight = 5000
|
||||||
|
WhiteDaylight = 5600
|
||||||
|
WhiteNoonDaylight = 6000
|
||||||
|
WhiteBrightDaylight = 6500
|
||||||
|
WhiteCloudDaylight = 7000
|
||||||
|
WhiteBlueDaylight = 7500
|
||||||
|
WhiteBlueOvercast = 8000
|
||||||
|
WhiteBlueIce = 9000
|
||||||
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
Candlelight = func() HSBKColor { c, _ := NewWhite(1500); return c }
|
DefaultWhites = map[string]int{
|
||||||
Sunset = func() HSBKColor { c, _ := NewWhite(2000); return c }
|
"candlelight": WhiteCandlelight,
|
||||||
UltraWarm = func() HSBKColor { c, _ := NewWhite(2500); return c }
|
"sunset": WhiteSunset,
|
||||||
Incandescent = func() HSBKColor { c, _ := NewWhite(2700); return c }
|
"ultrawarm": WhiteUltraWarm,
|
||||||
Warm = func() HSBKColor { c, _ := NewWhite(3000); return c }
|
"incandesent": WhiteIncandescent,
|
||||||
Cool = func() HSBKColor { c, _ := NewWhite(4000); return c }
|
"warm": WhiteWarm,
|
||||||
CoolDaylight = func() HSBKColor { c, _ := NewWhite(4500); return c }
|
"cool": WhiteCool,
|
||||||
SoftDaylight = func() HSBKColor { c, _ := NewWhite(5000); return c }
|
"cooldaylight": WhiteCoolDaylight,
|
||||||
Daylight = func() HSBKColor { c, _ := NewWhite(5600); return c }
|
"softdaylight": WhiteSoftDaylight,
|
||||||
NoonDaylight = func() HSBKColor { c, _ := NewWhite(6000); return c }
|
"daylight": WhiteDaylight,
|
||||||
BrightDaylight = func() HSBKColor { c, _ := NewWhite(6500); return c }
|
"noondaylight": WhiteNoonDaylight,
|
||||||
CloudDaylight = func() HSBKColor { c, _ := NewWhite(7000); return c }
|
"brightdaylight": WhiteBrightDaylight,
|
||||||
BlueDaylight = func() HSBKColor { c, _ := NewWhite(7500); return c }
|
"clouddaylight": WhiteCloudDaylight,
|
||||||
BlueOvercast = func() HSBKColor { c, _ := NewWhite(8000); return c }
|
"bluedaylight": WhiteBlueDaylight,
|
||||||
BlueIce = func() HSBKColor { c, _ := NewWhite(9000); return c }
|
"blueovercast": WhiteBlueOvercast,
|
||||||
|
"blueice": WhiteBlueIce,
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewRGBColor(r, g, b uint8) (*RGBColor, error) {
|
func NewRGBColor(r, g, b uint8) (*RGBColor, error) {
|
||||||
@ -89,6 +109,16 @@ func NewWhite(k int16) (HSBKColor, error) {
|
|||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewWhiteString(s string) (HSBKColor, error) {
|
||||||
|
k, ok := DefaultWhites[s]
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
return HSBKColor{}, fmt.Errorf("'%s' is not a valid default white", s)
|
||||||
|
}
|
||||||
|
|
||||||
|
return NewWhite(int16(k))
|
||||||
|
}
|
||||||
|
|
||||||
func (c RGBColor) ColorString() string {
|
func (c RGBColor) ColorString() string {
|
||||||
return fmt.Sprintf("rgb:%d,%d,%d", c.R, c.G, c.B)
|
return fmt.Sprintf("rgb:%d,%d,%d", c.R, c.G, c.B)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user