[ANN] Colorfy.jl

Colorfy.jl is a tiny utility to convert any vector of Julia objects into Colors.jl colors:

julia> using Colorfy

julia> values = [:red, :green, :blue];

julia> colorfy(values, alpha=[0.5, 0.6, 0.7])
3-element Vector{RGBA{FixedPointNumbers.N0f8}}:
 RGBA(1.0, 0.0, 0.0, 0.502)
 RGBA(0.0, 0.502, 0.0, 0.6)
 RGBA(0.0, 0.0, 1.0, 0.698)

New types can be registered by adding methods to Colorfy.repr, i.e., by implementing a reasonable colorful representation. For instance, we can convert Distributions.jl via a package extension. The colors have different transparency depending on the entropy:

julia> values = [Bernoulli(1.0), Bernoulli(0.8), Bernoulli(0.5)]
3-element Vector{Bernoulli{Float64}}:
 Bernoulli{Float64}(p=1.0)
 Bernoulli{Float64}(p=0.8)
 Bernoulli{Float64}(p=0.5)

julia> colorfy(values)
3-element Vector{ColorTypes.RGBA{Float64}}:
 RGBA(0.993248, 0.906157, 0.143936, 1.0)
 RGBA(0.993248, 0.906157, 0.143936, 0.2780719051126377)
 RGBA(0.267004, 0.004874, 0.329415, 0.0)

We use this utility package to visualize objects over Meshes.jl as colors. These objects are stored in vectors that are columns of GeoTables.jl.

The package was registered years ago, but I updated it recently to simplify the code and to make it more extendable. If you have a type with a colorful representation, please feel free to contribute a package extension. That way it can be automatically visualized with Makie.jl.

4 Likes