Merge pull request 'Assign similar colors to child groups' (#110) from chosen-colors into main
Some checks failed
Check usage of free licenses / build-static-assets (push) Successful in 57s
Build Nginx-based docker image / build-static-assets (push) Failing after 1m59s
Run unit tests / unit_tests (push) Successful in 2m18s

Reviewed-on: #110
This commit is contained in:
bustikiller 2024-11-10 11:26:54 +00:00
commit aef55abe54
3 changed files with 26 additions and 0 deletions

View File

@ -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

View 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

View File

@ -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)