Hello
There is a hex function to convert decimal to hex - great
But what if we like to use functions that primarily use colours as decimals.
Like, How to work out a Decimal from Hex (RRGGBB) hex coding.
Here is my function
// Project: Hex2Int
// Created: Damo 2016-10-17
// show all errors
SetErrorMode(2)
width=1024: height=768
// set window properties
SetWindowTitle( "Hex2Int" )
SetWindowSize( width, height, 0 )
// set display properties
SetVirtualResolution( width, height )
SetOrientationAllowed( 1, 1, 1, 1 )
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
do
color=hex2dec("0000FF") // Blue
DrawEllipse(width/2, height/2,100,100,color,color,1)
DrawEllipse(random(0,width),random(0,height),50,50,hex2dec("FFAAAA"),hex2dec("FF0000"),1) //Red
DrawEllipse(random(0,width),random(0,height),50,50,hex2dec("FFFF00"),hex2dec("FFFF00"),1) //Yellow
DrawEllipse(random(0,width),random(0,height),50,50,hex2dec("FFFFFF"),hex2dec("FFFFFF"),1) //white
Sync()
loop
function hex2dec(colorinhex$ as string )
result as integer
result = 0
//loop through the string brought in and check each value in turn
for a=1 to len(colorinhex$)
// Grab a value in order of the string and work it out
value$=mid(colorinhex$, a, 1)
//Convert any A B C D E F to their correct base 16 value
if value$="A" or value$="a" then value$="10"
if value$="B" or value$="b" then value$="11"
if value$="C" or value$="c" then value$="12"
if value$="D" or value$="d" then value$="13"
if value$="E" or value$="e" then value$="14"
if value$="F" or value$="f" then value$="15"
// Calculate by * the value to the power of 16 of the current position
result=result+val(value$) * (16^(a-1))
next
// Return it back out to be able to use most AppGameKit functions..
// eg. DrawEllipse function uses pure decimal number for colours
endfunction result
Enjoy!
Thanks
Damo
Using Tier 1 AppGameKit V2
Started coding with AMOS