# Make a LCHab{Float32} color darker

**URL:** <https://discourse.julialang.org/t/make-a-lchab-float32-color-darker/52432>\
**Category:** New to Julia\
**Tags:** question, package, colors\
**Created:** [December 27, 2020, 12:13am UTC](https://discourse.julialang.org/t/make-a-lchab-float32-color-darker/52432 "2020-12-27T00:13:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![BeyondMagic](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/beyondmagic/32/20674_2.png) [@BeyondMagic](https://discourse.julialang.org/u/BeyondMagic)\
**Post date:** [December 27, 2020, 12:13am UTC](https://discourse.julialang.org/t/make-a-lchab-float32-color-darker/52432/1 "2020-12-27T00:13:34Z")

</div>

I’ll be direct! I’m trying to make a **LCHab{Float32}** color made with **Colors.jl** darker; at first glance, I thought in iterating and giving it a smaller value, however perhaps I’m very dumb for not knowing that I cannot _probably_ iterate it, **Julia 1.5.3** gave the following error trying with **foreach** and **println** :

```julia
julia> w = LCHab{Float32}(70.0f0,70.0f0,0.0f0)
LCHab{Float32}(70.0f0,70.0f0,0.0f0)

julia> foreach(println, w)
ERROR: MethodError: no method matching iterate(::LCHab{Float32})
Closest candidates are:
  iterate(::Base.MethodList, ::Any...) at reflection.jl:874
  iterate(::LibGit2.GitBranchIter) at /build/julia/src/julia-1.5.3/usr/share/julia/stdlib/v1.5/LibGit2/src/reference.jl:343
  iterate(::LibGit2.GitBranchIter, ::Any) at /build/julia/src/julia-1.5.3/usr/share/julia/stdlib/v1.5/LibGit2/src/reference.jl:343
  ...
Stacktrace:
 [1] foreach(::typeof(println), ::LCHab{Float32}) at ./abstractarray.jl:2009
 [2] top-level scope at REPL[13]:1
 [3] run_repl(::REPL.AbstractREPL, ::Any) at /build/julia/src/julia-1.5.3/usr/share/julia/stdlib/v1.5/REPL/src/REPL.jl:288

julia> w[1]
ERROR: MethodError: no method matching getindex(::LCHab{Float32}, ::Int64)
Stacktrace:
 [1] top-level scope at REPL[14]:1
 [2] run_repl(::REPL.AbstractREPL, ::Any) at /build/julia/src/julia-1.5.3/usr/share/julia/stdlib/v1.5/REPL/src/REPL.jl:288

```

Or perhaps it is iterable and I just can’t figure it out, anyway, I’d be glad if someone can show me how to make this type of color darker.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [December 27, 2020, 12:40am UTC](https://discourse.julialang.org/t/make-a-lchab-float32-color-darker/52432/2 "2020-12-27T00:40:47Z")

</div>

It’s a struct so you need to access each of the fields:

```julia
julia> w = LCHab{Float32}(70.0f0,70.0f0,0.0f0)
LCHab{Float32}(70.0f0,70.0f0,0.0f0)

julia> dump(w)
LCHab{Float32}
  l: Float32 70.0f0
  c: Float32 70.0f0
  h: Float32 0.0f0

julia> foreach(x->println(getfield(w,x)), fieldnames(typeof(w)))
70.0
70.0
0.0

```

it’s not mutable, so you need to make a new `LCHab` that only has difference in the field `l`? (which controls Luminance?)

```julia
julia> b = LCHab(w.l * 0.8f0, w.c, w.h)
LCHab{Float32}(56.0f0,70.0f0,0.0f0)

```

---

<div class="post-metadata">

**Author:** ![BeyondMagic](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/beyondmagic/32/20674_2.png) [@BeyondMagic](https://discourse.julialang.org/u/BeyondMagic)\
**Post date:** [December 27, 2020, 1:06am UTC](https://discourse.julialang.org/t/make-a-lchab-float32-color-darker/52432/3 "2020-12-27T01:06:54Z")

</div>

Thank you, it worked as expected!
