Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Random Colors For Use In Defining Different Regions

Reply
Thread Tools

Random Colors For Use In Defining Different Regions

 
 
Adam Hartshorne
Guest
Posts: n/a
 
      01-27-2006
Hi All,

I was wondering if somebody could post a few lines of code which would
produce random colors, which will be used in defining different regions
on a mesh. So in addition to having n random colors, I feel that there
should also be some condition to ensure that they aren't too similar in
appearance, given that is likely to range from 2-20 say.

Any help much appreciated,

Adam
 
Reply With Quote
 
 
 
 
Adam Hartshorne
Guest
Posts: n/a
 
      01-27-2006
Adam Hartshorne wrote:
> Hi All,
>
> I was wondering if somebody could post a few lines of code which would
> produce random colors, which will be used in defining different regions
> on a mesh. So in addition to having n random colors, I feel that there
> should also be some condition to ensure that they aren't too similar in
> appearance, given that is likely to range from 2-20 say.
>
> Any help much appreciated,
>
> Adam


I should have added I'm also looking to be able limit the range of the
colors as well. Say to avoid ever having black or white etc.

Adam
 
Reply With Quote
 
 
 
 
Adam Hartshorne
Guest
Posts: n/a
 
      01-27-2006
Adam Hartshorne wrote:
> Hi All,
>
> I was wondering if somebody could post a few lines of code which would
> produce random colors, which will be used in defining different regions
> on a mesh. So in addition to having n random colors, I feel that there
> should also be some condition to ensure that they aren't too similar in
> appearance, given that is likely to range from 2-20 say.
>
> Any help much appreciated,
>
> Adam


I think I should have said I obviously know how to produce 3 random
numbers to plug into RGB, but I was looking for a more sensible
arrangement than this.

Also, I should have added I'm also looking to be able limit the range of
the colors as well. Say to avoid ever having black or white etc.

Adam
 
Reply With Quote
 
Adam Hartshorne
Guest
Posts: n/a
 
      01-27-2006
Adam Hartshorne wrote:
> Hi All,
>
> I was wondering if somebody could post a few lines of code which would
> produce random colors, which will be used in defining different regions
> on a mesh. So in addition to having n random colors, I feel that there
> should also be some condition to ensure that they aren't too similar in
> appearance, given that is likely to range from 2-20 say.
>
> Any help much appreciated,
>
> Adam


I think I should have said I obviously know how to produce 3 random
numbers to plug into RGB, but I was looking for a more sensible
arrangement than this.

Also, I should have added I'm also looking to be able limit the range of
the colors as well. Say to avoid ever having black or white etc.

Adam
 
Reply With Quote
 
Mike Wahler
Guest
Posts: n/a
 
      01-27-2006

"Adam Hartshorne" <> wrote in message
news:43daaa5f$...
> Adam Hartshorne wrote:
>> Hi All,
>>
>> I was wondering if somebody could post a few lines of code which would
>> produce random colors, which will be used in defining different regions
>> on a mesh. So in addition to having n random colors, I feel that there
>> should also be some condition to ensure that they aren't too similar in
>> appearance, given that is likely to range from 2-20 say.
>>
>> Any help much appreciated,
>>
>> Adam

>
> I think I should have said I obviously know how to produce 3 random
> numbers to plug into RGB, but I was looking for a more sensible
> arrangement than this.


I don't understand why you call it 'not sensible'

>
> Also, I should have added I'm also looking to be able limit the range of
> the colors as well. Say to avoid ever having black or white etc.


You could generate a (pseudo)random number withing a
specified range. See the C FAQ for details.

If any undesired values fall inside a range, you can define
several ranges, delimited by the undesired values, and randomly
select a range before randomly selecting a value from it.
If necessary you could also use the same approach to randomly select
'cells' or ranges of cells in your mesh.

-Mike


 
Reply With Quote
 
Adam Hartshorne
Guest
Posts: n/a
 
      01-27-2006
Mike Wahler wrote:
> "Adam Hartshorne" <> wrote in message
> news:43daaa5f$...
>> Adam Hartshorne wrote:
>>> Hi All,
>>>
>>> I was wondering if somebody could post a few lines of code which would
>>> produce random colors, which will be used in defining different regions
>>> on a mesh. So in addition to having n random colors, I feel that there
>>> should also be some condition to ensure that they aren't too similar in
>>> appearance, given that is likely to range from 2-20 say.
>>>
>>> Any help much appreciated,
>>>
>>> Adam

>> I think I should have said I obviously know how to produce 3 random
>> numbers to plug into RGB, but I was looking for a more sensible
>> arrangement than this.

>
> I don't understand why you call it 'not sensible'
>
>> Also, I should have added I'm also looking to be able limit the range of
>> the colors as well. Say to avoid ever having black or white etc.

>
> You could generate a (pseudo)random number withing a
> specified range. See the C FAQ for details.
>
> If any undesired values fall inside a range, you can define
> several ranges, delimited by the undesired values, and randomly
> select a range before randomly selecting a value from it.
> If necessary you could also use the same approach to randomly select
> 'cells' or ranges of cells in your mesh.
>
> -Mike
>
>


However that isn't making any conditions that the n number of colors
created are differing in appearance. You can limit the range of the
random numbers for the creation of each R,G and B value, but that makes
no stipulation that a color maybe not be used because a similar one has
already been created.

Adam
 
Reply With Quote
 
Mike Wahler
Guest
Posts: n/a
 
      01-28-2006

