From fa3d3cf13bbe8ecb9be8e23bd790d32ffa273849 Mon Sep 17 00:00:00 2001 From: Manuel Bustillo Date: Sun, 10 Nov 2024 09:49:08 +0100 Subject: [PATCH 1/2] Assign similar colors to child groups --- app/models/group.rb | 14 ++++++++++++++ config/initializers/colors.rb | 6 ++++++ db/seeds.rb | 4 ++++ 3 files changed, 24 insertions(+) create mode 100644 config/initializers/colors.rb 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..042a749 --- /dev/null +++ b/config/initializers/colors.rb @@ -0,0 +1,6 @@ +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 From 4089ff63baf538a870bc50bf4d44be495a440aab Mon Sep 17 00:00:00 2001 From: Manuel Bustillo Date: Sun, 10 Nov 2024 11:24:07 +0000 Subject: [PATCH 2/2] Add copyright notice --- config/initializers/colors.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config/initializers/colors.rb b/config/initializers/colors.rb index 042a749..b435084 100644 --- a/config/initializers/colors.rb +++ b/config/initializers/colors.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2024 Manuel Bustillo + Chroma.define_palette :decreasing_saturation do spin(20).desaturate(40) spin(-20).desaturate(40)