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 Professional Discussion / Using hex values for constants

Author
Message
Rich Dersheimer
AGK Developer
17
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 15th Jun 2011 03:54 Edited at: 15th Jun 2011 04:44
A while back, there was some discussion about using constants for color values. Like this...



and since a program would have to call the rgb() function each time the constant was used, it was deemed to be sub-optimal. (Over the course of a 10,000 iteration loop, it seemed to add about 50ms to the loop time, in my rudimentary test)

But what about using a hex value? Like this...



or even the DWORD value



These don't add any extra delay, since the value is just substituted, instead of being calculated.

I prefer using the hex values for two reasons. First, I can see the alpha channel. The alpha channel is useful when drawing with the commands in IanM's matrix utils, the Advanced 2D plugin, and some other plugins.

Second, I'm just used to using hex values for colors, from web design work.

Any thoughts?

EDIT: I've attached a colorpicker program I use when I'm searching for that perfect shade of whatever.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 16th Jun 2011 01:44
Quote: "Any thoughts?"


I think you've answered your own question.

As you say, it would usually be faster to process a constant (a dword in this case) rather than a function call which has to reconstruct the same dword each time. The downside is readability and inflexibility. How would you use hex in place of



where "blue" is a variable that might change?

DBPro constants, as defined by #constant, are not constants in the usual sense at all - they are simply convenient abbreviations for a bit of DBPro code (but are often used to represent actual constants in the program - but that is the programmer's choice).

Login to post a reply

Server time is: 2026-07-10 22:54:44
Your offset time is: 2026-07-10 22:54:44