Skip to content

Instantly share code, notes, and snippets.

@tpoisot
Created February 29, 2020 17:51
Show Gist options
  • Save tpoisot/a57e88957e5639d4a0590a27993cb5ae to your computer and use it in GitHub Desktop.
Save tpoisot/a57e88957e5639d4a0590a27993cb5ae to your computer and use it in GitHub Desktop.
colormaps with equal luminance
using Pkg
Pkg.activate(".")
using Colors
using Mustache
using Plots
using Clustering
luma(color) = luma(convert(RGB, color))
luma(color::T) where {T <: RGB} = 0.299color.r + 0.587color.g + 0.114color.b
function generate_color(H=30, Y=0.3, S=0.5)
L = collect(0.0:0.001:1.0)
colors = map(l -> HSL(H, S, l), L)
best_match = findmin(abs.(luma.(colors).-Y))
return colors[last(best_match)]
end
colors = generate_color.(1:360, 0.6, 0.2)
reshape(colors, (20, 18))
D = zeros(Float64, (length(colors),length(colors)))
for (i,c1) in enumerate(colors)
for (j,c2) in enumerate(colors)
D[i,j] = colordiff(c1,c2)
end
end
heatmap(D)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment