June 14, 2024, 02:11:16 AM

## News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!

## Experimenting with colors I - Conversions

Started by Egil, August 11, 2016, 12:06:22 PM

0 Members and 1 Guest are viewing this topic.

#### Egil

##### August 11, 2016, 12:06:22 PM
I have told you about my young "assistants" before, and since school starts up again monday after summer leave, and the weather was rather lousy, we had a little "workshop" here today. This resulted in three programs, all demonstrating how to experiment with colors. And since I can't see that these ideas have ever been posted for CB before, here they are.

The first one is an idea that TexasPete once sent me in a PM. We had to modify it slightly to get it to work in CB. It converts RGB color values to decimal values and decimal values to RGB.

Have fun!

`'-------------------------------------------------------------------------------------' RGB_Ideas.CBA'-------------------------------------------------------------------------------------AutoDefine "Off"DECLARE RGBtoDec(red:int,green:int,blue:Int) as intDECLARE DecToRGB(decimal:int)def win:window  def dec,red,blue,green,run:int  Window win,-640,0,640,300,0,0,"    CB Skeleton Window",messages  ' Convert from RGB to integer value: dec = RGBtoDec(128,128,127) 'setwindowcolor win, dec :' In case you want to see the colour print win,"RGB(128,128,127) as decimal = ", dec' Convert from integer value to RGB: DecToRGB(dec) print" = RGB(",red,",",green,",",blue,")"run = 1  WAITUNTIL run = 0  CLOSEWINDOW win  END  'SUB messages()'----------------------------------------------------------------------------------------' Main Loop'----------------------------------------------------------------------------------------'SELECT @class CASE @idcreate  centerwindow win  CASE @idclosewindow  run = 0  CASE @IDKEYDOWN if GETKEYSTATE(0x1B) <> 0 then run = 0 :' ESC is pressed - end programENDSELECT  RETURN'SUB RGBtoDec(red:int,green:int,blue:Int) as int'----------------------------------------------------------------------------------------' Returns and RGB triplet as integer' Original idea: TexasPete'---------------------------------------------------------------------------------------- if blue > 0 then blue = blue * 65536 else blue =0 if green > 0 then green = green * 256 else green = 0RETURN blue + green + red'SUB DecToRGB(decimal:int)'----------------------------------------------------------------------------------------' Returns R G B Triplet from integer' Original idea: TexasPete' Please note  : Red,Green and Blue Must be Global and declared outside of this function'----------------------------------------------------------------------------------------def GetRed,GetGreen,GetBlue:int' GetRed :   blue=int(decimal/(256*256)) green=int((decimal-blue*256*256)/256)   GetRed= decimal-Blue*256*256-green*256' Getgreen:   blue=int(decimal/(256*256))   GetGreen=int((decimal-blue*256*256)/256)' GetBLue:   GetBlue=int(decimal/(256*256)) red=GetRed:green=GetGreen:blue=GetBlueRETURN `

Support Amateur Radio  -  Have a ham  for dinner!