| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- package ultraviolet
- import (
- "strconv"
- "strings"
- )
- type Color struct {
- Red int
- Green int
- Blue int
- Alpha int
- }
- func ColorFromHex(value string) Color {
- if len(value) != 8 {
- return Color{}
- }
- if !strings.HasPrefix(value, "0x") {
- return Color{}
- }
- red, err := strconv.ParseInt(value[2:4], 16, 16)
- if err != nil {
- return Color{}
- }
- green, err := strconv.ParseInt(value[4:6], 16, 16)
- if err != nil {
- return Color{}
- }
- blue, err := strconv.ParseInt(value[6:8], 16, 16)
- if err != nil {
- return Color{}
- }
- return Color{
- Red: int(red),
- Green: int(green),
- Blue: int(blue),
- Alpha: 255,
- }
- }
|