Created
February 15, 2012 14:44
-
-
Save butcher/1836288 to your computer and use it in GitHub Desktop.
Simple color builder
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
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