diff --git a/app/models/group.rb b/app/models/group.rb index cf7cba0..105d08c 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -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 diff --git a/config/initializers/colors.rb b/config/initializers/colors.rb new file mode 100644 index 0000000..b435084 --- /dev/null +++ b/config/initializers/colors.rb @@ -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 diff --git a/db/seeds.rb b/db/seeds.rb index e77df63..bd9417a 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -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) \ No newline at end of file