A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Cycling Colors rbg

  1. #1
    Member
    Join Date
    May 2007
    Posts
    46

    Cycling Colors rbg

    Hi there,

    i was wondering if someone could help advise me to the best approach for this problem.

    I have an interactive thing thast leaves a lind trail but id like to cycle the colours depending on the percetage loaded.

    How can i start from

    r:0
    b:0
    g:0

    and ease through the colour spectrum until

    r:255;
    b:255;
    g:255;

    I tired a few things but i seem to just be getting grayscale.

    Apprecite your time.

    Ronson.

  2. #2
    Member
    Join Date
    May 2007
    Posts
    35
    You can't do that within the RGB color space very easily. You can use the HSV color space instead, keep S and V constant while changing the H linearly and then converting back to RGB.

    Check this out: http://natecook.com/downloads/color.html
    Last edited by Martin Munoz; 07-27-2007 at 01:56 PM.

  3. #3
    Senior Member joshstrike's Avatar
    Join Date
    Jan 2001
    Location
    Alhama de Granada, España
    Posts
    1,131
    well, this is sort of a stab in the dark, but it seems if you set your saturation and brightness beforehand you can calculate the minimum remaining amounts, then it's just a matter of cycling one value up, then the next up, then the last down, ad infinitum...I haven't tested this code, this is off the top of my head, but I think something like this should work...
    Code:
    var sat:Number = 90;
    var bri:Number = 90;
    var minAmt:Number = sat*.256
    var maxAmt:Number = (256-(bri*.256));
    var rgb:Array = [maxAmt,minAmt,minAmt];
    var currentShift:Number = 0;
    
    //then within your timer event, or enterframe, or whatever...
    if (rgb[currentShift%2]<maxAmt) {
       rgb[currentShift%2]+=1;
    } else {
       rgb[(currentShift-1)%2]-=1;
       if (rgb[(currentShift-1)%2]<minAmt) {
    	   currentShift++;
      }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center