Results 1 to 10 of 10

Thread: They dont listen to me too :(

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2000
    Posts
    92

    Unhappy

    In the general forum got nno answer hope you can really help me out! (Desperate)

    Here i go:

    I'm writting a program that has a form with many random colors in a picture box!

    What i m trying to accomplish is to after the user clicks on a color the program tells wich color that is and if its light or dark color!

    Thing is there are millions of colors, so i would like to write a function to help me out!

    I thing that if i use the HSL i can know wich color it is but i dont know how since i couldn't find a proportion with the rgb values, like if Red > 100 and blue < 200 = something!

    I know how to get the long and convert it to RGB values but i'm looking to find a relation, see? U think HSL is a possible one?

    PLease give me some hints!

    Thanks!!!!

  2. #2
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    That's easy:

    Code:
    Sub ColorToRGB (ByVal Color As Long, R As Integer, G As Integer,  B As Integer)
    	R = Color Mod 256
    	Color = Color \ 256
    	G = Color Mod 256
    	Color = Color \ 256
    	B = Color Mod 256
    End Sub
    
    'Code improved by vBulletin Tool (Save as...)

  3. #3
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    After doing that, you could use....

    Function ISLIGHT(R,G,B) as Boolean
    Const MaxCapac=255+255+255

    If R+G+B<=Int(MaxCapac/2)

    End Function
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jul 2000
    Posts
    92
    I swear i looked at this 2 codes for a long lonng time and i'm even afraid to ask cause of my ignorance but i didn't understand the "logic" i guess thats the word of both helps you gave!

    I'm very sorry, please be more accurate and explain

    Thankx for trying to help though!

  5. #5
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628
    ok they are assuming that you know how to get the pixel color under the cursor.
    You take a long color value ok?
    It is combined of 4 bytes. Each byte represents these 4 things:
    byte 1: unused
    byte 2: blue portion of color in the value range of 0-255
    byte 3: green portion in range of 0-255
    byte 4: red portion in range of 0-255

    The first code posted is used to get the red, green, and blue portions of the color from the long value with math tricks.

    The 2nd code works like similar to this one:
    Brightnessofcolor = int((red+green+blue) / 3)
    which will return a number in the range of 0 to 255.
    This is the brightness of the color. It should be pointed out however that the green portion of the color is actually about 2x the brightness of the red and blue part. So your reading would have to take that into account if you wanted proper brightness checking.
    perhaps this code:
    Brightnessofcolor = int((red + green + green + blue) / 4)
    A suitable mod could be made for blue as well, since in my opinion blue is darker than red. Im not bsing about green being brighter either. The value of the green component for standard green is 128. The value for the blue component for standard blue is 255.

    So after you get your brightness value, a simple matter to split it between light and dark:
    if Brightnessofcolor > 128 then
    msgbox "bright!"
    else
    msgbox "dark!"
    end if


    I never saw you post in the general forum...
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  6. #6
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Hey, ya cant blame me for having a 5 second post

    Happy Coding!
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jul 2000
    Posts
    92
    That's great thanks, the light-dark matter is solved!

    By the way i use pset to get the long color, is it accurate?
    i'd like to try fox's example but if that sub is to try and find the R G B values hoow come its in a form of a sub,cause then i have to insert the R G B values before i know them?

    Humm not usest to this VB code about graphics!!!

    Now all i need is too find the same thing you guuys helped but to find out the color, meaning:

    Code:
    function DefineColor(R as integer, G as Integer, B as Interger) as string
    
    Select case RGB
    Case r =< 100 and g => 200 and b >50 
    'then use the brightnessof color function and define wich color it is
    If BrightnessOfColor > 128 Then
    MsgBox "bright!"
    Else
    MsgBox "dark!"
    End If
    definecolor is Light Yealow' for example of course
    case ....
    
    end select
    P.S. - I really would like to know the function to figure out the HSL from a RGB value

    P.S. 2 - I posted as Defining color
    Thanks a lot!!!!!!!
    Last edited by iScanning; Mar 17th, 2001 at 10:32 AM.

  8. #8
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Use API GetPixel and if you need SetPixelV. the V is important cause it is faster, since it doenst return the colour value.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Jul 2000
    Posts
    92
    Ok, i thinkk i havent made myself clear!

    My problem is not about getting the pixel as long or "translating" it to rgb, i want to write a function where i have a list of combinations of RGB values that will return the names: light BLUE, Dark Brown, see?

    But since there are millions of colors and i m certainly not gonna write: 1,1,1 = black , 1,2,2 = black and so on to every color that we know of. But anyways i think i can find a way to wrrite coode just as the brightness example if i know how can i find the HSL(Hue,Saturation...) from a RGB color! Can you guys tell me how?

    Because the rgb is very vague(dont know if it says like that in english) but it will be easy to me if i know the HSL since with the hue usually you can get the color, like: if hue =>0 and < 10 then color x, if hue >10 < and < 20 then color = y

    Thanks for the patience!!!

  10. #10
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628
    I should like to mention that i gave some slightly inaccurate data to you. I said that bit4 is unused. This isn't entirely true. If you use 32-bit graphics, the 4th byte is used to store alpha information.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

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