Skip to content

Instantly share code, notes, and snippets.

@glucero
Last active December 18, 2015 22:29
Show Gist options
  • Save glucero/5855300 to your computer and use it in GitHub Desktop.
Save glucero/5855300 to your computer and use it in GitHub Desktop.
terminal colormap
#!/usr/bin/env ruby
def color_map
yield ->(offset) { ->(color) { print "\x1b[48;5;#{color + offset}m " } }
print "\x1b[0m", ?\n
end
puts 'System colors:'
color_map { |color| 8.times &color[0] }
color_map { |color| 8.times &color[8] }
puts ?\n, 'Color map:'
6.times do |green|
color_map do |color|
6.times do |red|
6.times &color[16 + (red * 36) + (green * 6)] # blue
end
end
end
puts ?\n, 'Grayscale map:'
color_map { |color| 24.times &color[232] }
@glucero
Copy link
Author

glucero commented Jun 25, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment