Colormoo_ An Algorithmic Approach to Generating Color Palettes
Colormoo_ An Algorithmic Approach to Generating Color Palettes
Scholarship @ Claremont
CMC Senior Theses CMC Student Scholarship
2014
Recommended Citation
Rael, Joshua, "Colormoo: An Algorithmic Approach to Generating Color Palettes" (2014). CMC Senior Theses. Paper 975.
http://scholarship.claremont.edu/cmc_theses/975
This Open Access Senior Thesis is brought to you by Scholarship@Claremont. It has been accepted for inclusion in this collection by an authorized
administrator. For more information, please contact [email protected].
Pomona College
Department of Computer Science
Joshua Rael
Selecting one color can be done with relative ease, but this
task becomes more difficult with each subsequent color. Col-
ormoo is an online tool aimed at solving this problem. We im-
plement three algorithms for generating color palettes based
off of a starting color. Data is collected for each palette that
is generated. Our analysis reveals two of the algorithms are
preferred, but under different circumstances. Furthermore,
we find that users prefer palettes containing colors that are
compatible, but not too similar. With refined heuristics, we
believe these techniques can be extended and applied beyond
the field of graphic design alone.
i
ii
Acknowledgments
iii
iv
Contents
Abstract . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . i
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . iii
List of Figures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vii
1 Introduction 1
2 Background 3
2.1 Color Representation . . . . . . . . . . . . . . . . . . . . . . . 3
2.2 Color Compatibility Algorithms . . . . . . . . . . . . . . . . . 5
2.3 Application of Color Compatibility Algorithms . . . . . . . . 7
3 Colormoo 11
3.1 The User Flow . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.2 Three Color Palettes . . . . . . . . . . . . . . . . . . . . . . . 11
4 Methodology 17
4.1 Technology . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4.2 Data Collection . . . . . . . . . . . . . . . . . . . . . . . . . . 18
5 Results 21
5.1 Results by Component . . . . . . . . . . . . . . . . . . . . . . 21
5.2 Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
6 Future Work 25
6.1 Refinement . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
6.2 Industry Application . . . . . . . . . . . . . . . . . . . . . . . 26
7 Conclusion 27
v
Bibliography 35
vi
List of Figures
vii
viii
Chapter 1
Introduction
While the way that designers have interacted with color has evolved through-
out the history of graphic design, the problem of choosing colors continues
to be a difficult task. Fortunately there are many resources available to
aid in the process, though their number alone is enough to suggest there is
no perfect solution. Color choice sits at a peculiar point between intuition
and experience. A color may be chosen because it conforms to established
set of rules or simply because the absence of it would leave more to be
desired. One approach to finding compatible colors is by consensus. As
such, modern tools have positioned themselves on the internet where they
can be part of a much larger feedback loop. Two popular websites, Adobe
Kuler and COLOURLovers, have developed forums through which users can
create color palettes and submit them for public appraisal. On these two
sites alone, more than two million palettes have been generated by tens of
thousands of users [OAH11].
A designer may select a color for any number of reasons, but the value
of that color often cannot be established until it sits alongside other colors.
Herein lies the essence of this problem: picking one color can be done with
relative ease, but the task becomes more difficult with each subsequent color.
Despite all the excitement around seeking compatible colors, little has been
done in exploration of this subproblem.
The goal of this research is to evaluate three different algorithms that
produce color themes, i.e., a set of six compatible colors. We built an appli-
cation that measures which algorithms are preferred and under what condi-
tions. On Colormoo, designers can input a color of their choice, generate a
series of themes, and select their favorite. We collect data for each palette
that users select. Ultimately, we observe that two algorithms come out on
1
top and the properties of the user’s starting color will make one approach
more favorable than the other. These results, along with general observa-
tions of color preference, can provide helpful insight into future explorations
of this problem, especially as it becomes relevant beyond the field of graphic
design alone.
2
Chapter 2
Background
2.1.1 RGB
The red-green-blue (RGB) color model defines how screens emit colored
light. This is the model computer monitors use to determine the color of
each individual pixel. A color is represented by the amount of red, green, and
blue required to produce it, each within the range of 0 to 255. These colors
are typically represented by a three-tuple or by their hexadecimal (HEX)
variant in base 16. For example, white light is represented as (255,255,255)
where black is (0,0,0). Although, RGB is not the most intuitive way for
humans to think about color, this is a popular format for referencing a
particular color. HEX colors, for example, are used in stylesheets to display
colors online.
3
Figure 2.1: The three different components of the HSL color space [Vir14].
2.1.2 HSL
The hue-saturation-lightness (HSL) model more closely represents the way
we think about color (Figure 2.1). Hue is typically what people think when
they hear the word color [Jac13]. It represents the rainbowed spectrum of
light from red to violet. Hue is measured in degrees because it is commonly
displayed as a color wheel. For example, red colors sit around 0 and 360
degrees, while blues are more in the 175-220 range. Saturation is the per-
centage of color intensity. Really vibrant colors will be highly saturated.
Dull colors will have closer to 0% saturation. Finally, lightness is used to
define a color on the darker or lighter end of the spectrum. Lightness is also
measured on a percentage scale.
4
2.2 Color Compatibility Algorithms
Finding compatible colors is not a problem unique to one audience. Ar-
chitects, engineers, publishers, artists, and designers all use color every day.
Each has their own toolset for color use in their respective fields. We explore
a few of these techniques and observe how they are implemented in different
consumer facing applications.
5
in statistics. Our implementation will keep lightness constant to give the
user more control over the hue component. An example of this technique
can be seen in our implementation in Figure 3.3. Regardless, this technique
is a relatively simple way to produce a variety of different palettes and
previous studies confirm that colors along a line drawn this kind of space
are harmonious [OAH11].
6
Color quantization produces reliable results [OAH11]. It has the addi-
tional freedom of allowing users to sample colors from any image they find
aesthetically pleasing. Tools that utilize this method are great for deriving
new and fresh palettes. However, the palette will always be constrained to
the colors present in that image. If the user already has a color that they
would like to use in their design this may not be the best way to derive a
color theme.
7
ors present in the palette (between 3-12, though not all schemes can be
expanded to 12 colors). Ultimately this means sacrificing a little artistic
freedom when it comes to creating a color palette.
Jacomy’s I Want Hue is a little more elegant in this regard. The same
kind of palettes for data visualization can be created by restricting the color
space using the input sliders on the site. These schemes are successful with-
out relying on hard coded color values.
8
data from the two sites. An important difference between the two services
is that the Kuler interface encourages the use of hue templates while the
COLOURLovers interface does not. In comparing the two services, they
found that users would not typically create themes based on hue templates
unless encouraged to by the interface [OAH11]. Furthermore, they did not
find a correlation between a high rating and a theme whose colors closely
matched a hue template. However, when users did utilize hue templates,
they found themes with complementary and analogous colors to be the most
highly rated.
9
10
Chapter 3
Colormoo
11
Figure 3.1: Colormoo enables users to input a color with a color specification
or with the color sliders to generate three color palettes.
12
Figure 3.2: These three color wheels demonstrate the hue templates used in
the theory palette. From left: complementary colors, analogous colors, and
triadic colors. [Col12]
13
of the color’s associated RGB components. However, even to the untrained
eye, it is unlikely that five random colors are going to look good together.
Furthermore, there is no correlation between the derived colors and the
starting color. Not only would the resulting palette be an unsatisfactory
solution to the problem, but it would also appear too random. Users might
be able to recognize it as random and, as such, be biased against it.
To account for this we first played with the idea of “mixing” the start-
ing color with each random color. After creating a random color’s RGB
components, we add the corresponding component from the starting color
and divide the sum by two. The result is a color whose RGB components
are an average of the two colors. This is a better algorithm than purely
random colors because it allows the user’s choice to impact the resulting
theme. However, while averaging proved to work well for some colors, if the
starting color was too red, too blue, or too green (that is, having a high R,
G, or B value) then the resulting palette was tinted as such. When placed
next to the theory palette, for example, it was still fairly obvious that two
different algorithms had been used. It wouldn’t necessarily be interpreted
as a random assortment of colors, but it was certainly distinct from the
other palettes. Finally, it may be argued that the tinted theme contained
colors that go well together, but the colors may be a little too similar to
be considered a solution to this problem. Much like the theory palette, we
want colors that go well together and offer variety.
Inspiration for a better solution came from Erica Schoonmaker on Dribb-
ble [Sch11]. In one of her posts, Schoonmaker reveals that her secret for a
cohesive color palette is to overlay a sixth color over a five color palette. She
recommends the photoshop mask “soft light,” but the idea is to add a very
slight tint to the rest of the color palette. The result is a palette of different
colors that subtly channel this outside color to become a little more united.
We incorporate this idea into our previous solution. We were mixing the
random color and the starting color evenly. Instead, we will decidedly use
less of the starting color to let more of the random color shine through. Our
final colors will be 10% the starting color and 90% the random color. These
colors do not stick out from the other palettes as much as the previous itera-
tion. Starting colors with high RGB components did not overwhelm the rest
of the palette and, much like Schoonmaker’s post, the colors in this palette
appeared to be more consistent.
14
Figure 3.3: This is an example of our Pygame instance during the refine-
ment of the equidistant palette. The x-axis represents hue and the y-axis is
saturation. We sample colors evenly spaced along this line to create a color
palette.
15
what we generally think of when we use the word “color,” and therefore the
component users will want control over, we can rule it out as the component
that we should hold constant. However, deciding between keeping satura-
tion or lightness constant is a little more difficult. If we keep saturation
constant, the palette could very easily become divergent as the line plunges
into the darker or lighter end of the space. If we keep lightness constant,
the resulting color palette is a little more consistent. This is the option we
ultimately settled on. Our transformation consists of hue along the x-axis
and saturation on the y-axis. When the user selects a color, we use the
lightness value of the starter color selected by the user.
Drawing a straight line in the space is done by using the starting color
as the start point and randomly selecting a second color to serve as the
end point. We define a couple heuristics to ensure that the line is ideal
for deriving a good color palette. Specifically, we want to ensure the line
spans across enough hues. If the line is too short, we might only sample red
and yellow colors, for example. We enforce a restriction by calculating the
distance between the two points and limiting it to a length of at least 180
units. In the same vein, we don’t want a line that is too vertical because then
we would sample colors with the same hue at various levels of saturation.
To account for this we restrict the slope to being within the range of -1 and
1. For some colors this restriction may be a little conservative, however the
results are still varied enough that this is not too much of a problem.
With two points on a line, we can use simple algebra to determine colors
equidistant along the line. In theory we could find any number of equidistant
points along this line, but after a certain point the colors become too similar.
Their relationship to one another becomes more obvious as the sample begins
to resemble a gradient between the two endpoints. Five points might be the
maximum number of colors we can generate and still have variety, especially
given the number of restrictions we have already placed on the kinds of
palettes we can generate. Fortunately, for our case, that is all we need.
16
Chapter 4
Methodology
4.1 Technology
The logic behind the palette generation is a single Python file that imple-
ments the algorithms described in Chapter 3. This file can be viewed in
Appendix A. This file primarily utilizes Grapefruit, a Python library for
performing basic color conversions between color spaces. Grapefruit was
also used to calculate the hue templates for the theory palette and mix the
colors used in the random palette.
Initial experimentation was done locally using the Pygame gaming frame-
work. The first prototypes supported a command line interface for selecting
colors whose corresponding palettes would be generated in the Pygame in-
stance. It was in this stage of development that the heuristics for each
palette were refined. An example of this prototyping environment can be
seen in Figure 3.3.
With the logic written, we worked to bring the functionality online in or-
der to test it with more users than we could locally. By publishing Colormoo
online, we also hoped to create a tool that users could refer to later as part
of their design workflow. This was done with a combination of the Django
Python web framework and Heroku, a platform for web applications. We
chose Django to avoid porting the logic to another language like Javascript.
Django is also very well documented and tightly integrated with Heroku.
17
Heroku was chosen because it abstracts the complicated process of deploy-
ing an application on a remote server. This made it relatively easy to setup
a development environment with the correct dependencies and enabled us
to quickly push new changes to the site as necessary.
The frontend of Colormoo was implemented with Django’s templating
system, with standard HTML and CSS. The Zurb Foundation front-end
framework is lightly utilized for creating the layout and improving the overall
aesthetics of the interface. Most of the interactivity of the site is afforded
by JQuery and Javascript. In particular, the color selecting interface is
a JQuery plugin offered by Virtualsoft [Vir14]. This plugin was chosen
because it offers both the color sliders and the color specification interfaces
for selecting a color. It is also very customizable, which in our case allowed
us to change the appearance to fit with the rest of the site.
We set up a Postgres database on Heroku to collect data on palette
preference. From the site we use Django’s database API to push data to the
server. This is essentially a Python wrapper for the Postgres commands.
We record each palette selection with a JQuery post request to an empty
Django view. This view processes the request and pushes necessary figures
to the database.
18
4.2.1 Users
Colormoo was shared on a number of websites where people might be inter-
ested in generating color palettes. We attribute most visits to the Hacker
News (www.news.ycombinator.com) and Designer News (www.news.layervault.com)
communities. These are forums where professional web developers and de-
signers share techniques and offer insight into their workflow. For this rea-
son, we believe our users are primarily concerned with the usefulness of
colors as they relate to user interface and visual design. They may not be
color experts, but we expect that they are approaching this problem with
an experienced eye.
4.2.2 Postprocessing
The data required some postprocessing before we could begin analysis. Ev-
ery time the app is loaded, the starting color is initially set to a pink color.
To account for this oversight, we had to toss much of the data that included
these initial component values. We also had to clean the data where it ap-
peared that users were testing the capabilities of the application. This was
made evident by duplicate rows of data in which the only difference was a
single column value. This anomaly can be attributed to the lack of context
that is provided for the application on the forums where it was published.
Users may have repeatedly generated the same results to determine how to
use the site. It could also be that users liked more than one of the palettes
and wanted the color specifications for both. Unfortunately, with the current
implementation, there is no other way to support this kind of behavior. To
account for this potentially extraneous data, we only take the first instance
of the repeated trials.
19
20
Chapter 5
Results
21
Figure 5.1: While there is no correlation between hue and a specific color
palette, we can observe user preference for red and blue colors.
around pure red at 0 degrees, but this could also be attributed to red being
located at the end of the slider. However, these results are consistent with
previous studies of color preference that found a general preference for reds
and blues [OAH11]. The least popular colors sit above 252 degrees. These
represent violet and magenta respectively.
5.1.2 Saturation
When we look at the saturation of the starting colors selected by the user
(Figure 5.2), we see more variation across the different palettes than we see
with hue. In particular, as the starting color becomes more saturated, users
tend to prefer the theory palette. This is most noticeable with levels of
saturation above 70%. However as the starting color becomes less saturated
the random palette becomes more popular. These two observations hold true
especially for the most extreme values of saturation. When the starting color
has 0% saturation, there is an overwhelming support for the random palette.
Likewise, when the starting color has 100% saturation the theory palette is
very clearly the favorite.
5.1.3 Lightness
Similar to saturation, there is more of a preference for one palette over the
other for different values of lightness (Figure 5.3). With a lighter starting
color, users preferred the theory palette. With the exception of the lightest
colors in the 88-100% range, the theory palette was preferred for every color
22
Figure 5.2: The theory palette is more popular with highly saturated colors.
above a 48% lightness value. Everything below that point was favored by
the random palette.
5.2 Discussion
Intuitively it makes sense that for more saturated colors, users prefer the
theory palette and for less saturated colors prefer the random palette. Sat-
uration is essentially a measure of how dull or intense a color appears. In
other words, saturation is the amount of color present in a particular color.
When there is a lot of color present, it makes sense that users would recog-
nize theoretical color relationships and prefer the palette that best utilizes
that color intensity. When there is very little color present, users might
appreciate the additional intensity afforded by a random set of colors.
The lightness results are a little more surprising. When users select
a light starting color, the results imply that they are trying to produce a
lighter color palette, such as the one generated using color theory. In this
case the result is usually a pastel palette. However, when users select a dark
color, the data suggests they are not trying to create a dark palette. Instead,
as with less saturated colors, they choose the random palette which tends
to be a brighter and more vibrant. Previous studies found a preference for
brighter palettes [OAH11]. Our data supports these findings.
These two results indicate that the preferred palette does not contain
colors that are too similar. A desaturated color will generate a desaturated
theory palette. The palette appears muted because its colors are not visually
distinct. The same effect can be observed with a dark starting color. The
23
Figure 5.3: The theory palette is more popular with lighter colors while the
random palette is preferred for darker colors.
24
Chapter 6
Future Work
There are several ways in which Colormoo can be improved. There are also
different avenues in which these concepts can be applied outside the context
of graphic design.
6.1 Refinement
Gregor Aisch actually advises against using equidistant colors with the HSL
color space [Ais11]. The problem is that, though the colors are mathemati-
cally the same distance from each other when plotted out in the transformed
color space, the colors may not necessarily be perceived to be equidistant by
the human eye. In some cases the jump from one color to the next may seem
larger than the subsequent jump. Aisch recommends using a more percep-
tually uniform color space like CIE LAB. While we experimented with it,
this approach was omitted from Colormoo because CIE LAB contains gaps
to account for the intricacies of human vision. It was difficult to develop a
good set of heuristics and account for these gaps such that we could consis-
tently offer a fourth palette. Future work might explore this concept a bit
further. Perhaps the equidistant palette performed the worst because of the
minor perceptual inconsistencies associated with HSL.
With the initial data on palette preference for different color values, we
can further explore how adding heuristics might improve the experience. It
might also help to consider the different ways in which these palettes are
used. For example, in design work, it is not very often that each color
is used the same amount. To generate a more useful palette, it might be
worth exploring a way to determine which colors in the palette should be
the principal colors and which colors should be secondary or only used as
25
accents.
26
Chapter 7
Conclusion
There are many ways to derive a set of colors that are compatible with one
another. Color experts across a variety of professions each have their own
solutions to this problem. We wanted to measure the circumstances under
which each technique was most successful.
We built Colormoo to evaluate three algorithms for generating color
palettes based off of a starting color. We found that the palette based on
color theory was most popular with highly saturated and light colors. When
the starting color is less saturated or dark, users prefer the random palette.
This may be because it produces palettes with more visually distinct colors.
Designers can take advantage of these findings by ensuring that their work
incorporates colors that are compatible, but not too similar.
We also note a general preference for red and blue colors as they were the
ones most frequently input as the starting color. More extensive research
needs to be done to determine how this might fit into a solution to the
problem of generating color palettes.
Our work provides a starting point for future exploration of the topic.
We believe that with refined heuristics and a better understanding of the
way humans perceive color, these algorithms can be improved and extended
such that they can be applied beyond the field of graphic design.
27
28
Appendix A
Included here is the main python file for generating the three color palettes
used on Colormoo. The only dependency is the python Grapefruit color
conversion library. This code is provided ”as is” without warranties or con-
ditions of any kind.
import sys
import random
import grapefruit
import pdb
import ast
import math
random.seed(542)
def generateRandomColor(mix):
""" Averages the RGB values of a random color and the input to
effectively ’mix’ the two colors
"""
red = random.uniform(0,255)
green = random.uniform(0,255)
blue = random.uniform(0,255)
29
newColor = grapefruit.Color.NewFromRgb(red, green, blue)
return newColor
def RGBconvertToHTML(color):
""" Takes a grapefruit color in RGB and converts it to HTML"""
r = color.rgb[0] / 255
g = color.rgb[1] / 255
b = color.rgb[2] / 255
return grapefruit.Color.RgbToHtml(r,g,b)
def averaged(myColor):
# create dictionary of colors
d = {}
d["one"] = RGBconvertToHTML(generateRandomColor(myColor))
d["two"] = RGBconvertToHTML(generateRandomColor(myColor))
d["three"] = RGBconvertToHTML(generateRandomColor(myColor))
d["four"] = RGBconvertToHTML(generateRandomColor(myColor))
d["five"] = RGBconvertToHTML(generateRandomColor(myColor))
return d
def generateBlendedColor(myColor):
red = random.uniform(0,255)
green = random.uniform(0,255)
blue = random.uniform(0,255)
randomColor = grapefruit.Color.NewFromRgb(red, green, blue)
newColor = myColor.Blend(randomColor, 0.1)
return newColor
def blended(myColor):
# create dictionary of colors
d = {}
d["one"] = RGBconvertToHTML(generateBlendedColor(myColor))
d["two"] = RGBconvertToHTML(generateBlendedColor(myColor))
d["three"] = RGBconvertToHTML(generateBlendedColor(myColor))
d["four"] = RGBconvertToHTML(generateBlendedColor(myColor))
d["five"] = RGBconvertToHTML(generateBlendedColor(myColor))
return d
30
a1, a2 = myColor.AnalogousScheme(angle=30, mode=myMode)
t1, t2 = myColor.TriadicScheme(angle=120, mode=myMode)
c = myColor.ComplementaryColor(mode=myMode)
################################################
# HSL COLOR SPACE CODE #
################################################
# 360/250 = 1.44
hue = [x*1.44 for x in range(250)]
sat = [x*0.4 for x in range(250)]
31
def distance(x0,y0,x1,y1):
return math.sqrt((float(x1-x0)**2) + ((y1-y0)**2))
def slope(x0,y0,x1,y1):
if (x1-x0) == 0: return float("inf")
return float(y1-y0)/(x1-x0)
def midpoint(x0,y0,x1,y1):
return (x0+x1)/2, (y0+y1)/2
def newRandomColor(mix):
""" Generates a new color with the lightness of the input color
"""
h,s,l = mix.hsl
hue = random.uniform(0,360)
sat = random.random()
lineColor = grapefruit.Color.NewFromHsl(hue, sat, l)
return lineColor
def genNewColor(myColor):
""" Returns a valid random color relative to the input color
"""
lineColor = newRandomColor(myColor)
32
return lineColor
def fiveColors(myColor):
endColor = genNewColor(myColor)
oh, os, ol = myColor.hsl
ch, cs, cl = endColor.hsl
# find the second color (midpoint of first and the newly generated midpoint)
sndHue, sndSat = midpoint(oh, os, midHue, midSat)
sndColor = grapefruit.Color.NewFromHsl(sndHue, sndSat, ol)
33
34
Bibliography
[HLT09] Y-C. Hu, M-G. Lee, and P. Tsai. Colour palette generation
schemes for colour image quantization. Imaging Science Journal,
57(1):46 – 59, 2009.
35