Documentation ¶
Overview ¶
Package csscolorparser provides function for parsing CSS color string as defined in the W3C's CSS color module level 4.
Example (NamedColor) ¶
package main import ( "fmt" "github.com/mazznoer/csscolorparser" ) func main() { c, err := csscolorparser.Parse("gold") if err != nil { panic(err) } fmt.Printf("R:%.3f, G:%.3f, B:%.3f, A:%.3f\n", c.R, c.G, c.B, c.A) fmt.Println(c.RGBA255()) fmt.Println(c.HexString()) fmt.Println(c.RGBString()) }
Output: R:1.000, G:0.843, B:0.000, A:1.000 255 215 0 255 #ffd700 rgb(255,215,0)
Example (RgbColor) ¶
package main import ( "fmt" "github.com/mazznoer/csscolorparser" ) func main() { c, err := csscolorparser.Parse("rgba(100%, 0%, 0%, 0.5)") if err != nil { panic(err) } fmt.Printf("R:%.3f, G:%.3f, B:%.3f, A:%.3f\n", c.R, c.G, c.B, c.A) fmt.Println(c.RGBA255()) fmt.Println(c.HexString()) fmt.Println(c.RGBString()) }
Output: R:1.000, G:0.000, B:0.000, A:0.500 255 0 0 128 #ff000080 rgba(255,0,0,0.5)
Index ¶
- type Color
- func (c Color) Clamp() Color
- func (c Color) HexString() string
- func (c Color) MarshalText() ([]byte, error)
- func (c Color) Name() (string, bool)
- func (c Color) RGBA() (r, g, b, a uint32)
- func (c Color) RGBA255() (r, g, b, a uint8)
- func (c Color) RGBString() string
- func (c *Color) UnmarshalText(text []byte) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Color ¶
type Color struct {
R, G, B, A float64
}
R, G, B, A values in the range 0..1
func FromLinearRGB ¶ added in v0.1.4
func (Color) MarshalText ¶ added in v0.1.3
Implement the Go TextMarshaler interface
func (*Color) UnmarshalText ¶ added in v0.1.3
Implement the Go TextUnmarshaler interface
Click to show internal directories.
Click to hide internal directories.