473,543 Members | 1,911 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Color Generator

My form allows the user to assign colors to different fields that are then
used in a java piechart/barchart applet as the colors of the different pie
sections/bars. It can be tedious assigning colors even with my color pic
tool especially as the number of different colors increases. The application
is data driven so it may end up requiring any number of colors up to about
100. Of course you want the colors to be as different as possible. It would
be nice to have an "Auto" button to click that will then fill out all the
color fields with a properly generated set of colors - that is colors that
are as different from each other as possible. Random colors won't do as you
might end up with very similar colors. Is such a program possible?
Apr 1 '06 #1
4 3943

Simon Wigzell wrote:
My form allows the user to assign colors to different fields that are then
used in a java piechart/barchart applet as the colors of the different pie
sections/bars. It can be tedious assigning colors even with my color pic
tool especially as the number of different colors increases. The application
is data driven so it may end up requiring any number of colors up to about
100. Of course you want the colors to be as different as possible. It would
be nice to have an "Auto" button to click that will then fill out all the
color fields with a properly generated set of colors - that is colors that
are as different from each other as possible. Random colors won't do as you
might end up with very similar colors. Is such a program possible?


Possibly.

Here's some color conversion functions

http://www.cs.rit.edu/~ncs/color/t_convert.html

Choose a hue to create the first color and the full Saturation and
Value (S=1, V=1) , then create the rgb values using tHSVtoRGB functions
by changing the hue value by 15/30/45 degrees each time.

Once you reach 360 degrees repeat the previous steps but with less
Saturation and full Value ( S<1 , V=1) , then the next time round with
full saturation and less value (S=1, V<1), and so on till you have
enough colors

The colors will then be fairly distributed with a reasonably even
distribution,

One problem is the HSV algorithm is not really perfectly evenly
distributed to the human eye - so you may end up with more blue +
violets than reds and yellow ( or maybe the other way round? )

Another problem is that with a 100 colors some will look alike, with
that many colors some shades will be hard to tell apart no matter what
you do.

Hope this is of some help

Tim

Apr 1 '06 #2
> Possibly.

Here's some color conversion functions


The functions are written in C, its enough easy to convert them to
javascript but its even easier to have me email them to you. :)

I won't be online much longer tonight, so if you want them write back
soon

Tim

Apr 1 '06 #3
Simon Wigzell wrote:
[...] It would be nice to have an "Auto" button to click that will then
fill out all the color fields with a properly generated set of colors -
that is colors that are as different from each other as possible. Random
colors won't do as you might end up with very similar colors. Is such a
program possible?


I think it is, although I do not think the solution will be a trivial one.
The first step would be to define the distance function: What makes color
C more different from color A than color B? Is it its color temperature,
hue, luminance etc. or a combination of either one (whereas you have to
take into account that computer displays and printers cannot display all
colors perceptible by humans)? After you have done that, you can devise an
algorithm to calculate C as the point with the maximum distance from A and
B within a finite n-dimensional space, according to that relation. Of
course there can be more than one solution, given the same start point.

The most simple solution would be using the existing RGB three-dimensional
color space. Starting with Black (0, 0, 0), the next "most different"
color, defined as the most distant point in the color space, would be White
(255, 255, 255). The next most distant points not already visited (colors
already used) would be the corners of that cube, identifying Red (255, 0,
0), Green (0, 255, 0), Blue (0, 0, 255), and the other standard colors like
Magenta (255, 0, 255). That would provide you with 8 "very different"
colors already, that do not even need to be computed (with a given set of
already used colors, you would only need to compute what corner color point
would have the maximum distance from all already used color points). The
next "most different" color, i.e. a point in the color space with the
maximum distance from all other already used points would be the center of
the greatest subset created by adjacent visited points (where you would
define the shape of that subset truly linear [between adjacent visited
points on a straight line], truly triangular [the center of the triangle
created by visited points that are not on a straight line], cubic, and so
on; since the color space is cubic, I would use a cubic-shaped subset).

