[ Team LiB ] |
Recipe 3.4 Setting the RGB Relative to Its Current Value3.4.1 ProblemYou want to modify the RGB value of a movie clip relative to its current value. 3.4.2 SolutionUse Color.getRGB( ) to retrieve the current value, then perform bitwise operations to modify the value, and set the new value using Color.setRGB( ). 3.4.3 DiscussionWe saw in Recipe 3.3 how to retrieve the current RGB value of a movie clip using Color.getRGB( ) and then use bitwise operations to extract the red, blue, and green components. To perform a relative color adjustment, simply modify the individual color components and reapply the new color using Color.setRGB( ). For example, you could brighten a movie clip's color by increasing the red, green, and blue components by a certain amount: // Create the Color object. my_color = new Color(myMovieClip); // Retrieve the current RGB setting. rgb = my_color.getRGB( ); red = (rgb >> 16); green = (rgb >> 8) & 0xFF; blue = rgb & 0xFF; // Brighten the colors by increasing their magnitude. This assumes that the red, // green, and blue values are no more than 245 prior to the operation. red += 10; green += 10; blue += 10; // Combine the components into a single RGB value and apply it with Color.setRGB( ). rgb = (red << 16) | (green << 8) | blue; my_color.setRGB(rgb); |
[ Team LiB ] |