realbasic-games
[Top] [All Lists]

Re: Selecting Colors

To: Jonathan Johnson <jonj at realsoftware dot com>, REALbasic Games <REALbasic-Games at lists dot realsoftware dot com>
Subject: Re: Selecting Colors
From: Chris Malumphy <cmalumphy at earthlink dot net>
Date: Sun, 30 May 2004 21:12:52 -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>
References: <40B9DA07 dot 34617579 at earthlink dot net> <0832E518-B23C-11D8-B45A-000A959DF1D2 at realsoftware dot com>
Thanks. Your code seems to do the trick pretty well. I've never really
taken a look at, or understood, hsv before. In my application, clashing
colors are fine. Sometimes they even add a certain "ambiance" to my board.

Jonathan Johnson wrote:

> On May 30, 2004, at 7:56 AM, Chris Malumphy wrote:
>
> > 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.
>
> Here's something I just whipped up:
>
>    dim c() as Color
>    dim i,j as integer
>    dim newColor as Color
>    dim rand as new Random
>    dim isUnique as Boolean
>
>    CONST NumColors = 5
>    CONST Tolerance = .10
>
>    for i = 0 to NumColors - 1
>      while true
>        newColor =
> rgb(rand.InRange(0,255),rand.InRange(0,255),rand.InRange(0,255))
>
>        isUnique = true
>
>        for j = 0 to ubound(c)
>          if abs(newColor.hue - c(j).hue) < Tolerance or _
>              abs(newColor.saturation - c(j).saturation) < Tolerance or _
>              abs(newColor.value - c(j).value) < Tolerance then
>            isUnique = false
>          end if
>        next
>
>        if isUnique then
>          c.Append newColor
>          exit
>        end if
>      wend
>    next
>
> You can tweak Tolerance a bit, but .1 seems pretty good. I'm comparing
> HSV values because what really distinguishes a color isn't the amount
> of Red that changed, but rather if the Hue, Saturation, or Value
> changed.
>
> However, this code does not notice if colors are clashing colors. I'm
> not even sure how to approach that problem ;)
>
> Good luck and HTH,
> Jon
>
> --
> Jonathan Johnson
> Testing Department
> REAL Software, Inc.

_______________________________________________
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>