48 x Color, not Gradient

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
User avatar
AUGE_OHR
Posts: 1143
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany
Has thanked: 211 times
Been thanked: 303 times

48 x Color, not Gradient

Post 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
have fun
Jimmy

User avatar
mol
Posts: 3434
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Has thanked: 277 times
Been thanked: 176 times
Contact:

Post by mol »

Some years ago Grigori Filatov posted sample with colored grid in this way. Try to search, maybe it will help you

User avatar
Rathinagiri
Posts: 5351
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 211 times
Been thanked: 232 times
Contact:

Post 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. :)
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.

User avatar
Rathinagiri
Posts: 5351
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 211 times
Been thanked: 232 times
Contact:

Post by Rathinagiri »

East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.

User avatar
bpd2000
Posts: 1188
Joined: Sat Sep 10, 2011 4:07 am
Location: India
Has thanked: 277 times
Been thanked: 158 times

Post by bpd2000 »

Visit
C:\MiniGUI\SAMPLES\Applications\RGBMixer
BPD
Convert Dream into Reality through HMG

User avatar
gfilatov
Posts: 778
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Has thanked: 32 times
Been thanked: 449 times
Contact:

Post 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 262 times
Hope that useful :idea:
Kind Regards,
Grigory Filatov

"Everything should be made as simple as possible, but no simpler." Albert Einstein

Post Reply