"Adam Hartshorne" <> wrote in message
news:43dab25d$...
> Mike Wahler wrote:
>> "Adam Hartshorne" <> wrote in message
>> news:43daaa5f$...
>>> Adam Hartshorne wrote:
>>>> Hi All,
>>>>
>>>> I was wondering if somebody could post a few lines of code which would
>>>> produce random colors, which will be used in defining different regions
>>>> on a mesh. So in addition to having n random colors, I feel that there
>>>> should also be some condition to ensure that they aren't too similar in
>>>> appearance, given that is likely to range from 2-20 say.
>>>>
>>>> Any help much appreciated,
>>>>
>>>> Adam
>>> I think I should have said I obviously know how to produce 3 random
>>> numbers to plug into RGB, but I was looking for a more sensible
>>> arrangement than this.

>>
>> I don't understand why you call it 'not sensible'
>>
>>> Also, I should have added I'm also looking to be able limit the range of
>>> the colors as well. Say to avoid ever having black or white etc.

>>
>> You could generate a (pseudo)random number withing a
>> specified range. See the C FAQ for details.
>>
>> If any undesired values fall inside a range, you can define
>> several ranges, delimited by the undesired values, and randomly
>> select a range before randomly selecting a value from it.
>> If necessary you could also use the same approach to randomly select
>> 'cells' or ranges of cells in your mesh.
>>
>> -Mike
>>
>>

>
> However that isn't making any conditions that the n number of colors
> created are differing in appearance.


If the RGB values are different, the colors will be different.
Admittedly, the human eye cannot easily distinguish among
colors with very close values. BUT:

Again, you can impose your own restrictions upon the sets
of values you generate. E.g. delimit your ranges, such as:
make sure all red values are at least some distance (value)
apart. E.g. if your possible range is from 500 to 32000,
generate a random value between 5 and 320, and then multiply it
by 100. You could do this with any size factor you like
(e.g. 5,10, 32). Just remember if you want to include the
highest and lowest possible values in the set, use a factor
that divides it evenly. If you want to exclude the first
'x' values from the set, just use 'x' as the bottom of your
range. Use the same technique to exclude from the highest
'x' values.

All this isn't really a language issue, but of algorithms,
applicable in any language.

All I can say in closing is to try to be creative.

-Mike


 
Reply With Quote
 
Daniel T.
Guest
Posts: n/a
 
      01-28-2006
In article <43daa802$>,
Adam Hartshorne <> wrote:

> Hi All,
>
> I was wondering if somebody could post a few lines of code which would
> produce random colors, which will be used in defining different regions
> on a mesh. So in addition to having n random colors, I feel that there
> should also be some condition to ensure that they aren't too similar in
> appearance, given that is likely to range from 2-20 say.
>
> Any help much appreciated,


Create an array of 20 colors of your choice, making sure you can tell
the difference between them and none of them are black or white. Then
have the program randomly choose between them. QED.
 
Reply With Quote
 
Cy Edmunds
Guest
Posts: n/a
 
      01-28-2006

"Adam Hartshorne" <> wrote in message
news:43daa802$...
> Hi All,
>
> I was wondering if somebody could post a few lines of code which would
> produce random colors, which will be used in defining different regions on
> a mesh. So in addition to having n random colors, I feel that there should
> also be some condition to ensure that they aren't too similar in
> appearance, given that is likely to range from 2-20 say.
>
> Any help much appreciated,
>
> Adam


The problem you pose isn't trivial in general. The outline is this: starting
from RGB compute XYZ (based on some calibration you must know) and hence to
Lab space. Select a color difference formula such as CIE2000 and you can
then compute the difference in color between all pairs of patches. Now you
still need something like an annealing algorithm to maximize the minimum
color difference.

However, if you only expect to have 20 colors on screen at one time I would
just pick 20 colors from a palette using any decent image editor. That's a
whole lot more practical.


 
Reply With Quote
 
Cy Edmunds
Guest
Posts: n/a
 
      01-28-2006

"Cy Edmunds" <> wrote in message
newsCBCf.106454$.. .
>
> "Adam Hartshorne" <> wrote in message
> news:43daa802$...
>> Hi All,
>>
>> I was wondering if somebody could post a few lines of code which would
>> produce random colors, which will be used in defining different regions
>> on a mesh. So in addition to having n random colors, I feel that there
>> should also be some condition to ensure that they aren't too similar in
>> appearance, given that is likely to range from 2-20 say.
>>
>> Any help much appreciated,
>>
>> Adam

>
> The problem you pose isn't trivial in general. The outline is this:
> starting from RGB compute XYZ (based on some calibration you must know)
> and hence to Lab space. Select a color difference formula such as CIE2000
> and you can then compute the difference in color between all pairs of
> patches. Now you still need something like an annealing algorithm to
> maximize the minimum color difference.
>
> However, if you only expect to have 20 colors on screen at one time I
> would just pick 20 colors from a palette using any decent image editor.
> That's a whole lot more practical.
>


PS- You could Google for "named colors" to get some ideas. For instance:

http://www.echoecho.com/documentation_named_colors.htm


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Math.random() and Math.round(Math.random()) and Math.floor(Math.random()*2) VK Javascript 15 05-02-2010 03:43 PM
TreeNode colors come from anchor colors AAaron123 ASP .Net 1 08-07-2008 07:56 PM
random.random(), random not defined!? globalrev Python 4 04-20-2008 08:12 AM
Date in regional format in different regions Andrew Poulos Javascript 6 05-02-2005 09:31 PM
Playing Different Regions Unlimited Times. Patrick D. Rockwell DVD Video 2 06-27-2004 12:22 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57