From 921efbabe92585f3bc7d4f46b41a5816df65d9c2 Mon Sep 17 00:00:00 2001 From: Carl Chenet Date: Tue, 16 May 2017 19:35:07 +0200 Subject: [PATCH] Tiny refactor for blue lobsters (#333) --- app/controllers/application_controller.rb | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 26a18ea..77ee039 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -50,13 +50,9 @@ class ApplicationController < ActionController::Base Rails.logger.info " Traffic level: #{@traffic.to_i}" end - if rand(2000000) == 1 - @traffic_color = sprintf("%02x%02x%02x", - 0, 0, [ 255, (@traffic * 7).floor + 50.0 ].min) - else - @traffic_color = sprintf("%02x%02x%02x", - [ 255, (@traffic * 7).floor + 50.0 ].min, 0, 0) - end + intensity = (@traffic * 7).floor + 50.0 + color = rand(2000000) == 1 ? "0000%02x" : "%02x0000" + @traffic_color = sprintf(color, intensity > 255 ? 255 : intensity) true end