Page 1 of 1

48 x Color, not Gradient

Posted: Sat Nov 21, 2020 8:26 am
by AUGE_OHR
hi,

i like to set Backcolor 48 Label "like Gradient" ...
1st Label should be YELLOW and 48st Label BLUE so other Label should have Color between
how :idea:

---

how to convert this HEX Color to RGB :?:

Code: Select all

0x01800000

Re: 48 x Color, not Gradient

Posted: Sat Nov 21, 2020 8:57 am
by mol
Some years ago Grigori Filatov posted sample with colored grid in this way. Try to search, maybe it will help you

Re: 48 x Color, not Gradient

Posted: Sat Nov 21, 2020 10:34 am
by Rathinagiri
Say we have R1, G1, B1 as the first color and R2, G2, B2 as the second Color.

DiffR = ( R2-R1)/48
DiffG = (G2-G1)/48
DiffB = (B2-B1)/48

For every cell you can increment this DiffRGB.

Just an idea. :)

Re: 48 x Color, not Gradient

Posted: Sat Nov 21, 2020 10:36 am
by Rathinagiri

Re: 48 x Color, not Gradient

Posted: Sat Nov 21, 2020 10:39 am
by bpd2000
Visit
C:\MiniGUI\SAMPLES\Applications\RGBMixer

Re: 48 x Color, not Gradient

Posted: Sat Nov 21, 2020 6:30 pm
by gfilatov
AUGE_OHR wrote:
Sat Nov 21, 2020 8:26 am
hi,

i like to set Backcolor 48 Label "like Gradient" ...
1st Label should be YELLOW and 48st Label BLUE so other Label should have Color between
how :idea:
Hi Jimmy,

Please take a look for the sample code below (it is for MiniguiEX, of course). :arrow:

Code: Select all

/*
 * MINIGUI - Harbour Win32 GUI library Demo
 *
 * (c) 2020 Grigory Filatov <gfilatov@inbox.ru>
 */

#include "hmg.ch"

STATIC nLabelObj := 1


FUNCTION MAIN

   LOCAL y, x, cSymbol, pos, h := 16
   LOCAL aDummy := Array( 48 )

   LOCAL ColorBegin := HMG_RGB2n( YELLOW )
   LOCAL ColorEnd := HMG_RGB2n( BLUE )

   DEFINE WINDOW Form_1 ;
         WIDTH 400 ;
         HEIGHT 840 ;
         TITLE '48 Colors Demo' ;
         MAIN

      y := 20
      x := 10

      FOR EACH cSymbol IN aDummy
         pos := hb_enumindex( cSymbol )
         @ y, x LABEL ( 'Lbl_' + hb_ntos( nLabelObj++ ) ) WIDTH 360 HEIGHT h ;
            VALUE pos CENTERALIGN VCENTERALIGN ;
            FONTCOLOR HMG_n2RGB( GradientColor( HMG_RGB2n( BLACK ), HMG_RGB2n( WHITE ), 1, 48, Pos ) ) ;
            BACKCOLOR HMG_n2RGB( GradientColor( ColorBegin, ColorEnd, 1, 48, Pos ) )

         y += h
      NEXT
   END WINDOW

   CENTER WINDOW Form_1

   ACTIVATE WINDOW Form_1

RETURN NIL

*------------------------------------------------------------------------------*
STATIC FUNCTION GradientColor( ColorBegin, ColorEnd, AMin, AMax, APosition )
*------------------------------------------------------------------------------*
   LOCAL B
   LOCAL B1, B2, B3
   LOCAL E
   LOCAL E1, E2, E3
   LOCAL P

   B := COLORREF_TO_ArrayRGB( ColorBegin )

   B1 := B[ 1 ]
   B2 := B[ 2 ]
   B3 := B[ 3 ]

   E := COLORREF_TO_ArrayRGB( ColorEnd )

   E1 := E[ 1 ]
   E2 := E[ 2 ]
   E3 := E[ 3 ]

   IF AMax - AMin <> 0
      P := ( APosition - AMin ) / ( AMax - AMin )
   ELSE
      P := 0
   ENDIF

RETURN B1 + Round( ( E1 - B1 ) * P, 0 ) + hb_bitShift( B2 + Round( ( E2 - B2 ) * P, 0 ), 8 ) + hb_bitShift( B3 + Round( ( E3 - B3 ) * P, 0 ), 16 )

The result screen is showed below:
capture.jpg
capture.jpg (25.43 KiB) Viewed 453 times
Hope that useful :idea: