Announcement

Collapse
No announcement yet.

Color definition

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Color definition

    Someone in this forum knows how to transform the RGB(x,y,z) color to a ...% needed for colordefinition ?

  • #2
    You mean "%" as in a 16 bits integer ?
    x, y, z are each 8 bits, that makes 24 bits ....

    The PB RGB() function returns a 32 bits long ...

    Kind regards
    Eddy

    Comment


    • #3
      Code:
      %MYCOLOR = RGB(myRed, mygreen, myblue)
      If that doesn't work (but I think it does)...try ...
      Code:
      %MYCOLOR =   &h00rrggbb
      .. that I have exactly zero faith that I have the bytes ordered correctly but you get the idea.

      If "%EQUATE= RGB(red, blue, green)" does not work, I know I have previously submitted a NFS to make it supported. BUt you can send it in too; the more who ask, the more likely the NFS will be adopted, or so they say.

      MCM
      Michael Mattias
      Tal Systems (retired)
      Port Washington WI USA
      [email protected]
      http://www.talsystems.com

      Comment


      • #4
        Or, you could just reverse-engineer these..
        Code:
        ' -------------------------------------------------
        '  MACROS TO GET R, G, B values from RGB dword
        ' -------------------------------------------------
        MACRO mGetRed   (Rgbvalue)  = Rgbvalue AND &h0FF
        MACRO mGetGreen (rgbvalue)  = (Rgbvalue AND &h0FF00)   \ &h100
        MACRO mGetBlue  (rgbvalue)  = (rgbvalue AND &h0FF0000) \ &h10000
        Michael Mattias
        Tal Systems (retired)
        Port Washington WI USA
        [email protected]
        http://www.talsystems.com

        Comment


        • #5
          color description

          Thanks both of you !
          I'll try.
          BTW another feature which is interesting to have is arctg2(y;x) instead of arctg(x) , which returns values between 0-2pi instead of ...

          Comment


          • #6
            Duh. This will ALWAYS work:

            Code:
            ' custom color for this application
            %MYRED       = 5
            %MYGREEN    = 110
            %MYBLUE      = 77
            MACRO MyColor = RGB(%MYRED, %MYGREEN, %MYBLUE) 
            ...
            
              hBrush = CreateSolidBrush (MyColor)


            That HAS to work.
            Michael Mattias
            Tal Systems (retired)
            Port Washington WI USA
            [email protected]
            http://www.talsystems.com

            Comment


            • #7
              Nuance...

              Comment


              • #8
                MCM was correct about using the &H0 method, but the order is wrong. I use this format: &H0bbggrr (where bb is the blue value in Hex format, gg=green, rr=red )

                Or if you just want something that can calc the value for you to hard code in to a program, I set this small tool up several years back (it is even kinda fun to watch and play with)

                http://www.powerbasic.com/support/pb...ad.php?t=23678

                There is also a handy button to copy the values to the clipboard so you can easily paste them in your programs.
                "I haven't lost my mind... its backed up on tape... I think??" :D

                Comment


                • #9
                  Frank,

                  I think you could use the following WinAPI macros, which retrieve intensity values for the blue, green and red components, respectively, of a 32-bit red, green, blue (RGB) value:

                  GetRValue
                  GetGValue
                  GetBValue

                  The values you obtain are in the range 0-255. Dividing by 255 and multiplying by 100 would give percentage.

                  Here is some more information on colors:

                  http://msdn2.microsoft.com/en-us/library/bb980062.aspx

                  Best regards,

                  Erik

                  Comment


                  • #10
                    Originally posted by Erik Christensen View Post
                    ... would give percentage.
                    Ah, he meant 'percentage' with '..%' ... I thought he meant a 16 bit integer variable by it .. :doh:
                    Eddy

                    Comment


                    • #11
                      Originally posted by Frank Kestens View Post
                      Thanks both of you !
                      I'll try.
                      BTW another feature which is interesting to have is arctg2(y;x) instead of arctg(x) , which returns values between 0-2pi instead of ...
                      Something like this ?

                      Code:
                      GLOBAL Pi AS DOUBLE, Pi_2 AS DOUBLE
                      ....
                      Pi = 4*ATN(1): Pi_2 = Pi/2
                      ....
                      FUNCTION ATN2 (YW AS DOUBLE, XW AS DOUBLE) AS DOUBLE
                          DIM ZZZ AS DOUBLE
                         SY&=SGN(YW): IF SY&=0 THEN SY&=1
                         IF XW = 0 THEN ZZZ = Pi_2 * SY& ELSE ZZZ = ATN(YW / XW)
                         IF XW < 0 THEN ZZZ = ZZZ + Pi * SY&
                         ATN2 = ZZZ
                      END FUNCTION
                      Aldo Vitagliano
                      alvitagl at unina it

                      Comment


                      • #12
                        Similar to the above I found this function in my previous 3D-Graphics Demonstration Program:

                        http://www.powerbasic.com/support/pb...ad.php?t=23341
                        Code:
                        FUNCTION CalculatePhi(EX AS SINGLE, EZ AS SINGLE) AS SINGLE
                            ‘ EX and EZ are X and Z coordinates, respectively
                            ' These corrections are needed to make Phi take a full
                            ' circle i.e. 360 degrees.
                            ' Without the corrections Phi will only vary 180 degrees
                            ' (-90 to 90) corresponding to the range for arcus tangens (ATN).
                            LOCAL Ph AS SINGLE
                            IF ABS(EX) < EZ*1E-36! THEN EX = EZ*1E-36!
                            Ph = ATN(EZ/EX)
                            IF Ph < 0! THEN Ph=Ph+3.141593!
                            IF EZ < 0! THEN Ph=Ph+3.141593!
                            FUNCTION = Ph
                        END FUNCTION
                        Is this useful to you?

                        Best regards,

                        Erik

                        Comment


                        • #13
                          Frank,
                          BTW another feature which is interesting to have is arctg2(y;x) instead of arctg(x) , which returns values between 0-2pi instead of ...
                          Check out this: http://www.powerbasic.com/support/pb...ead.php?t=8959

                          Paul.

                          Comment


                          • #14
                            Originally posted by Eddy Van Esch View Post
                            Ah, he meant 'percentage' with '..%' ... I thought he meant a 16 bit integer variable by it .. :doh:
                            How funny. I on the other hand, thought he is talking about defining a constant that he can use for anything in his program that needs a color definition. Such as: %MYCOLOR = &H03A475F
                            "I haven't lost my mind... its backed up on tape... I think??" :D

                            Comment


                            • #15
                              color and Arctan2

                              Thanks for the useful conversion formulae ...
                              ArcTan2 works fine .

                              Comment


                              • #16
                                color conversion

                                Originally posted by Eddy Van Esch View Post
                                You mean "%" as in a 16 bits integer ?
                                x, y, z are each 8 bits, that makes 24 bits ....

                                The PB RGB() function returns a 32 bits long ...

                                Kind regards
                                Ah ... I meant the colordefinition as in the HelpSection : DIALOG SET COLOR statement where predefined colors may be used as %BLACK ,
                                %WHITE ...
                                out of RGB(r%,g%,b%) values .

                                Comment


                                • #17
                                  Color definition

                                  Thanks for the codes here !
                                  I was able to convert the color definition in RGB using :
                                  color&=val("H0RRGGBB") , where RR...BB are the hexadecimal values.
                                  This can be used fi. in the Graphic Ellipse commands ...

                                  Comment

                                  Working...
                                  X