is there a way I could use #000000 instead of 000,000,000 ..... for colors
Blitz3D Forums/Blitz3D Beginners Area/is there a way I could use #000000 instead of 000,000,000 ..... for colors
| ||
Is there a way I could use HTML color codes (example: #000000 is black) instead of using Color 0,0,0 it would be really useful and less long to figure out the colors........ |
| ||
Yes, write a function. Clr(#000000) |
| ||
Can you use a function in a function? How would I go about to do this function I'm clueless :| |
| ||
I think that #000000 Should be $000000 in blitz. |
| ||
This will work: Color $FF,$FF,$FF |
| ||
or this: color 0,0,rgb |
| ||
You should be able to make a function that does this. You should just have to pass in the code ( the #000000 thingy ) and use Left/Mid/Right to pull out the R G and B parts in the code. The you just convert them to decimal system using some of those functions, and your done! -Rich05 |
| ||
So far I got this...Function MGUI_clr( clr$) clr_red = "$" + Left$(clr$,3) clr_green = "$" + Mid$(clr$,-1) + Mid$(clr$,1) clr_blue = "$" + Right(clr$,-2) End Function But I got no idea how to get this function to return thoses for the "Color 0,0,0" in my other function... *thinking* |
| ||
MGUI_clr(FFFFFF)Function MGUI_clr( clr$) clr_red = "$" + Left$(clr$,3) clr_green = "$" + Mid$(clr$,-1) + Mid$(clr$,1) clr_blue = "$" + Right(clr$,-2) End Function Wheres my error? |
| ||
You can only return one variable from a function. Why don't you just set the color from within the function? Plus, your string functions are wrong. Did you read the documentation? Like: Mid$ (string$, offset, characters) string$ = any valid string offset = location within the string to start reading characters = how many characters to read frm the offset point So, to get the green value, something like Mid$(clr, 3, 2)... Then when you're done, "Color(clr_red, clr_green, clr_blue)" |
| ||
the only problem with html color codes is that they are in hexadecimal, i can't see a way to convert an hexadecimal string to a decimal value without anoter function that handle hexadecimal conversion... the a=$ff return 255 but a="$ff" don't work so i had to include hexadecimal conversion in the function ; usage : setcolor("rrggbb") ; setcolor("ff0000") for red ; setcolor("00ff00") for green ; setcolor("0000ff") for blue Function setcolor$(mycolor$) Hexa$="0123456789abcdef" red=((Instr(hexa$,Mid$(mycolor$,1,1),1)-1)*16)+((Instr(hexa$,Mid$(mycolor$,2,1),1)-1)) green=((Instr(hexa$,Mid$(mycolor$,3,1),1)-1)*16)+((Instr(hexa$,Mid$(mycolor$,4,1),1)-1)) blue=((Instr(hexa$,Mid$(mycolor$,5,1),1)-1)*16)+((Instr(hexa$,Mid$(mycolor$,6,1),1)-1)) Color red,green,blue End Function |
| ||
future enhancement! Eventually you want something more luxury, like: color red,green,blue,brightness# brightness# is a float between 0 (all black), 1 (normal) and 2++ (bright(er)) Handy for drawing 3d tiles (buttons etc.) .. you only need to adjust the brightness and all stuff is rgb customizable while the light/shadow remains! |
| ||
Na, tis easier than that.. Global fore1 = $5f5f5f Global fore1r = fore1 Shr 16 And $FF Global fore1g = fore1 Shr 8 And $FF Global fore1b = fore1 And $FF |
| ||
As rims said you can use a little trick: color 0,0,$FFFFFF or color 0,0,$58A2FF or whatever rgb color. this is the easiest way. save bytes, save plutonium. |
| ||
there is code for this in the code archives already. It includes functions for putting RGB values into an integer, as well as extracting RG&B components from the integer. |
| ||
maybe my code below can be of help somehow .. dunnoFunction print_debug_info() totalDrivers%=CountGfxDrivers() r_dec%=0 : g_dec%=0 : b_dec%=0 r_hex$=0 : g_hex$=0 : b_hex$=0 r_dec=ColorRed() : g_dec=ColorGreen() : b_dec=ColorBlue() r_hex=Hex$(r_dec) : g_Hex=Hex$(g_dec) : b_Hex=Hex$(b_dec) Cls Print "Date : " + CurrentDate() Print "Time : " + CurrentTime() Print "PlayField Width : " + GraphicsWidth() Print "PlayField Height : " + GraphicsHeight() Print "PlayField Depth : " + GraphicsDepth() Print "PlayField Memory : " + GraphicsBuffer() Print "PlayField Drawing Color (DEC) : " + r_dec + " " + g_dec + " " + b_dec Print "PlayField Drawing Color (HEX) : " + Right$(r_hex,2) + " " + Right$(g_hex,2) + " " + Right$(b_Hex,2) Select JoyType() Case 0 Print "Joystick : None" Case 1 Print "Joystick : Digital" Case 2 Print "Joystick : Analog" End Select For t = 1 To totalDrivers Print "Installed GFX driver(s) : " + GfxDriverName$(t) Next Print "Total GFX memory on card : " + TotalVidMem() + " " + "(Bytes)" + " " + (TotalVidMem() / 1024) + " " + "(Mb)" Print "Avail GFX memory : " + AvailVidMem() + " " + "(Bytes)" + " " + (AvailVidMem() / 1024) + " " + "(Mb)" Print "Operating system installed : " + SystemProperty("OS") Print "CPU installed : " + SystemProperty("CPU") End Function |