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.

Code Snippets / [DBP] - ARGB() function. Set rgb with alpha.

Author
Message
zeroSlave
14
Years of Service
User Offline
Joined: 13th Jun 2009
Location: Springfield
Posted: 4th Jun 2012 23:02 Edited at: 8th Jun 2012 01:29
Was trying to change change the alpha when setting a color to text and didnt see an option in the internal commands. Came up with a quick and easy function. Works with objects also. Unfortunately, it doesn't work with 2D shape commands.

Here is a quick method for doing it from Mr Kohlenstoff that uses bitwise operators:


Here is the original using multipication:


Here it is in action:


Everybody is a genius. But if you judge a fish by its ability to climb a tree, it will live its whole life believing that it is stupid.
Mr Kohlenstoff
17
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Germany
Posted: 7th Jun 2012 20:38 Edited at: 7th Jun 2012 20:47
I thought using bitshift-operations instead of multiplications should run faster, but seemingly there is no significant difference:



Anyway. Given the fact that the argb-function won't be used too often probably and it should already be fast enough, I highly doubt that optimizations on this level have any noticable effect on a game or application at all. I did this test just out of curiousity, you know.


Edit:

Actually there is quite a difference. When reducing the overhead generated by the for-loop and variable-assignments, the difference gets more obvious and the function using bitwise-operators gets around ~30% faster (on my computer at least).



zeroSlave
14
Years of Service
User Offline
Joined: 13th Jun 2009
Location: Springfield
Posted: 8th Jun 2012 01:28
That's cool! I didn't even think about using bitwise operators in darkbasic like that. Thanks for testing it out. I went ahead and updated the first post with the function you wrote. Hope that's okay!

Everybody is a genius. But if you judge a fish by its ability to climb a tree, it will live its whole life believing that it is stupid.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 2nd Jul 2012 03:20
I use the bitwise method myself.

"You're not going crazy. You're going sane in a crazy world!" ~Tick

Login to post a reply

Server time is: 2024-04-24 22:35:34
Your offset time is: 2024-04-24 22:35:34