In practice, you want to align that algorithm on the points in the color
space identifying the 216 True Web-safe colors, and you want to avoid
reddish and greenish colors that have the same grey-value.
PointedEars
Apr 3 '06 #4
ti********@gmai l.com wrote:
Simon Wigzell wrote:
[Is there a program to generate colors that are as different from each
other as possible?]


[...]
Choose a hue to create the first color and the full Saturation and
Value (S=1, V=1) , then create the rgb values using tHSVtoRGB functions
by changing the hue value by 15/30/45 degrees each time.

Once you reach 360 degrees repeat the previous steps but with less
Saturation and full Value ( S<1 , V=1) , then the next time round with
full saturation and less value (S=1, V<1), and so on till you have
enough colors

The colors will then be fairly distributed with a reasonably even
distribution,

One problem is the HSV algorithm is not really perfectly evenly
distributed to the human eye - so you may end up with more blue +
violets than reds and yellow ( or maybe the other way round? )

Another problem is that with a 100 colors some will look alike, with
that many colors some shades will be hard to tell apart no matter what
you do.


Another catch of this approach is that for a reasonable decrement in
saturation, and later value, to create colors "most different" from
one another (taking the restrictions above into account), you would
need to know how many colors would be needed _before_ you apply the
algorithm. My "RGB color space coordinates-marking" approach does
not need that.
PointedEars
Apr 3 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1892
by: Mike | last post by:
I need to be able to store a list of schedulable items, either regular callables or generator-producing functions -- is there a way to test if a fn is generator-producing? (In the non-generator case, the fn is a 'tick' fn that I will call to produce results - a pre-generator implementation.) I can test for a generator itself with isinstance(f,...
4
2312
by: Wai Yip Tung | last post by:
I'm attempting to turn some process than uses callback to return result into a more user friendly generator. I'm hitting some road block so any pointer would be appriciated. Let say there is an existing method producer(x, cb). It calls the supplied cb() every time when there is data available. The definititon of cb should be: def cb(data)
12
1921
by: Thomas Lotze | last post by:
Hi, I'm trying to figure out what is the most pythonic way to interact with a generator. The task I'm trying to accomplish is writing a PDF tokenizer, and I want to implement it as a Python generator. Suppose all the ugly details of toknizing PDF can be handled (such as embedded streams of arbitrary binary content). There remains one...
2
2712
by: Bernhard Mulder | last post by:
I have something like the following (using Python 2.5 syntax): class adapt(object): def __init__(self): self.iterator = self.generator() self.n = 0 def generator(self): while True: while True:
20
2886
by: Chris Withers | last post by:
Hi All, The following piece of code is giving me issues: from email.Charset import Charset,QP from email.MIMEText import MIMEText charset = Charset('utf-8') charset.body_encoding = QP msg = MIMEText( u'Some text with chars that need encoding: \xa3',
3
3510
by: andy.leszczynski | last post by:
Hi, I might understand why this does not work, but I am not convinced it should not - following: def nnn(): print 'inside' yield 1 def nn():
4
1573
by: Kenneth McDonald | last post by:
I'm trying to write a 'flatten' generator which, when give a generator/iterator that can yield iterators, generators, and other data types, will 'flatten' everything so that it in turns yields stuff by simply yielding the instances of other types, and recursively yields the stuff yielded by the gen/iter objects. To do this, I need to...
1
1636
by: Schüle Daniel | last post by:
Hello, I came up with this algorithm to generate all permutations it's not the best one, but it's easy enough # lst = list with objects def permute3(lst): tmp = lenlst = len(lst) def permute(perm, level):
9
2009
by: Kugutsumen | last post by:
I am relatively new the python language and I am afraid to be missing some clever construct or built-in way equivalent to my 'chunk' generator below. def chunk(size, items): """generate N items from a generator.""" chunk = count = 0 while True: try:
14
1204
by: castironpi | last post by:
I'm actually curious if there's a way to write a generator function (not a generator expression) in C, or what the simplest way to do it is... besides link the Python run-time.
0
7355
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7594
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7746
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7356
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7697
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
4899
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3394
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1830
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
979
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.