From 052ec59d7e6ec9f1d09e3cc7dd0d9eab8b40dc18 Mon Sep 17 00:00:00 2001 From: Sami Samhuri Date: Mon, 14 Dec 2009 10:50:28 -0800 Subject: [PATCH] New tool to convert between integer RGB 0-255 and hex colours. --- colours.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 colours.rb diff --git a/colours.rb b/colours.rb new file mode 100755 index 0000000..c8bc951 --- /dev/null +++ b/colours.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env ruby + +hex = '' +rgb = [] +red = green = blue = 0 + +if ARGV.size == 1 + hex = ARGV.first[0,1] == '#' ? ARGV.first[1..-1] : ARGV.first + red = hex[0,2].to_i(16) + green = hex[2,2].to_i(16) + blue = hex[4,2].to_i(16) + rgb = [red, green, blue] +elsif ARGV.size == 3 + rgb = ARGV[0..2] + red,green,blue = *rgb + hex = rgb.map {|n| n.to_i.to_s(16)}.join +end + +puts '#' + hex +puts "RGB (#{red}, #{green}, #{blue})" +puts "Red:#{red.to_f/255} green:#{green.to_f/255} blue:#{blue.to_f/255}"