// Initialize with byte value via .byte(_) method
let color1 = Color<RGB>(
red: .byte(221),
green: .byte(51),
blue: .byte(12),
alpha: .byte(255)
)
// or directly via numeric literals and .raw(_) method for numerics
let alpha = 1
let color2 = Color<RGB>(
red: .max,
green: 0.2,
blue: .byte(12),
alpha: .raw(alpha)
)
print(color1 == color2) // true
// hex initialization is supported for RGB color space
// - works with "#" prefix and without, case-insensitive
// - works with rgb, rgba, rrggbb, rrggbbaa representations
// - avalible trough .hex and .init(hex:)
Color.hex("FA6878") // Type == Color<RGB>?
Color(hex: "#aaaf") // rgba, the same as #AAAAAAFF
// or use hex literals
Color(rgb: 0xfa6878)
Color(rgba: 0xfa6878ff)
Color.rgb(0xAAAAAA)
// you can also get an rgb hex value of any color
color1.hex()
color2.hex(uppercased: true)
color3.hex(hashTagPrefix: true)
// color literals will work too, but accuracy is not guarantied
let literal: Color<RGB> = #colorLiteral(red: 0.9803921568627451, green: 0.40784313725490196, blue: 0.47058823529411764, alpha: 1)
Platform agnostic color Library.
Usage
Initialization
ColorSpaces
Installation
Add the package to Your SwiftPM package dependencies:
then add
GenericColor
dependency to your targetMore
See tests for more usage examples.
Check out higher-level framework Palette for more.