making next_color function more readable
This commit is contained in:
parent
1d7f3207a6
commit
460d117d7a
1 changed files with 11 additions and 7 deletions
|
|
@ -597,14 +597,18 @@ class Conference < ActiveRecord::Base
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# Returns a different html colour for every i. We make use of big prime numbers
|
# Returns a different html colour for every i and consecutive colors are
|
||||||
# to avoid repetition and to make consecutive colors clearly different.
|
# clearly different.
|
||||||
def next_color(i)
|
def next_color(i)
|
||||||
color = '#000000'
|
'#' + next_color_component(:r, i) + next_color_component(:g, i) + next_color_component(:b, i)
|
||||||
color[1..2] = ((i*113)%239 + 16).to_s(16)
|
end
|
||||||
color[3..4] = ((i*67)%239 + 16).to_s(16)
|
|
||||||
color[5..6] = ((i*151)%239 + 16).to_s(16)
|
# Auxiliar function which is used in next_color and returns each component of
|
||||||
color
|
# the color. We make use of big prime numbers to avoid repetition and to make
|
||||||
|
# consecutive colors clearly different.
|
||||||
|
def next_color_component(component, i)
|
||||||
|
big_prime_numbers = {r: 113, g: 67, b: 151}
|
||||||
|
((i*big_prime_numbers[component])%239 + 16).to_s(16)
|
||||||
end
|
end
|
||||||
|
|
||||||
after_create do
|
after_create do
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue