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