Question Function to Return a Color

r3plica

Well-known member
Joined
Mar 4, 2010
Messages
86
Programming Experience
3-5
Can anyone help me.
I want to create a function that accepts a number as a parameter.
That function should then look at a list of colors (system.drawing.color) and return the specified one.
I would like to the list to have a max of 24 colors and the color to follow a color scheme (in this case all the colors should be dark and get darker from the first one onwards).

cheers in advance.
If you need more info, let me know.
 
This sort of works, but I need all colors (no starting at red) as I have 24 and the shades are too close together.

VB.NET:
Private Const ONE_SIXTH As Double = 0.166666666666667R
    Private Const ONE_THIRD As Double = 0.333333333333333R
    Private Const TWO_THIRDS As Double = 0.666666666666667R
    Private Const FIVE_SIXTHS As Double = 0.833333333333333R
    Private Shared Function WheelColor(ByVal d As Double) As Color
        If (d < 0.0R) OrElse (d > 1.0R) Then
            Throw New ArgumentOutOfRangeException("d", d, "d must be between 0.0 and 1.0, inclusive")
        End If
        Dim R As Double = 1
        Dim G As Double = 1
        Dim B As Double = 1
        If d < ONE_SIXTH Then
            G = d / ONE_SIXTH
            B = 0
        ElseIf d < ONE_THIRD Then
            R = 1 - ((d - ONE_SIXTH) / ONE_SIXTH)
            B = 0
        ElseIf d < 0.5 Then
            R = 0
            B = (d - ONE_THIRD) / ONE_SIXTH
        ElseIf d < TWO_THIRDS Then
            R = 0
            G = 1 - ((d - 0.5) / ONE_SIXTH)
        ElseIf d < FIVE_SIXTHS Then
            R = (d - TWO_THIRDS) / ONE_SIXTH
            G = 0
        Else
            B = 1 - ((d - FIVE_SIXTHS) / ONE_SIXTH)
            G = 0
        End If
        Return Color.FromArgb(CInt((R * 255)), CInt((G * 255)), CInt((B * 255)))
    End Function
 

Latest posts

Back
Top