473,800 Members | 2,696 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Random Colors For Use In Defining Different Regions

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
Jan 27 '06 #1
12 3100
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
Jan 27 '06 #2
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
Jan 27 '06 #3
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
Jan 27 '06 #4

"Adam Hartshorne" <ad**@dcs.warwi ck.ac.uk> wrote in message
news:43******** **@mk-nntp-2.news.uk.tisca li.com...
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
Jan 27 '06 #5
Mike Wahler wrote:
"Adam Hartshorne" <ad**@dcs.warwi ck.ac.uk> wrote in message
news:43******** **@mk-nntp-2.news.uk.tisca li.com...
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
Jan 28 '06 #6

"Adam Hartshorne" <ad**@dcs.warwi ck.ac.uk> wrote in message
news:43******** **@mk-nntp-2.news.uk.tisca li.com...
Mike Wahler wrote:
"Adam Hartshorne" <ad**@dcs.warwi ck.ac.uk> wrote in message
news:43******** **@mk-nntp-2.news.uk.tisca li.com...
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
Jan 28 '06 #7
In article <43**********@m k-nntp-2.news.uk.tisca li.com>,
Adam Hartshorne <ad**@dcs.warwi ck.ac.uk> 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.
Jan 28 '06 #8

"Adam Hartshorne" <ad**@dcs.warwi ck.ac.uk> wrote in message
news:43******** **@mk-nntp-2.news.uk.tisca li.com...
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. :)
Jan 28 '06 #9

"Cy Edmunds" <sp************ ***@rochester.r r.com> wrote in message
news:DC******** ************@tw ister.nyroc.rr. com...

"Adam Hartshorne" <ad**@dcs.warwi ck.ac.uk> wrote in message
news:43******** **@mk-nntp-2.news.uk.tisca li.com...
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
Jan 28 '06 #10

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

Similar topics

10
2508
by: Virus | last post by:
Ok well what I am trying to do is have 1.) the background color to change randomly with 5 different colors.(change on page load) 2,) 10 different quotes randomly fadeing in and out in random spots on the webpage. with a delay timer on them, so they keep changing as the page is open. Not random each time the page is loaded. If anyone can help it would be greatly appreaciated, I have tried many of
23
4209
by: Thomas Mlynarczyk | last post by:
I remember there is a programming language where you can initialize the random number generator, so that it can - if you want - give you the exactly same sequence of random numbers every time you initialize it with the same parameter. Can this be done with JavaScript? I couldn't find anything in the documentation. Basically, what I want to achieve is to obtain always the same sequence of random numbers for the same given initialization...
1
426
by: Job Lot | last post by:
how to genrate random colors without repeat of the same color or color code. I am creating a line graph using ComponentOne Chart control and what to show series with different colors. thanx
14
4925
by: Debbie Lucier | last post by:
How would I generate a even random number each time? I can generate a random number each time but not an even one? Here is the code I use for the random number from 1-100. <script type="text/javascript"> no=math.random()*100 document.write (math.round(no)) </script>
6
6161
by: Danny Lesandrini | last post by:
I'm using an Access database to drive a web site and the colors of various table backgrounds are stored in Access. I want users of the Access database to be able to select colors for the site, but my mappings between named colors, HEX values and the Long Integer values used in Access are not jibbing. Anyone have a nice list laying around? Danny J Lesandrini dlesandrini@hotmail.com
11
2263
by: Paul Smith | last post by:
I have a button on my web page the backcolor of which I want to change: btnSample.backcolor = ???????? I want the color to be Gainsboro However I enter Gainsboro or color.Gainsboro I have the blue wavy line indicating an error. Help!
5
2085
by: jar13861 | last post by:
I'm confused on how to write a random array that will only generate 9 different numbers from 1-9. Here is what I have, but its only writing one number.... holder = new Array ( 9 ); var flag = true; var rannum = Math.floor( 1 + Math.random() * 9 ); for (var j = 0; j < 9; j++) {
1
1879
by: Demi | last post by:
I want to be able to define standard colors in a base form, then have child forms use those values instead of standard colors. Ex in my base form I want to do this: Color myColor = System.Drawing.SystemColors.Control; Then in my child form in the designer, I want to be able to enter "myColor" in the BackColor property.
0
913
by: sweatha | last post by:
Hi Friends I have designed a form with a label box named 'Label30' and text box named 'TextBox21'. Then I have generated the random number in the label box using the coding in form load event as Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here str = "user id=sa;password=;data source=AURO-RA4;initial...
0
9691
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10507
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10279
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10036
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9092
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6815
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5473
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3765
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2948
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.