A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: colours and shades

  1. #1
    Senior Member dudeqwerty's Avatar
    Join Date
    Mar 2005
    Location
    Bosnia
    Posts
    1,626

    colours and shades

    hello,

    i have 20 mc's, when i pick a colour from my colour picker component i want the 20 mc's to show the various shades of the colour selected (from dark to light).

    i have tried using setTransform() but all i get is a white - black "shade spectrum"

    how would i go about getting the various shades of a colour?

    also, how can i extract the seperate R, G and B values from a RGB value?

    many thanks,

    zlatan
    New sig soon

  2. #2
    FK Newb Beater
    Join Date
    Dec 2002
    Location
    Seattle
    Posts
    676
    I Peiced this code together while building a smaller ComboBox Component for an online app. You can experiment with it as it does exactly what you describe. I found it to be very useful while setting color themes and creating several shades and borders from one RGB value:
    Code:
    var rgb = 0x53AC82
    //extacts the red channel
    var red = (rgb & 16711680) >> 16;
    //extacts the green channel
    var green = (rgb & 65280) >> 8;
    //extacts the blue channel
    var blue = rgb & 255;
    //Adjusts color monochrome +40% upto 255 Max
    //Positive adjustments lighten
    //Negative adjustments darken
    red = (red * 1.4) < 255 ? red * 1.4 : 255;
    green = (green * 1.4) < 255 ? green * 1.4 : 255;
    blue = (blue * 1.4) < 255 ? blue * 1.4 : 255;
    //Convert back to Hex
    var c = red << 16 | green << 8 | blue;
    trace(c)
    Just because you changed the code, doesn't mean it's yours

    Most Recent Work:
    Commercial tanning beds website

  3. #3
    Senior Member dudeqwerty's Avatar
    Join Date
    Mar 2005
    Location
    Bosnia
    Posts
    1,626
    thanks, but you code does not work with the "primary colours" such as 0x00ff00 and 0xff0000, also i dont see a way of changing the difference between the 2 shades.

    please correct me if i am mistaken,

    thanks again,

    zlatan
    New sig soon

  4. #4
    FK Newb Beater
    Join Date
    Dec 2002
    Location
    Seattle
    Posts
    676
    Correct, look at the math of the code. green and blue = 0 when extracting from 0xff0000 and 0*1.4 = 0, when it needs to be >0 to lighten.

    Experiment with this code and you can come up with something that suites you needs.
    Just because you changed the code, doesn't mean it's yours

    Most Recent Work:
    Commercial tanning beds website

  5. #5
    FK Newb Beater
    Join Date
    Dec 2002
    Location
    Seattle
    Posts
    676
    you could do this...
    Code:
    red = (red * 1.4) < 255 ? red * 1.4 : 255;
    red = red == 0 ? 255 * .4 : red;
    green = (green * 1.4) < 255 ? green * 1.4 : 255;
    green = green == 0 ? 255 * .4 : green;
    blue = (blue * 1.4) < 255 ? blue * 1.4 : 255;
    blue = blue == 0 ? 255 * .4 : blue;
    Just because you changed the code, doesn't mean it's yours

    Most Recent Work:
    Commercial tanning beds website

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