4 # Copyright (C) 2002 Jörg Lehmann <joergl@users.sourceforge.net>
5 # Copyright (C) 2002 André Wobst <wobsta@users.sourceforge.net>
7 # This file is part of PyX (http://pyx.sourceforge.net/).
9 # PyX is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
14 # PyX is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with PyX; if not, write to the Free Software
21 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 class color(base
.PathStyle
):
27 """base class for all colors"""
36 def __init__(self
, gray
):
37 if gray
<0 or gray
>1: raise ValueError
38 self
.color
= {"gray": gray
}
40 def write(self
, file):
41 file.write("%(gray)f setgray\n" % self
.color
)
43 grey
.black
= grey(0.0)
44 grey
.white
= grey(1.0)
52 def __init__(self
, r
=0.0, g
=0.0, b
=0.0):
53 if r
<0 or r
>1 or g
<0 or g
>1 or b
<0 or b
>1: raise ValueError
54 self
.color
= {"r": r
, "g": g
, "b": b
}
56 def write(self
, file):
57 file.write("%(r)f %(g)f %(b)f setrgbcolor\n" % self
.color
)
60 rgb
.green
= rgb(0,1,0)
68 def __init__(self
, h
=0.0, s
=0.0, b
=0.0):
69 if h
<0 or h
>1 or s
<0 or s
>1 or b
<0 or b
>1: raise ValueError
70 self
.color
= {"h": h
, "s": s
, "b": b
}
72 def write(self
, file):
73 file.write("%(h)f %(s)f %(b)f sethsbcolor\n" % self
.color
)
80 def __init__(self
, c
=0.0, m
=0.0, y
=0.0, k
=0.0):
81 if c
<0 or c
>1 or m
<0 or m
>1 or y
<0 or y
>1 or k
<0 or k
>1: raise ValueError
82 self
.color
= {"c": c
, "m": m
, "y": y
, "k": k
}
84 def write(self
, file):
85 file.write("%(c)f %(m)f %(y)f %(k)f setcmykcolor\n" % self
.color
)
88 cmyk
.GreenYellow
= cmyk(0.15, 0, 0.69, 0)
89 cmyk
.Yellow
= cmyk(0, 0, 1, 0)
90 cmyk
.Goldenrod
= cmyk(0, 0.10, 0.84, 0)
91 cmyk
.Dandelion
= cmyk(0, 0.29, 0.84, 0)
92 cmyk
.Apricot
= cmyk(0, 0.32, 0.52, 0)
93 cmyk
.Peach
= cmyk(0, 0.50, 0.70, 0)
94 cmyk
.Melon
= cmyk(0, 0.46, 0.50, 0)
95 cmyk
.YellowOrange
= cmyk(0, 0.42, 1, 0)
96 cmyk
.Orange
= cmyk(0, 0.61, 0.87, 0)
97 cmyk
.BurntOrange
= cmyk(0, 0.51, 1, 0)
98 cmyk
.Bittersweet
= cmyk(0, 0.75, 1, 0.24)
99 cmyk
.RedOrange
= cmyk(0, 0.77, 0.87, 0)
100 cmyk
.Mahogany
= cmyk(0, 0.85, 0.87, 0.35)
101 cmyk
.Maroon
= cmyk(0, 0.87, 0.68, 0.32)
102 cmyk
.BrickRed
= cmyk(0, 0.89, 0.94, 0.28)
103 cmyk
.Red
= cmyk(0, 1, 1, 0)
104 cmyk
.OrangeRed
= cmyk(0, 1, 0.50, 0)
105 cmyk
.RubineRed
= cmyk(0, 1, 0.13, 0)
106 cmyk
.WildStrawberry
= cmyk(0, 0.96, 0.39, 0)
107 cmyk
.Salmon
= cmyk(0, 0.53, 0.38, 0)
108 cmyk
.CarnationPink
= cmyk(0, 0.63, 0, 0)
109 cmyk
.Magenta
= cmyk(0, 1, 0, 0)
110 cmyk
.VioletRed
= cmyk(0, 0.81, 0, 0)
111 cmyk
.Rhodamine
= cmyk(0, 0.82, 0, 0)
112 cmyk
.Mulberry
= cmyk(0.34, 0.90, 0, 0.02)
113 cmyk
.RedViolet
= cmyk(0.07, 0.90, 0, 0.34)
114 cmyk
.Fuchsia
= cmyk(0.47, 0.91, 0, 0.08)
115 cmyk
.Lavender
= cmyk(0, 0.48, 0, 0)
116 cmyk
.Thistle
= cmyk(0.12, 0.59, 0, 0)
117 cmyk
.Orchid
= cmyk(0.32, 0.64, 0, 0)
118 cmyk
.DarkOrchid
= cmyk(0.40, 0.80, 0.20, 0)
119 cmyk
.Purple
= cmyk(0.45, 0.86, 0, 0)
120 cmyk
.Plum
= cmyk(0.50, 1, 0, 0)
121 cmyk
.Violet
= cmyk(0.79, 0.88, 0, 0)
122 cmyk
.RoyalPurple
= cmyk(0.75, 0.90, 0, 0)
123 cmyk
.BlueViolet
= cmyk(0.86, 0.91, 0, 0.04)
124 cmyk
.Periwinkle
= cmyk(0.57, 0.55, 0, 0)
125 cmyk
.CadetBlue
= cmyk(0.62, 0.57, 0.23, 0)
126 cmyk
.CornflowerBlue
= cmyk(0.65, 0.13, 0, 0)
127 cmyk
.MidnightBlue
= cmyk(0.98, 0.13, 0, 0.43)
128 cmyk
.NavyBlue
= cmyk(0.94, 0.54, 0, 0)
129 cmyk
.RoyalBlue
= cmyk(1, 0.50, 0, 0)
130 cmyk
.Blue
= cmyk(1, 1, 0, 0)
131 cmyk
.Cerulean
= cmyk(0.94, 0.11, 0, 0)
132 cmyk
.Cyan
= cmyk(1, 0, 0, 0)
133 cmyk
.ProcessBlue
= cmyk(0.96, 0, 0, 0)
134 cmyk
.SkyBlue
= cmyk(0.62, 0, 0.12, 0)
135 cmyk
.Turquoise
= cmyk(0.85, 0, 0.20, 0)
136 cmyk
.TealBlue
= cmyk(0.86, 0, 0.34, 0.02)
137 cmyk
.Aquamarine
= cmyk(0.82, 0, 0.30, 0)
138 cmyk
.BlueGreen
= cmyk(0.85, 0, 0.33, 0)
139 cmyk
.Emerald
= cmyk(1, 0, 0.50, 0)
140 cmyk
.JungleGreen
= cmyk(0.99, 0, 0.52, 0)
141 cmyk
.SeaGreen
= cmyk(0.69, 0, 0.50, 0)
142 cmyk
.Green
= cmyk(1, 0, 1, 0)
143 cmyk
.ForestGreen
= cmyk(0.91, 0, 0.88, 0.12)
144 cmyk
.PineGreen
= cmyk(0.92, 0, 0.59, 0.25)
145 cmyk
.LimeGreen
= cmyk(0.50, 0, 1, 0)
146 cmyk
.YellowGreen
= cmyk(0.44, 0, 0.74, 0)
147 cmyk
.SpringGreen
= cmyk(0.26, 0, 0.76, 0)
148 cmyk
.OliveGreen
= cmyk(0.64, 0, 0.95, 0.40)
149 cmyk
.RawSienna
= cmyk(0, 0.72, 1, 0.45)
150 cmyk
.Sepia
= cmyk(0, 0.83, 1, 0.70)
151 cmyk
.Brown
= cmyk(0, 0.81, 1, 0.60)
152 cmyk
.Tan
= cmyk(0.14, 0.42, 0.56, 0)
153 cmyk
.Gray
= cmyk(0, 0, 0, 0.50)
154 cmyk
.Grey
= cmyk
.Gray
155 cmyk
.Black
= cmyk(0, 0, 0, 1)
156 cmyk
.White
= cmyk(0, 0, 0, 0)
161 def __init__(self
, mincolor
, maxcolor
, min=0, max=1):
162 if mincolor
.__class
__ != maxcolor
.__class
__:
164 self
.colorclass
= mincolor
.__class
__
165 self
.mincolor
= mincolor
166 self
.maxcolor
= maxcolor
170 def getcolor(self
, index
):
172 for key
in self
.mincolor
.color
.keys():
173 color
[key
] = ((index
- self
.min) * self
.maxcolor
.color
[key
] +
174 (self
.max - index
) * self
.mincolor
.color
[key
])/float(self
.max - self
.min)
175 return self
.colorclass(**color
)
178 gradient
.Gray
= gradient(gray
.white
, gray
.black
)
179 gradient
.Grey
= gradient
.Gray
180 gradient
.ReverseGray
= gradient(gray
.black
, gray
.white
)
181 gradient
.ReverseGrey
= gradient
.ReverseGray
182 gradient
.RedGreen
= gradient(rgb
.red
, rgb
.green
)
183 gradient
.RedBlue
= gradient(rgb
.red
, rgb
.blue
)
184 gradient
.GreenRed
= gradient(rgb
.green
, rgb
.red
)
185 gradient
.GreenBlue
= gradient(rgb
.green
, rgb
.blue
)
186 gradient
.BlueRed
= gradient(rgb
.blue
, rgb
.red
)
187 gradient
.BlueGreen
= gradient(rgb
.blue
, rgb
.green
)
188 gradient
.RedBlack
= gradient(rgb
.red
, rgb(0, 0, 0))
189 gradient
.BlackRed
= gradient(rgb(0, 0, 0), rgb
.red
)
190 gradient
.RedWhite
= gradient(rgb
.red
, rgb(1, 1, 1))
191 gradient
.WhiteRed
= gradient(rgb(1, 1, 1), rgb
.red
)
192 gradient
.GreenBlack
= gradient(rgb
.green
, rgb(0, 0, 0))
193 gradient
.BlackGreen
= gradient(rgb(0, 0, 0), rgb
.green
)
194 gradient
.GreenWhite
= gradient(rgb
.green
, rgb(1, 1, 1))
195 gradient
.WhiteGreen
= gradient(rgb(1, 1, 1), rgb
.green
)
196 gradient
.BlueBlack
= gradient(rgb
.blue
, rgb(0, 0, 0))
197 gradient
.BlackBlue
= gradient(rgb(0, 0, 0), rgb
.blue
)
198 gradient
.BlueWhite
= gradient(rgb
.blue
, rgb(1, 1, 1))
199 gradient
.WhiteBlue
= gradient(rgb(1, 1, 1), rgb
.blue
)
200 gradient
.Rainbow
= gradient(hsb(0, 1, 1), hsb(2.0/3.0, 1, 1))
201 gradient
.ReverseRainbow
= gradient(hsb(2.0/3.0, 1, 1), hsb(0, 1, 1))
202 gradient
.Hue
= gradient(hsb(0, 1, 1), hsb(1, 1, 1))
203 gradient
.ReverseHue
= gradient(hsb(1, 1, 1), hsb(0, 1, 1))