Skip to content

Instantly share code, notes, and snippets.

@dahu
Created August 27, 2012 14:19
Show Gist options
  • Select an option

  • Save dahu/3488848 to your computer and use it in GitHub Desktop.

Select an option

Save dahu/3488848 to your computer and use it in GitHub Desktop.
color_plane - hsl(ish) map of Xresources colours
#!/usr/bin/env ruby
# color_plane - hsl(ish) map of Xresources colours
# Barry Arthur
require 'color'
@opt_print_values = nil
def swatch(color)
print "\x1b[48;5;#{color}m "
print @opt_print_values ? sprintf("%3s", color) : " "
end
x1 = `xrdb -query`.split(/\n/).grep(/color\d+:/).map {|x| x.sub(/.*color(\d+):\s*#(.*)/, '\1:\2').split(/:/)}
x1.map! {|x| [x[0], Color::RGB.new(*(x[1].scan(/../).map {|h| h.to_i(16)})).to_hsl]}
x2 = x1.sort_by {|color| c = color[1]; 0 * c.h + 0 * c.s + 20 * c.l}
x3 = x2.each_slice(20).map{|a| a.sort_by {|color| c = color[1]; 20 * c.h + 0 * c.s + 20 * c.l }}
x4 = x3.each_slice(12).map{|a| a.sort_by{|color| c = color[0][1]; 0 * c.h + 20 * c.s + 20 * c.l}}
puts "\x1b[1m\n"
x4.each do |c2|
c2.each do |c1|
c1.each do |c|
swatch(c[0])
end
puts "\x1b[0m\n"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment