Documentation
¶
Overview ¶
Package rgb provides a RGBA color type, which is a uint32, with a set of methods to manipulate the color.
Color type is a 32bits color: 24bits for the RGB color itself and 8 bits for the alpha channel (transparency/opacity)
Index ¶
- Constants
- type Color
- func (c Color) Alpha() uint8
- func (c Color) Blue() uint8
- func (c Color) Darken(factor float32) Color
- func (c Color) GrayScale() Color
- func (c Color) Green() uint8
- func (c Color) Hexa() string
- func (c Color) Lighten(factor float32) Color
- func (c Color) Opacify(opacityfactor float32) Color
- func (c Color) RGB() (R uint8, G uint8, B uint8)
- func (c Color) RGBA() (R uint8, G uint8, B uint8, A uint8)
- func (c Color) Red() uint8
Examples ¶
Constants ¶
const ( Red = Color(0xff0000ff) Green = Color(0x00ff00ff) Blue = Color(0x0000ffff) Yellow = Color(0xffff00ff) Cyan = Color(0x00ffffff) Magenta = Color(0xff00ffff) Black = Color(0x000000ff) Silver = Color(0xc0c0c0ff) Gray = Color(0x808080ff) White = Color(0xffffffff) None = Color(0x00000000) )
Basic RGB Colors
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Color ¶
type Color uint32
Color is a 32bits color: 24bits for the Color color itself and 8 bits for the alpha channel (transparency/opacity)
func MakeRGBA ¶
MakeRGBA create a 24bits RGB color with an Alpha channel for the opacity. Alpha varies from 0 (full transprency) to 255 (full opacity)
func ParseHexa ¶
ParseHexa create a 24bits color with 100% opacity.
Accepted string formats:
the string can start with '#' but it s optional '#A' means a color with R="0xAA", G="0xAA", B="0xAA", and a full opacity '#ABC' means a color with R="0xAA", G="0xBB", B="0xCC", and a full opacity '#ABCD' means a color with R="0xAA", G="0xBB", B="0xCC", and an opacity of "0xDD" '#ABCDEF' means a color with R="0xAB", G="0xCD", B="0xEF", and a full opacity '#ABCDEF88' means a color with R="0xAB", G="0xCD", B="0xEF", and an opacity of "0x88"
return nil if unable to convert the string in a valid color
func (Color) Darken ¶
Create a darker color, usefull to create a shade for example. The factor values is between 0 and 1. Alpha chanel stays unchanged.
A factor >= 1 returns an unchanged color A factor <= 0 returns BLACK
func (Color) Hexa ¶
Hexa returns a 8 length char hexadecimal value of the color, starting with #
Example ¶
blue := MakeRGB(13, 110, 253)
transparentblue := blue.Opacify(0.8)
fmt.Printf("blue=%s, transparent blue=%s\n", blue.Hexa(), transparentblue.Hexa())
Output: blue=#0D6EFDFF, transparent blue=#0D6EFDCC
func (Color) Lighten ¶
Create a ligher color, a tint. The factor values is between 0 and 1. Alpha chanel stays unchanged.
A factor >= 1 returns WHITE A factor <= 0 returns an unchanged color
Example ¶
lightblue := MakeRGB(13, 110, 253).Lighten(0.5)
r, g, b := lightblue.RGB()
fmt.Printf("lightblue R=%d G=%d B=%d\n", r, g, b)
Output: lightblue R=134 G=182 B=254
func (Color) Opacify ¶
Clone the color setting the alpha chanel with an opacity factor.
opacityfactor >= 1 set the alpha chanel to 255, fully opaque opacityfactor <= 0 set the alpha chanel to 0, fully transparent
func (Color) RGB ¶
RGB returns the R, G, B components of the color
Example ¶
blue := Color(0x0d6efdff)
r, g, b := blue.RGB()
fmt.Printf("blue R=%d G=%d B=%d\n", r, g, b)
Output: blue R=13 G=110 B=253
Directories
¶
| Path | Synopsis |
|---|---|
|
Package bootstrapcolor provides a set of default rgb constant colors.
|
Package bootstrapcolor provides a set of default rgb constant colors. |