Results 1 to 9 of 9

Thread: Scrolling through Hue

  1. #1

    Thread Starter
    Hyperactive Member Frodo_Baggins's Avatar
    Join Date
    Feb 2004
    Location
    Sao Paulo, Brazil
    Posts
    397

    Scrolling through Hue

    Let's say I have an array of, say, 50 picture boxes.
    I want the first one to have a backcolor whose Hue is 0, the next to have a Hue of 1, and so forth. But since HSB and RGB are not perfectly interchangeable, how would I code this using a for-next loop?
    Ash Nazg durbatuluk, Ash Nazg gimbatul, Ash Nazg tharkathuluk, Agh barzum-ishi krimpatul.

  2. #2

    Thread Starter
    Hyperactive Member Frodo_Baggins's Avatar
    Join Date
    Feb 2004
    Location
    Sao Paulo, Brazil
    Posts
    397

    Re: Scrolling through Hue

    Well, in order to solve the problem I first decided to make a little converter from RGB to HSB. There are three textboxes and a command button. There are no errors, however the code does not return the correct values for Hue and Saturation based on the RGB values. What am I doing wrong?? (I found a mathematical operation on the web and adapted it... maybe something is wrong).

    Note: All variables dimmed as Single

    VB Code:
    1. Private Sub Command1_Click()
    2. R = Val(txtR.Text) / 255
    3. G = Val(txtG.Text) / 255
    4. B = Val(txtB.Text) / 255
    5. vMax = Max(R, G, B) 'Function that returns maximum of the three values
    6. vMin = Min(R, G, B) 'Function that returns minimum of the three values
    7. Delta = vMax - vMin
    8. If Delta = 0 Then
    9.     Hue = 0
    10.     Sat = 0
    11. Else
    12.     Sat = Delta / vMax
    13.     dR = (((vMax - R) / 6) + (Delta / 2)) / Delta
    14.     dG = (((vMax - G) / 6) + (Delta / 2)) / Delta
    15.     dB = (((vMax - B) / 6) + (Delta / 2)) / Delta
    16.     If R = vMax Then
    17.         Hue = dB - dG
    18.     ElseIf G = vMax Then
    19.         Hue = 1 / 3 + dR - dB
    20.     ElseIf B = vMax Then
    21.         Hue = 2 / 3 + dG - dR
    22.     End If
    23.     If Hue < 0 Then
    24.         Hue = Hue + 1
    25.     ElseIf Hue > 0 Then
    26.         Hue = Hue - 1
    27.     End If
    28. End If
    29. Hue = Hue * 180
    30. 'Ranges: -180<Hue<180
    31. '        0<Sat<1
    32. Debug.Print Hue
    33. Debug.Print Sat
    34. End Sub
    Ash Nazg durbatuluk, Ash Nazg gimbatul, Ash Nazg tharkathuluk, Agh barzum-ishi krimpatul.

  3. #3
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Scrolling through Hue

    Here's a program that does conversions. You can try it for free for 10 days.
    It will let you know if you are doing things correctly.

    http://www.google.com/url?sa=U&start...icker/&e=10431

  4. #4

    Thread Starter
    Hyperactive Member Frodo_Baggins's Avatar
    Join Date
    Feb 2004
    Location
    Sao Paulo, Brazil
    Posts
    397

    Re: Scrolling through Hue

    Quote Originally Posted by dglienna
    Here's a program that does conversions. You can try it for free for 10 days.
    It will let you know if you are doing things correctly.
    Well, I know that I'm doing them incorrectly
    The program can't help me.....
    Last edited by Frodo_Baggins; Jul 8th, 2005 at 06:25 PM.
    Ash Nazg durbatuluk, Ash Nazg gimbatul, Ash Nazg tharkathuluk, Agh barzum-ishi krimpatul.

  5. #5
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Scrolling through Hue

    Try this one. It gives you soure code.

    http://www.xbeat.net/vbspeed/c_RGBToHSL.htm

  6. #6

    Thread Starter
    Hyperactive Member Frodo_Baggins's Avatar
    Join Date
    Feb 2004
    Location
    Sao Paulo, Brazil
    Posts
    397

    Re: Scrolling through Hue

    Quote Originally Posted by dglienna
    Try this one. It gives you soure code.

    http://www.xbeat.net/vbspeed/c_RGBToHSL.htm
    I'll check it out... thanks
    Ash Nazg durbatuluk, Ash Nazg gimbatul, Ash Nazg tharkathuluk, Agh barzum-ishi krimpatul.

  7. #7

    Thread Starter
    Hyperactive Member Frodo_Baggins's Avatar
    Join Date
    Feb 2004
    Location
    Sao Paulo, Brazil
    Posts
    397

    Re: Scrolling through Hue

    Hum, it seems to be exactly what I need... Thanks, dglienna
    Ash Nazg durbatuluk, Ash Nazg gimbatul, Ash Nazg tharkathuluk, Agh barzum-ishi krimpatul.

  8. #8

    Thread Starter
    Hyperactive Member Frodo_Baggins's Avatar
    Join Date
    Feb 2004
    Location
    Sao Paulo, Brazil
    Posts
    397

    Re: Scrolling through Hue

    Alright! Coded...
    If anybody's interested, the code for "scrolling through hue" is attached.
    Attached Files Attached Files
    Ash Nazg durbatuluk, Ash Nazg gimbatul, Ash Nazg tharkathuluk, Agh barzum-ishi krimpatul.

  9. #9
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Scrolling through Hue

    I thought I had that before, but couldn't find it. Glad things worked out.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width