Assigning color to variable and using with colorant

The following works:

`cs = ColorScheme([colorant"white", colorant"#5AC3E3"]`

But how do I assign #5AC3E3 to a variable and re-write the code?

Here are a few options:

julia> using Colors, FixedPointNumbers

julia> c = colorant"#5AC3E3"
RGB{N0f8}(0.353,0.765,0.89)

julia> c = RGB{N0f8}(0.353,0.765,0.89)
RGB{N0f8}(0.353,0.765,0.89)

julia> c = RGB(0.353,0.765,0.89)
RGB{Float64}(0.353,0.765,0.89)

julia> c = RGB(reinterpret.(N0f8, (0x5a, 0xc3, 0xe3))...)
RGB{N0f8}(0.353,0.765,0.89)
2 Likes

Hi Steve, sorry for the newbie question. Since the Colors package already uses FixedPointNumbers, could we access the functionality of the latter by just using the former? Thanks.

Yes. You can do

julia> using Colors

julia> Colors.FixedPointNumbers.N0f8
N0f8 (alias for FixedPointNumbers.Normed{UInt8, 8})

or simply

julia> Colors.N0f8
N0f8 (alias for FixedPointNumbers.Normed{UInt8, 8})

or even

julia> using Colors: N0f8

julia> N0f8
N0f8 (alias for FixedPointNumbers.Normed{UInt8, 8})

Or, if you want to import the whole FixedPointNumbers namespace:

using Colors.FixedPointNumbers
2 Likes