views:

104

answers:

3

i am controlling the hue and saturation of the backcolor of the form with scrollbars:

Private Sub tbHUE_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tbHue.Scroll
        Dim r, g, b As Integer
        HSVtoRGB(r, g, b, tbHue.Value, tbSaturation.Value / 50, 255)
        Form1.BackColor = Color.FromArgb(r, g, b)
        Label1.Text = tbHue.Value


    End Sub
    Private Sub tbsaturation_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tbSaturation.Scroll
        Dim r, g, b As Integer
        HSVtoRGB(r, g, b, tbHue.Value, tbSaturation.Value / 50, 255)
        Form1.BackColor = Color.FromArgb(r, g, b)
        Label2.Text = tbSaturation.Value
    End Sub

i would like to know what is the purpose of dividing by 50?

A: 

It's hard to know what the person was thinking that did that division, but the result is that you will get a color that's less "pure" (has more white mixed in).

For more info you may want to look at the conversion algorithm, which has good comments as well.

Eric J.
+3  A: 

If you're referring to this question: http://stackoverflow.com/questions/1048892/implementing-a-trackbar-that-will-change-background-color-of-form, the HSVtoRGB procedure expects:

  • a saturation value between 0.0 and 1.0
  • a value value between 0.0 and 1.0
  • a hue value between 0 and 360

This is in-line with the intent of the algorithm, as it points to the wikipedia version as its reference, at http://www.xtremevbtalk.com/showthread.php?t=302304. I didn't proofread the implementation to check for correctness though.

Dividing the saturation value you get from the tbSaturation textbox by 50 allows you to interpret values between 0 and 50 entered by the user. You might actually want to divide by 100 instead to allow a 0-100 range.

Oren Trutner
this is incorrect, the hue is not going over 360/50
I__
btw i want the range to reflect the actual range stated in colordialog which would be 0 to 240
I__
+1  A: 

That depends on the range of your scroll bars and the intended range of HSVtoRGB.

Without greater context, I'd assume that your scroll bars are ranged from 0 to 50 and that the code is attempting normalize the values or they're trying to scale the components.

plinth
the hue goes up to 360 without an error and the saturation up to 50 without an error
I__