Skip to content

Instantly share code, notes, and snippets.

@butcher
Created February 15, 2012 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save butcher/1836288 to your computer and use it in GitHub Desktop.
Save butcher/1836288 to your computer and use it in GitHub Desktop.
Simple color builder
count = ARGV[0].to_i
min = ARGV[1].to_i
def int_to_hex(r,g,b)
"#%02X%02X%02X" % [r, g, b]
end
arr = []
r = 255
g = min
b = min
g.upto(255){|green| arr << {:r => r, :g => green, :b => b}}
g = 255
r.downto(min){|red| arr << {:r => red, :g => g, :b => b}}
r = min
b.upto(255){|blue| arr << {:r => r, :g => g, :b => blue}}
b = 255
g.downto(min){|green| arr << {:r => r, :g => green, :b => b}}
g = min
r.upto(255){|red| arr << {:r => red, :g => g, :b => b}}
r = 255
b.downto(min){|blue| arr << {:r => r, :g => g, :b => blue}}
b = min
increaser = arr.size/count
result = []
count.times{|i| result << arr[i*increaser] }
puts result.map{|c| "<div style='background-color: #{int_to_hex(c[:r], c[:g], c[:b])}; width: 16px; height:16px; float:left;'></div>" }.join
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment