From d27fc0d2105976d4f9ae9b70d568dac1c204d3e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoffer=20M=C3=BCller=20Madsen?= Date: Thu, 11 May 2017 09:16:03 +0200 Subject: [PATCH] rudimentary solution for generating non-similar colors --- plot.rb | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/plot.rb b/plot.rb index 33221ea..768154a 100644 --- a/plot.rb +++ b/plot.rb @@ -6,8 +6,23 @@ log_dir = LOG_DIR 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| - 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 plotstring = %Q[set terminal 'svg' size 800,400 fname 'Verdana, Helvetica, Arial, sans-serif' \