Last active
August 29, 2015 14:19
-
-
Save studio3104/524030aeb510b24addda to your computer and use it in GitHub Desktop.
n種類のカラーコードのちょうど平均のカラーコードを出す
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
#!/usr/bin/env ruby | |
def colorcodeaverage(*codes) | |
sum = [ 0, 0, 0 ] | |
codes.each do |code| | |
c = code.scan(/.{1,2}/) | |
sum = sum.map.with_index { |s,i| s + c[i].to_i(16) } | |
end | |
sum.map { |s| ( s / codes.size ).to_s(16).rjust(2,'0') }.join.upcase | |
end | |
p colorcodeaverage('cc11cc', '221111', '000000') | |
#=> "4F0B49" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment