Assign similar colors to child groups #110
@ -13,6 +13,20 @@ class Group < ApplicationRecord
|
||||
|
||||
has_many :guests
|
||||
|
||||
def colorize_children(generation = 1)
|
||||
derived_colors = generation == 1 ? color.paint.palette.analogous(size: children.count) : color.paint.palette.decreasing_saturation
|
||||
|
||||
children.zip(derived_colors) do |child, raw_color|
|
||||
|
||||
final_color = raw_color.paint
|
||||
final_color.brighten(60) if final_color.dark?
|
||||
|
||||
child.update!(color: final_color)
|
||||
|
||||
child.colorize_children(generation + 1)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_color
|
||||
|
8
config/initializers/colors.rb
Normal file
8
config/initializers/colors.rb
Normal file
@ -0,0 +1,8 @@
|
||||
# Copyright (C) 2024 Manuel Bustillo
|
||||
|
||||
Chroma.define_palette :decreasing_saturation do
|
||||
spin(20).desaturate(40)
|
||||
spin(-20).desaturate(40)
|
||||
spin(40).desaturate(40)
|
||||
spin(-40).desaturate(40)
|
||||
end
|
@ -65,3 +65,7 @@ NUMBER_OF_GUESTS.times do
|
||||
end
|
||||
|
||||
ActiveJob.perform_all_later(3.times.map { TableSimulatorJob.new })
|
||||
|
||||
'red'.paint.palette.triad(as: :hex).zip(Group.roots).each { |(color, group)| group.update!(color: color.paint.desaturate(40)) }
|
||||
|
||||
Group.roots.each(&:colorize_children)
|
Loading…
x
Reference in New Issue
Block a user