# Assigning color to variable and using with colorant

**URL:** <https://discourse.julialang.org/t/assigning-color-to-variable-and-using-with-colorant/80753>\
**Category:** New to Julia\
**Tags:** colors\
**Created:** [May 9, 2022, 12:20pm UTC](https://discourse.julialang.org/t/assigning-color-to-variable-and-using-with-colorant/80753 "2022-05-09T12:20:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nash](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nash/32/14482_2.png) [@Nash](https://discourse.julialang.org/u/Nash)\
**Post date:** [May 9, 2022, 12:20pm UTC](https://discourse.julialang.org/t/assigning-color-to-variable-and-using-with-colorant/80753/1 "2022-05-09T12:20:12Z")

</div>

The following works:

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

```

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

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [May 9, 2022, 12:25pm UTC](https://discourse.julialang.org/t/assigning-color-to-variable-and-using-with-colorant/80753/2 "2022-05-09T12:25:20Z")

</div>

> [@Nash](#):
>
> But how do I assign #5AC3E3 to a variable and re-write the code?

Here are a few options:

```julia
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)

```

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [May 9, 2022, 12:55pm UTC](https://discourse.julialang.org/t/assigning-color-to-variable-and-using-with-colorant/80753/3 "2022-05-09T12:55:06Z")

</div>

> [@stevengj](#):
>
> `using Colors, FixedPointNumbers`

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.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [May 9, 2022, 12:58pm UTC](https://discourse.julialang.org/t/assigning-color-to-variable-and-using-with-colorant/80753/4 "2022-05-09T12:58:57Z")

</div>

> [@rafael.guerra](#):
>
> 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
julia> using Colors

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

```

or simply

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

```

or even

```julia
julia> using Colors: N0f8

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

```

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

```julia
using Colors.FixedPointNumbers

```
