Today I want to talk about a new algorithm I implemented this month in Dehoarder 2.
One of the big features in Dehoarder 2 is the ability to re-arrange and re-decorate Harry’s home. One of the ways that feature ties to the gameplay is that the in-game home decor magazine, “Nicer Homes”, periodically runs a contest where homes are judged on how well they are decorated. That means that the game needs to be able to take a look at the home and determine things like how well the colors go together.
Luckily there has been a lot of study devoted to that particular question. What it boils down to is that there are a couple of tried and true ways to pick colors that go together.
- Complementary Colors – The hues of these colors lie opposite each other on the color wheel.
- Triadic Colors – The hues of these colors form an equilateral triangle on the color wheel.
- Split Complementary Colors – The hues of these colors form an isosceles triangle on the color wheel.
- Analogous Colors – The hues of these colors are close to each other on the color wheel, but not too close.
There are a couple of other ways colors can be paired, but for the purposes of the game, this list can likely be considered sufficient.
It is pretty trivial to take a color and determine a digital hue value from it, which is the main input for determining whether colors go together. What is a bit more complicated is the part where you make a computer take a list of arbitrary colors, and determine how well that list of colors fits any of the above “shapes” on the color wheel.
I found a good resource on how to do that from the Interactive Geometry Lab, a department of ETH Zurich. For their paper on color harmonization, they created some pretty nifty software that can take an arbitrary image, and adjust the colors within the image to fit a given profile of complementary colors. What I’m trying to do is slightly different since I’m only asking how well the existing colors fit a profile and stopping short of actually adjusting colors, but a lot of the principles still applied.
I won’t get into a bunch of really technical detail involving mathematical symbols most people do not comprehend. However, at a high level, what my implementation does is take a list of colors and corresponding weights (the weights determine what percentage of the whole room is that color), and then looks at that list of colors through a series of templates that describe the above list of how colors should go together. When it evaluates a particular template, it evaluates it at many different “angles” on the color wheel. Each evaluation ends up with a score, and the highest score for each template is chosen. Once that is done, the highest scoring template “wins” and the score of that template is the result of how well the colors go together. If the resulting score is high, the colors go together well, but if the resulting score is low, the colors go together poorly.
Since it involves hundreds of evaluations, it’s not a fast algorithm, but it doesn’t need to be, since it will only need to be run when the magazine contest event is evaluating a room. The game even goes ones step further, taking the template and score and converting it into a human-readable evaluation, like, “The use of red and green together is a good start, but it really needs more blue to balance it out.” This result would come when the best template match was “partially triadic” with red and green as the main colors.
All in all, the hardest part of implementing this feature was developing the actual determination of whether a list of colors go together. With that that piece in place, the rest of the feature was fairly straightforward.
It’s hard to believe that GDEX 2018 is only two months away. Of course, I will be there with Dehoarder 2, showing off all of the new changes that have been made to the game since GDEX 2017. Each time I show the game, the reaction to it keeps getting better and better, so I’m really looking forward to seeing what people have to say about the game this time around. Over the next two months, I hope to devote a little more time than usual to the game, to get as many features as possible done for the expo. Hope to see you there!