# RGB code to HEX conversion code, need to speed it up!

• elibol
• Novice
• Joined: Feb 19, 2004
• Posts: 29
• Status: Offline

February 20th, 2004, 5:45 pm

well, i was kind of asking a combination of those... thanks though man... u know of any tutorial or documentation that i could absorb some bitwise related info?
• Anonymous
• Bot
• Joined: 25 Feb 2008
• Posts: ?
• Loc: Ozzuland
• Status: Online

February 20th, 2004, 5:45 pm

• lostinbeta
• Guru
• Joined: Jun 26, 2003
• Posts: 1402
• Status: Offline

February 20th, 2004, 7:58 pm

Well I can't really think of an "efficient" way to code this... However I have seen a gradient-esque method from Keith Peters (Bit-101) and it goes a little something like this... (changing the for loop in the current code)
Code: [ Select ]
for (var i = 1; i<=500; i++) {
red = Math.sin(ra += .03)*127+128;
green = Math.sin(rb += .02)*127+128;
blue = Math.sin(rc += .01)*127+128;
myCol = red << 16 | green << 8 | blue;
attachMovie('colorme', 'colorme'+i, i, {_y:0, _x:i});
mcColor = new Color(this['colorme'+i]);
mcColor.setRGB(myCol);
}
1. for (var i = 1; i<=500; i++) {
2.     red = Math.sin(ra += .03)*127+128;
3.     green = Math.sin(rb += .02)*127+128;
4.     blue = Math.sin(rc += .01)*127+128;
5.     myCol = red << 16 | green << 8 | blue;
6.     attachMovie('colorme', 'colorme'+i, i, {_y:0, _x:i});
7.     mcColor = new Color(this['colorme'+i]);
8.     mcColor.setRGB(myCol);
9. }

But the gradient fade doesn't come out the same. I don't know if you play around with it if perhaps you will get similar results or not.
• elibol
• Novice
• Joined: Feb 19, 2004
• Posts: 29
• Status: Offline

February 21st, 2004, 3:08 am

ok, well the reason "efficiency" is so important is because there are is alot of code weighing down what i want to be doing in the first place. so please...

hmm, the ra, rb, and rc variables are defined within the expression?

i thought i should mention, isnt it annoying that you cannot define variables in expressions in AS2.0 ? so annoying... but there is a way around this when using for loops...

the less the amount of defined variables, the higher the efficiency. furthermore the only reason variables should be used is if you will be working with what is going on in the variable, which in this case is irrelevant since this is an algorithm we're working with variables and functions should be kept at a minimal...

the reason im saying this is i felt you didnt see it necessary to bother with efficiency...

the more efficient my algorithms are, the more i can do with my code.

here it is refined:
Code: [ Select ]
for (var i=1, ra=0,rb=0,rc=0; i<=500; i++) {
attachMovie('colorme', 'colorme'+i, i, {_y:0, _x:i});
mcColor = new Color(this['colorme'+i]);
mcColor.setRGB((Math.sin(ra += .03)*127+128) << 16 | (Math.sin(rb += .02)*127+128) << 8 | (Math.sin(rc += .01)*127+128));
}
1. for (var i=1, ra=0,rb=0,rc=0; i<=500; i++) {
2. attachMovie('colorme', 'colorme'+i, i, {_y:0, _x:i});
3. mcColor = new Color(this['colorme'+i]);
4. mcColor.setRGB((Math.sin(ra += .03)*127+128) << 16 | (Math.sin(rb += .02)*127+128) << 8 | (Math.sin(rc += .01)*127+128));
5. }

cool gradient... thanks man i will mess around with this =]

incase your interested in the things i wish to color->
http://huseyin.kicks-ass.net/htdocs/spacewarpdeus.html

there is an index of other stuff here ->
http://huseyin.kicks-ass.net/htdocs/
• elibol
• Novice
• Joined: Feb 19, 2004
• Posts: 29
• Status: Offline

February 21st, 2004, 5:54 am

i looked around but i couldnt find jack that explained how i could implement my own incrementation ratio based on some maximum range...

if u know of any i'd like the hook up =]
tnx
• lostinbeta
• Guru
• Joined: Jun 26, 2003
• Posts: 1402
• Status: Offline

February 21st, 2004, 8:10 pm

Oh, I definitely think efficiency is always something important to include in code... I was just saying that I personally have no clue how to make your current code more efficient.

And I have never used AS2.0 (still a Flash MXer), so I have no idea about the variables in expressions dealy.

Excellent stuff on your site btw :thumb:

## Post Information

• Total Posts in this topic: 20 posts
• Users browsing this forum: No registered users and 31 guests
• You cannot post new topics in this forum
• You cannot reply to topics in this forum
• You cannot edit your posts in this forum
• You cannot delete your posts in this forum
• You cannot post attachments in this forum

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.