Generating N colors (Ruby)

Kevin messaged me a few days ago to give me a problem his boss had given him. Generate a list of colors that can be used when drawing n lines on a graph.  My first solution was to just pick 20 or 30 colors, put them an in a list and pick one of them for each graph, but I had a few other ideas.  One of them seemed stupidly-simple, so I threw it together in ruby and had it generate an html page to display the results.

maxColors = 250
File.open('colors.html', 'w') do |myfile|  #create file
    myfile.print "nnn"
    1.upto(maxColors) { |tblcnt|
        myfile.print "n"
        1.upto(tblcnt) { |rowcnt|
            newColor = (rowcnt * (0xFFFFFF/tblcnt)).to_s(16)
            myfile.print "n"
        }
        myfile.print "
.
n" } myfile.print " nn" end

Here are the results from my code:

Click for html (warning 1MB file)

Click for html (warning >1MB file)

The code basically takes 0xFFFFFF, divides it by n and displays each color.  It’s a simple hack, but the patterns it generated were just incredible.  Most of the color lines aren’t distinct enough to use in graphing, so it doesn’t really match what Kevin asked me to do.  Oh well, it was a fun little script to write.