On Sun, Jul 16, 2006 at 05:18:36PM -0600, Dave Smith wrote:
> How about something like this:
>
> In the header:
>
> int mMode;
> int mSkipper;
> float mRGBA;
> enum { Incrementing = 1, Decrementing = -1 };
>
> In the implementation (more or less):
>
> if( getId == selectedId )
> {
> if( ++mSkipper % 10 == 0 )
> {
> if( mRGBA > 10 )
> mMode = Decrementing;
> else if( mRGB < -10 )
> mMode = Incrementing;
>
> mRGBA += mMode;
> }
> }
>
>
> I probably missed lots of details here, but you get the point. Use an
> incrementer variable that is either -1 or +1, and just always add that
> value to the RGB intensity. Saves you some extra logic. Also note the
> use of mod (%) to check mSkipper for every 10th run instead of checking
> for equality with 10. This is the de facto standard way for doing
> something every Nth time, and you don't have to ever assign the
> variable, which is a fun hack. :)The problem with the modulus operator is that it implies a division, even if integer, which usually takes longer than a comparison. (Ah those old 6502 days.... :-). Of course, the OP may not care about performance. Best of all if you have the luxury of being able to pick your number of steps is to use an integer power of two; then you do a bitwise AND to mask off the surplus bits after every increment. > > By the way, I always use names (ie, enums) instead of bools to indicate > this kind of state (incrementing vs. decrementing) unless the state is > clearly a boolean type of state. Good idea. -- Charles Curley /"\ ASCII Ribbon Campaign Looking for fine software \ / Respect for open standards and/or writing? X No HTML/RTF in email http://www.charlescurley.com / \ No M$ Word docs in email Key fingerprint = CE5C 6645 A45A 64E4 94C0 809C FFF6 4C48 4ECD DFDB
pgp8bWRRQDgfw.pgp
Description: PGP signature
/* PLUG: http://plug.org, #utah on irc.freenode.net Unsubscribe: http://plug.org/mailman/options/plug Don't fear the penguin. */
