In julia gamezero i want to programatically change the tint of a draw object. However, colorant doesnt allow variables to be substituted into strings

38 views Asked by At

Draw(somethin,colorant'blue'). I want to change colour programmatically and do Draw(somethin, colorant'rgb($(val),$(val),$(val))'). This doesnt work. Nor does concatenation with *. Any ideas

Draw method doesnt interpret colorant properly

1

There are 1 answers

0
Przemyslaw Szufel On

The colorant string macro comes from the package Colors. If you do not know how to do something in Julia try first dump:

julia> dump(colorant"blue")
RGB{FixedPointNumbers.N0f8}
  r: FixedPointNumbers.N0f8
    i: UInt8 0x00
  g: FixedPointNumbers.N0f8
    i: UInt8 0x00
  b: FixedPointNumbers.N0f8
    i: UInt8 0xff

You can see that colorant"blue" just created an RGB object. Let's see how one can be constructed:

julia> methods(RGB)
# 6 methods for type constructor:
 [1] RGB(r::T, g::T, b::T) where T<:Integer
     @ c:\JuliaPkg\Julia-1.10.1\packages\ColorTypes\1dGw6\src\types.jl:460
 [2] RGB(r::T, g::T, b::T) where T<:Union{AbstractFloat, FixedPointNumbers.FixedPoint}
     @ c:\JuliaPkg\Julia-1.10.1\packages\ColorTypes\1dGw6\src\types.jl:108
...

So let's see if we learnt how to construct colors:

julia> RGB(0.0, 0.0, 1.0) == colorant"blue"
true

julia> RGB(1.0, 1.0, 0.0) == colorant"yellow"
true