realbasic-games
[Top] [All Lists]

Selecting Colors

To: REALbasic Games <REALbasic-Games at lists dot realsoftware dot com>
Subject: Selecting Colors
From: Chris Malumphy <cmalumphy at earthlink dot net>
Date: Sun, 30 May 2004 08:56:39 -0400
Cc:
Delivered-to: REALbasic-Games at lists dot realsoftware dot com
List-help: <mailto:realbasic-games-request@lists.realsoftware.com?subject=help>
List-id: REALbasic Games <realbasic-games.lists.realsoftware.com>
List-post: <mailto:realbasic-games@lists.realsoftware.com>
I'm making a game where I need to randomly select 5 discernably
different colors for each round of play. It would be nice if the range
of colors was as wide as possible, although it would also be nice if the
combination of the 5 selected colors was at least somewhat attractive.
The game will randomly fill small hexagons or rectangles with these
colors.

To get the widest range of colors I currently use:

 for i = 1 to 5
    mycolor(i) = rgb(rnd * 255, rnd * 255, rnd * 255)
    crect(i - 1).fillcolor = mycolor(i)
  next

But this means one color could be selected twice, and that two or more
colors might be so similar that they are not readily discernable from
each other.

I have also experimented with something like:

 for i = 1 to 5
    unique = false
    while unique = false
      mycolor(i) = rgb(rnd * 255, rnd * 255, rnd * 255)
      crect(i - 1).fillcolor = mycolor(i)
      unique = true
      for j = 0 to i - 1
        if mycolor(j) = mycolor(i) then
          unique = false
          exit
        end
      next
    wend
  next

Which eliminates duplicates but still leaves some colors looking too
similar to others.

In that last section of code I've also experimented with changing the
color creation section to something like

      n1 = rnd * 18
      n2 = rnd * 18
      n3 = rnd * 18
      mycolor(i) = rgb(n1 * 17, n2 * 17, n3 * 17)

which seems to help ensure the colors are more discernable, but limits
the range of possible colors.

Does anyone have any tips on how to select my random colors better?




_______________________________________________
Unsubscribe or switch delivery mode:
<http://support.realsoftware.com/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

<Prev in Thread] Current Thread [Next in Thread>