A limited palette of named colors

There is a vast list of romantically named colors like cornflower blue, misty rose, or papaya whip. There are about 340 of these named colors that are usable in Python.

Colors get names because people remember them most easily in association with a place and an emotional mood. It is easy to remember evocative names and therefore easier to use them. In this example, we reduce the long list down to 140 by using systematic names and eliminating colors that are very similar.

How to do it...

Execute the program shown in exactly the same way as all the examples in previous chapters. What you should see on your screen is a logically laid out chart of rectangular color swatches. Each will have its callable name on it. These are names you can use in Python/Tkinter programs and they will be correctly displayed.

#systematic_colorNames_1.py
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
from Tkinter import *
root = Tk()
root.title("Systematically named colors - limited pallette")
cw = 1000 # canvas width
ch = 800 # canvas height
canvas_1 = Canvas(root, width=cw, height=ch, background="black")
canvas_1.grid(row=0, column=1)
whiteColors = "Gainsboro","peach puff","cornsilk",
"honeydew","aliceblue","misty rose","snow", "snow3","snow4",
"SlateGray1", "SlateGray3", "SlateGray4",
"gray", "darkGray","DimGray","DarkSlateGray"
redColors = "Salmon","salmon1","salmon2","salmon3","salmon4",
"orange red","OrangeRed2","OrangeRed3","OrangeRed4",
"red","red3","red4",
"IndianRed1","IndianRed3","IndianRed4",
"firebrick","firebrick1","firebrick3","firebrick4",
"sienna","sienna1","sienna3","sienna4"
pinkColors = "Pink","pink3","pink4",
"hot pink","HotPink3","HotPink4",
"deep pink","DeepPink3","DeepPink4",
"PaleVioletRed1","PaleVioletRed2","PaleVioletRed3","PaleVioletRed4",
"maroon","maroon1","maroon3","maroon4"
magentaColors = "magenta","magenta3","magenta4","DarkMagenta",
"orchid1","orchid3","orchid4",
"MediumOrchid3","MediumOrchid4",
"DarkOrchid","DarkOrchid1","DarkOrchid4",
"MediumPurple1","MediumPurple3", "MediumPurple4",
"purple","purple3","purple4"
blueColors = "blue","blue3","blue4",
"SlateBlue1", "SlateBlue3","SlateBlue4",
"DodgerBlue2", "DodgerBlue3","DodgerBlue4",
"deep sky blue","DeepSkyBlue3", "DeepSkyBlue4",
"sky blue", "SkyBlue3", "SkyBlue4"
cyanColors = "CadetBlue1", "CadetBlue3", "CadetBlue4",
"pale turquoise", "PaleTurquoise3","PaleTurquoise4",
"cyan", "cyan3", "cyan4",
"aquamarine","aquamarine3", "aquamarine4"
greenColors = "green", "green3", "green4","dark green",
colorssimilar colors, eliminating"chartreuse", "chartreuse3", "chartreuse4",
"SeaGreen","SeaGreen1", "SeaGreen3",
"pale green", "PaleGreen3", "PaleGreen4",
"spring green", "SpringGreen3", "SpringGreen4",
"olive drab","OliveDrab1", "OliveDrab4",
"dark olive green","DarkOliveGreen1", "DarkOliveGreen3",  "DarkOliveGreen4",
yellowColors= "yellow", "yellow3","yellow4",
colorsrectangular color swatches chart"gold","gold3","gold4",
"goldenrod","goldenrod1","goldenrod3","goldenrod4",
"orange","orange3","orange4",
"dark orange","DarkOrange1","DarkOrange4"
x_start = 10
y_start = 25
x_width = 118
x_offset = 2
y_height = 30
y_offset = 3
text_offset = 0
text_width = 95
kbk = [x_start, y_start, x_start + x_width, y_start + y_height]
defshowColors(selectedColor):
# Basic columnar color swatch display. All colours laid down in a # vertical stripe.
print "number of colors --> ", len(selectedColor)
for i in range (0,len(selectedColor)):
kula = selectedColor[i]
canvas_1.create_rectangle(kbk, fill=kula)
canvas_1.create_text(kbk[0]+10, kbk[1] , text=kula,  width=text_width, fill ="black", anchor=NW)
kbk[1] += y_offset + y_height
y0 = kbk[1]
kbk[3] += y_offset + y_height
y1 = kbk[3]
kbk[1] = y_offset + y_height
kbk[3] = y_offset + 2 * y_height
kbk[0] += x_width + 2*x_offset
kbk[2] += x_width + 2*x_offset
return y0,y1
showColors(redColors)
showColors(pinkColors)
showColors(magentaColors)
showColors(cyanColors)
showColors(blueColors)
showColors(greenColors)
showColors(yellowColors)
showColors(whiteColors)
root.mainloop()
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

How it works...

This program uses techniques developed in Chapter 2, Drawing Fundamental Shapes. There are eight lists of named colors grouped in color families with each family arranged in a logical sequence. The main technique was to use a general purpose function that would use a pre-defined rectangle and using a for loop, work through the list of color names in sequence. With each iteration of the loop, a rectangle is filled with that color and the color name is printed across it.

There's more...

These colors were chosen by trial and error to provide a reasonably wide palette suitable for most purposes. In the numbered sequences of colors like red where red1, red2, red3, and red4 represent increasingly darker shades, colors that are very similar to other colors in their neighborhood have been left out. It was also discovered that many colors were fake in that they are painted onto the canvas as grey.

The complete set of color names that Tkinter recognizes are found at http://wiki.tcl.tk/16166

To get fine shadings of the primary colors

To achieve the subtle shadings and graduations of color combination, you need to mix the primary colors used on computer screens in controlled amounts. We begin this process in the next recipe.

A more compact color list

An even shorter sub-set of useful named colors are in the following color lists:

  • white_Colors = "white", "lemon chiffon", "honeydew","aliceblue","thistle", "misty rose"
  • blue_Colors = "blue","blue4","SlateBlue1","dodger blue","steelblue","sky blue"
  • grey_Colors ="SlateGray3", "SlateGray4", "LightGrey", "DarkGray", "DimGray", "LightSlateGray"
  • cyan_Colors = "CadetBlue1", "cyan", "cyan4", "LightSeaGreen", "aquamarine", "aquamarine3"
  • red_Colors = "light pink","IndianRed1","red","red2","red3","red4"
  • pink_Colors = "light pink","deeppink","hot pink","HotPink3","LightPink","LightPink2"
  • magenta_Colors = "PaleVioletRed1", "maroon", "maroon1", "magenta","magenta4", "orchid1"
  • purple_Colors = "purple", "purple4", "MediumPurple1", "plum2", "MediumOrchid", "DarkOrchid"
  • brown_Colors = "orange", "DarkOrange1", "DarkOrange2", "DarkOrange3", "DarkOrange4", "saddle brown"
  • green_Colors = "green", "green3", "green4"," chartreuse"," green yellow", "SpringGreen2"
  • yellow_Colors= "light yellow", "yellow", "yellow3","gold", "goldenrod1", "Khaki"

If you cut and paste these lists to replace the previous ones in systematic_colorNames_1.py, you will have a smaller, easier to manage, palette of 55 colors that you may find simpler to use.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.59.219