Last active
December 16, 2015 21:48
-
-
Save hachy/5501937 to your computer and use it in GitHub Desktop.
256 terminal colors and hex colors in Ruby
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
class Array | |
def generate_color(num, reg) | |
each.with_index(num) do |hexcolor, termcolor| | |
number = "#{termcolor}".ljust(3) | |
bg = "\e[48;5;#{termcolor}m \e[0m" | |
fg = "\e[38;5;#{termcolor}m #{number} ##{hexcolor} \e[0m" | |
print bg + fg | |
print "\n" if reg =~ hexcolor | |
end | |
end | |
end | |
def system_color | |
hex = %w(000000 800000 008000 808000 000080 800080 008080 c0c0c0 808080 ff0000 00ff00 ffff00 0000ff ff00ff 00ffff ffffff) | |
hex.generate_color(0, /(c0|ffffff)$/) | |
end | |
def color_cube | |
hex = [] | |
el = %w(00 5f 87 af d7 ff) | |
el.each do |r| | |
el.each do |g| | |
el.each do |b| | |
hex << r + g + b | |
end | |
end | |
end | |
hex.generate_color(16, /f{2}$/) | |
end | |
def gray_scale | |
el = %w(08 12 1c 26 30 3a 44 4e 58 60 66 76 80 8a 94 9e a8 b2 bc c6 d0 da e4 ee) | |
hex = el.map { |i| i * 3 } | |
hex.generate_color(232, /(4e|9e|ee)$/) | |
end | |
system_color | |
color_cube | |
gray_scale |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment