Created
December 10, 2017 01:11
-
-
Save JoshCheek/d4f0a39fed9e739f491590507b0a8ea5 to your computer and use it in GitHub Desktop.
Sorted colours
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ruby -r chunky_png -r base64 -e ' | |
side = 20 | |
colors = {# RR GG BB AA | |
red: [0xFF, 0x00, 0x00, 0xFF], | |
orange: [0xFF, 0x7F, 0x00, 0xFF], | |
yellow: [0xFF, 0xFF, 0x00, 0xFF], | |
green: [0x00, 0xFF, 0x00, 0xFF], | |
blue: [0x00, 0x00, 0xFF, 0xFF], | |
indigo: [0x4B, 0x00, 0x82, 0xFF], | |
violet: [0x94, 0x00, 0xD3, 0xFF], | |
} | |
sorts = { | |
hex: proc do |name, rgba| | |
rgba | |
end, | |
roygbiv: proc do |name, (r, g, b, a)| | |
min, _, max = [r,g,b].sort | |
case ∆ = (max - min).to_f | |
when 0 then 0 | |
when r then (g-b)/∆%6 | |
when g then (b-r)/∆+2 | |
else (r-g)/∆+4 | |
end | |
end, | |
} | |
sorts.each do |name, sorter| | |
canvas = ChunkyPNG::Canvas.new side*colors.size, side | |
colors.sort_by(&sorter).each.with_index do |(name, rgba), i| | |
canvas.rect i*side, 0, i*side+side-1, side-1, ChunkyPNG::Color::WHITE, ChunkyPNG::Color.rgba(*rgba) | |
end | |
b64img = Base64.encode64 canvas.to_blob(fast_rgba: true) | |
printf "%10s \e]1337;File=preserveAspectRatio=1;inline=1:%s\a\n", name, b64img | |
end | |
' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment