Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / RGB to HEX converter! but I need help

Author
Message
Lukas W
21
Years of Service
User Offline
Joined: 5th Sep 2003
Location: Sweden
Posted: 26th Jan 2005 17:05
This is a RGB to HEX and HEX to RGB converter written in DBC.
There are some issues thou... like i cant figure out a way to do HEX to RGB convertion.. if anyone could help or would try here is the code I got so far Thanks in advance



MDTalley
20
Years of Service
User Offline
Joined: 13th Jan 2005
Location: Mobile, AL
Posted: 27th Jan 2005 06:41
This is very easy to do in a language that has a Substring function. Have you thought about using a DLL program to do this? I think I have one somewhere.
Kevin Picone
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 27th Jan 2005 07:36 Edited at: 27th Jan 2005 07:39
Try this..

Note: this is actually PlayBasic code, but it should also compile with DB/DBPRO. Although you may have to alter a few things.. I.e. From memory the MID$() function in DB doesn't have a 3rd length parameter.

so this line

ThisChr=asc(mid$(h$,lp,1))

will probably need to be changed to

ThisChr=asc(mid$(h$,lp))





Kevin Picone
[url]www.underwaredesign.com[/url]
Play Nice! Play Basic - Next Generation Basic (Release V1.05 Out Now)
Lukas W
21
Years of Service
User Offline
Joined: 5th Sep 2003
Location: Sweden
Posted: 27th Jan 2005 15:43 Edited at: 27th Jan 2005 16:16
thanks, much apperciated I will have a look at this and see where it'll bring me

<EDIT>

@mdtalley
i have Dev-C++ but I have no idea how to code in that..

okay, the code works BUT there are still some issues: the HEX to RGB is not very accurate...



I will have a play with this anyway try to figure it out myself, but id be happy for more help

Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 28th Jan 2005 02:37 Edited at: 28th Jan 2005 03:11
I think some of your hex values are wrong. 10 should just be A, not 0A. I don't think you should have leading zeros. Dont really know if that'd make a difference or not. You could do the conversion by hand. Easiest way is to convert the hex into binary first. Each hex digit represents a 4bit binary number. The final binary number is all the parts put together. A binary to decimal converter would be pretty easy.



binary to decimal converter. I'll try the hex in a minute.



If you pass this function a hex value in this form: 0xed (237)
And not as a string, this will work.

Figured this one out by accident. I'm surprised it works, but the str$() function automatically converts hex numbers into their decimal form.


"eureka" - Archimedes
Kevin Picone
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 28th Jan 2005 03:01
You don't been the conversion table at all..

ie.. this



only needs to be. Since DB/DBPRO/PB etc already have a value to HEX function built in.



Kevin Picone
[url]www.underwaredesign.com[/url]
Play Nice! Play Basic - Next Generation Basic (Release V1.05 Out Now)
Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 28th Jan 2005 03:05
Only thing with the hex$() is that it adds in all the leading zeros. I was trying to get rid of those by first converting it into a string, then realizing the automatic conversion.

"eureka" - Archimedes
Lukas W
21
Years of Service
User Offline
Joined: 5th Sep 2003
Location: Sweden
Posted: 28th Jan 2005 18:08 Edited at: 28th Jan 2005 18:09
Quote: "Since DB/DBPRO/PB etc already have a value to HEX function built in. "

man i did not know that thanks

<EDIT>

I dont know if the leading 0's is the problem or not, but I will take a closer look at this later today

Lost in Thought
21
Years of Service
User Offline
Joined: 4th Feb 2004
Location: U.S.A. : Douglas, Georgia
Posted: 28th Jan 2005 19:29 Edited at: 28th Jan 2005 19:29
I'm confused. Why go through the trouble to convert between rgb and hex. Why not just use rgb?

[edit] Whats an example of how you would use this?

Lukas W
21
Years of Service
User Offline
Joined: 5th Sep 2003
Location: Sweden
Posted: 28th Jan 2005 20:17
I thought this question would pop up sooner or later

actually i was trying to make a paint program and suddenly i got the idea to make a color chooser that displays hex and can convert between rgb and hex and visa versa.. I dont know what I would use this for but it would be like an extra feauture in something.

the paint program will be a part of my world editor, which will have the support of making textures and stuff. well, that is what i hope.

blanky
20
Years of Service
User Offline
Joined: 3rd Aug 2004
Location: ./
Posted: 28th Jan 2005 20:48
Useful for HTML (i.e., this website for example) where colours are stored as hex values with a leading #.

For example (mixture of CSS and HTML):

<body style="background-color: #000000">

Would give you a HTML page with a black background.

Avatar - white cat in a snowstorm. Look closely.
Lost in Thought
21
Years of Service
User Offline
Joined: 4th Feb 2004
Location: U.S.A. : Douglas, Georgia
Posted: 29th Jan 2005 22:48 Edited at: 1st Feb 2005 16:34
Well I guess I'll play around a bit. I don't have DBC yet though. Here is a version in DBP.



And here it is using the mouse to pick the color.



Lukas W
21
Years of Service
User Offline
Joined: 5th Sep 2003
Location: Sweden
Posted: 1st Feb 2005 16:01
thanks

but, (there is a but), how to i convert this into DBC code?

`since r_hex is 8bit convert first character to upper bits
temp1 = temp1 << 4

Lost in Thought
21
Years of Service
User Offline
Joined: 4th Feb 2004
Location: U.S.A. : Douglas, Georgia
Posted: 1st Feb 2005 16:23 Edited at: 1st Feb 2005 16:36
DBC doesn't have bit shift command! I'll look into it.

[edit] Does it even have BITWISE OPERATORS at all (&&,~~,||,..?

[edit2] Replace it with this



or



Lukas W
21
Years of Service
User Offline
Joined: 5th Sep 2003
Location: Sweden
Posted: 1st Feb 2005 17:08 Edited at: 1st Feb 2005 17:51
ahh, ok. I will test it out, but not now; im at school and im actually in class ill have a look at this later thou

that worked thanks mate.

Lost in Thought
21
Years of Service
User Offline
Joined: 4th Feb 2004
Location: U.S.A. : Douglas, Georgia
Posted: 1st Feb 2005 18:07
Glad you got it working.

Login to post a reply

Server time is: 2025-05-24 03:50:20
Your offset time is: 2025-05-24 03:50:20