rudimentary solution for generating non-similar colors

This commit is contained in:
Christoffer Müller Madsen 2017-05-11 09:16:03 +02:00
parent 60907f1076
commit d27fc0d210

17
plot.rb
View File

@ -6,8 +6,23 @@ log_dir = LOG_DIR
colors = {} colors = {}
def rand_color
"%06x" % (rand * 0xffffff)
end
def color_dist (c1, c2)
(c1[0..1].hex - c2[0..1].hex).abs +
(c1[2..3].hex - c2[2..3].hex).abs +
(c1[4..5].hex - c2[4..5].hex).abs
end
users.each do |user| users.each do |user|
colors[user] = "%06x" % (rand * 0xffffff) tentative_color = rand_color
while (colors.detect {|k,v| color_dist(v,tentative_color) < 200}) do
tentative_color = rand_color
end
colors[user] = tentative_color
end end
plotstring = %Q[set terminal 'svg' size 800,400 fname 'Verdana, Helvetica, Arial, sans-serif' \ plotstring = %Q[set terminal 'svg' size 800,400 fname 'Verdana, Helvetica, Arial, sans-serif' \