Programatic Palettes

It all started when I saw Running the Numbers. I really enjoyed the colors of the very last photo, Shipping Containers. I thought, “I wonder if that would make a good color palette?”

I fired up the Digital Color Meter, which ships in the Applications/Utilities directory of all Mac OS X systems, and set the aperture wide to average the color variations within each container color. For the first 30 container images (two rows), I manually copied the RGB color value and pasted it into a text file.

Then I wanted to sort the colors by color value, and make a montage. Four hours later, starting from scratch, I have wrestled my first Ruby/Rmagick/ImageMagick program to the mat. I haven’t been able to sort the colors just yet, and it’s far past bedtime, but here is a program that reads the text file of color values, makes a color square for each, and generates a montage of the squares.

require 'rubygems'
require 'RMagick'
include Magick
# Create an imagelist to hold the individual color blocks
colorSquare =
# Read the text file and get RGB hex color values into an array
colors = IO.readlines("colors.txt")
# Create scratch images, one per array value
colors.each { |c|
colorSquare.new_image(55, 55) { self.background_color = c }
# Simple sort does not group by colors. Maybe try getting the
# separate chromaticity or rgb values instead? Or changing the
# colorspace to HSL first?
# Positon scratch images on canvas
montage = colorSquare.montage {
self.geometry = "+2+2"
self.tile = "6x5"
self.background_color = "white"
# Write file to disk

Here’s what it makes:


Update: “colorSquare.sort!” does a sort, but I can’t seem to get the reds, greens, and blues, to group together. I think I’d have to separate out the RGB color values and sort by individual array elements.