Color constants? 
Author Message
 Color constants?

Is there an easy way to define color constants, e.g., kRED? Now I use

Function kRED
     return RGB(255,0,0)
end function

which in my opinion is rather dramatic for a simple constant?

Boris



Sat, 25 Sep 2004 14:55:28 GMT  
 Color constants?

Quote:

> Is there an easy way to define color constants, e.g., kRED? Now I use

> Function kRED
>      return RGB(255,0,0)
> end function

> which in my opinion is rather dramatic for a simple constant?

What I do is define a module containing global properties like kRED.
Then I have an InitGlobals method, that does "kRed = RGB(255,0,0)" and
so on.  Just be sure to call InitGlobals early in your app's start-up
process, and you're all set.

True, these colors aren't truly constant, but that doesn't matter too
much... and they're pretty equivalent to true constants in terms of
performance (whereas your approach will be substantially slower).

HTH,
- Joe

--
,------------------------------------------------------------------.
|    Joseph J. Strout         Check out the Mac Web Directory:     |

`------------------------------------------------------------------'



Sat, 25 Sep 2004 22:14:16 GMT  
 Color constants?

Quote:


>> Is there an easy way to define color constants, e.g., kRED? Now I use
>> which in my opinion is rather dramatic for a simple constant?
> What I do is define a module containing global properties like kRED.
> Then I have an InitGlobals method, that does "kRed = RGB(255,0,0)" and
> so on. Just be sure to call InitGlobals early in your app's start-up
> process, and you're all set.
> True, these colors aren't truly constant, but that doesn't matter too
> much... and they're pretty equivalent to true constants in terms of
> performance (whereas your approach will be substantially slower).

It does clutter up the de{*filter*} though. A solution would be to choose
some variables as not displayed in the de{*filter*}.

--
Email Cleaner does convenient re-wrapping on badly wrapped emails and
newsgroup-posts. Badly wrapped lines is a problem every Internet User
comes across, Email Cleaner solves it! It also has many other features.

Email Cleaner works from inside all of your Mac programs, from one
button click.

<www.elfdata.com/emailcleaner/>



Sat, 25 Sep 2004 22:39:35 GMT  
 Color constants?

Quote:



> > Is there an easy way to define color constants, e.g., kRED? Now I use

> > Function kRED
> >      return RGB(255,0,0)
> > end function

> > which in my opinion is rather dramatic for a simple constant?

> What I do is define a module containing global properties like kRED.
> Then I have an InitGlobals method, that does "kRed = RGB(255,0,0)" and
> so on.  Just be sure to call InitGlobals early in your app's start-up
> process, and you're all set.

But what is the problem with using a variable?

dim blue as color
blue=rgb(214,250,255)

--
Groeten,
Roel Griffioen



Sun, 26 Sep 2004 06:35:07 GMT  
 Color constants?

Thanks for the answers,

I did approximately as below for all SVG colors (that is something like
170 or whatever). I edited all colorname=RGB(x,y,z) out of the
SVGdocumentation on the web and put them into a colorpicker module. It
was not much work (on a relative scale). I can now ask for a color by
name, find the svg-name or rgb-string of a color, and check whether a
color is one of the SVG colors or not.

Boris

Quote:
> What I do is define a module containing global properties like kRED.
> Then I have an InitGlobals method, that does "kRed = RGB(255,0,0)" and
> so on.  Just be sure to call InitGlobals early in your app's start-up
> process, and you're all set.



Sun, 26 Sep 2004 14:48:03 GMT  
 Color constants?

Quote:

>But what is the problem with using a variable?

Generally speaking, it's not a good idea to use variables for things that
really aren't variable. That is, if you have a a value that doesn't
change over the course of the program, and isn't determined on the fly by
user action, it's good programming practice to define that value in one
common place as a constant. Then you simply refer to that constant in the
program where needed.

This is the theory behind having and using resources, for example, rather
than "hard coding" all the values in the code itself. It facilitates UI
adjustments and localization. Plus, you don't have to search through all
your code to change every occurance of the hard-coded values--you just
change it in one spot, and you're all set.

 - Jeff



Mon, 27 Sep 2004 12:08:15 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. color constants?

2. mov [edi], constant vs mov [edi+4], constant

3. Usage Constant or other means of noting constants.

4. PGF90-S-0087-Non-constant expression where constant expression required

5. PGF90-S-0087-Non-constant expression where constant expression required

6. named constants vs. literal constants

7. Non-constant expression where constant expression required.

8. Setting a web hex color as background color for a canvas

9. conflicts between button colors and background color

10. RGB color to HTML color

11. Pulling color deffinitions from color palettes

12. How to get colors to print on a color printer

 

 
Powered by phpBB® Forum Software