The Ultrashock Ultra Bundle
  • Home
  • Community
  • Forum
  • Flash
  • ActionScript
  • Thread
  •  
  • Previous topic
  • Next topic
Sign up to post

Flash
 ActionScript

  • slyone Author 
    • 2014 
    • 0 
    • 5 
    color gurus : calculate hex tints (add white)
    alexboyer

    Last reply Oct 24 2007, 05:57 PM

    by alexboyer

    Posted: Oct 24 2007, 02:53 PM

    by slyone

     

I posted this on Actionscript.org but I think one of you awesome gurus here might know the answer to this.

First off just to clarify how I am using the word “tint”: a tint of a color in the print world is that same color with white added. For example, say I have 3 clips, each various tints of red…here are the corresponding hex values:

100% tint of Red : #FF0000
50% tint of Red: #FF8080
10% tint of Red: #FFE5E5

I need a way to calculate tints of a given hex value… ie I want to solve the following:

50% white +  [#hex value] = [new #hex value]

I have looked at bitwise operators because I think the answer lies there but I have to admit binary numbers and converting between bases was never my strong suit. Any help appreciated.

thanks!

  5 REPLIES
 
senocular
1  
senocular

Should be able to find something in here:
http://proto.layer51.com/l.aspx?p=10

  • 24 October 2007 03:03 PM
  •  
slyone Author 
2  
slyone

Thanks senocular, for the quick reply.

I am not seeing anything in there that will help exactly. If you read my post, I am trying to calculate a new hex value based on adding white to a known hex value. That’s different from ‘tints’ in Flash (which transparently overlay a color over another color).

I just need help with the calculation part.
I need a function that will return a result for the following:

[percent of white] + [#hex value] = [new #hex value]

For the example I gave before (tints of red), the pseudo formula would look like:

50% white + #FF0000 = #FF8080

The question is, how do I make that calculation in Actionscript?

  • 24 October 2007 03:43 PM
  •  
Nutrox
3  
Nutrox

[as]var tintedA:Number = tintColour( 0xFF0000, 1.0 );
var tintedB:Number = tintColour( 0xFF0000, 0.5 );
var tintedC:Number = tintColour( 0xFF0000, 0.1 );

trace( tintedA.toString( 16 ) ); // ff0000
trace( tintedB.toString( 16 ) ); // ff8080
trace( tintedC.toString( 16 ) ); // ffe6e6

//

function tintColour( colour:Number, tint:Number ):Number
{
var r:Number = ( colour & 0xFF0000 ) >> 16;
var g:Number = ( colour & 0x00FF00 ) >> 8;
var b:Number = ( colour & 0x0000FF );

tint = 1 - tint;

r = Math.round( r + ( ( 255 - r ) * tint ) );
g = Math.round( g + ( ( 255 - g ) * tint ) );
b = Math.round( b + ( ( 255 - b ) * tint ) );

return ( r << 16 ) | ( g << 8 ) | b;
}[/as]
That seems to be working.

The tint value you pass to the function is a value between 0.0 and 1.0 inclusive, where 0.0 = 0% and 1.0 = 100%

  • 24 October 2007 04:02 PM
  •  
slyone Author 
4  
slyone

whoa dude. you rock!

  • 24 October 2007 04:10 PM
  •  
alexboyer
5  
alexboyer

Nutrox is the US AS OG. (Ultrashock Actionscript Original Gangsta) stick out tongue

  • 24 October 2007 05:57 PM
  •  
  •   Log in or join for free to make a comment.
 
Topic actions
  •  Share on Facebook
  •  Share on Twitter
Topic Categories
  •  Show All Topics
  •  Development
    •  Server Side
    •  Client Side
  •  Creative Software
    •  Web
    •  Video
    •  3D
    •  Illustrator
    •  Photoshop Battles
    •  Photoshop
  •  Design
    •  Typography
    •  Resources & Insight
    •  Checkpoint
  •  Career
    •  Copyright Matters
    •  Advice & issues
    •  Job Seekers
    •  Job Offers
  •  Flash
    •  UltraMath
    •  OOP
    •  Third Party Tools
    •  Open Source alternatives
    •  Data Communication
    •  Components
    •  Flex
    •  AIR
    •  Flash Lite
    •  Flash Professional
    •  Flash Newbie
    •  ActionScript
    •  XML
  •  Lounge
    •  Polls
    •  Random Chat
    •  Showcase And Critique
    •  BombShock Award Nominations
  •  Community Essentials
    •  BombShock Award Winners
    •  Tutorials
    •  Interviews
    •  News
    •  Bitmap tutorials
Popular Topics
  • Sort by: 
  • Activity
  • Views
  • Comments
  • Likes
Advertise with us
  • Your advertisement here!
  • loading
Ultrashock
  • Creative Assets
  • Community
  • Blog
  1. Home
  2. Forum
+/-
Creative Assets
  • Categories
  • Contributors
  • How to buy
Make Money
  • Commission Rates
  • Referral Program
  • Contributor Program
Community
  • Activity Feed
  • Forum
  • Profiles
About
  • Quick Tour
  • Our History
  • Banners & Logos
Support
  • Contact Ultrashock
  • Advertise with us
  • Legal Information
  •  Keep up to date
  • Flash 775  Flash
  • Audio 6,481  Audio
  • Vector 2,130  Vectors
  • Image 12,338  Images
  • Creative Assets 21,724  Assets
  • Profiles 282,659  Members
  • Topics 93,762  Topics
  • Blog 4  Blog
  • Facebook 1,680  Facebook
  • Twitter 1,165  Twitter
  • Join our FREE monthly newsletter!
  • Archive
  • Invalid email address. Please try again.
Subscribe
  • ©2012 Ultrashock LLC - All rights reserved
  • Terms of Use
  • Privacy Policy
  • Switch to dark theme
  • RSS Feeds
  • Top

©2012 Ultrashock LLC - All rights reserved

Printed on Sat, February 04, 2012 - 20:24:53