Calculating "artistic" (ryb) Complementary color in AS3 - actionscript-3

I need to calculate/generate the complementary color of color. I thought I had it working but it's the wrong kind. As the opposite of red I get cyan instead of green, that's because AS3 uses rgb values. I know that I would need to use RYB values but I don't know how to convert from RGB to RYB, Calculate to complementary color of the RYB value and then Convert it back to RGB. I don't have a lot of knowledge of AS3.

You should look in to Hue-Saturation-Brightness. A rotation of 180 degrees on the Hue scale should give the opposite color.
I don't have actual code for you to share but check out the ColorMatrix class from Quasimondo:
http://code.google.com/p/quasimondolibs/source/browse/trunk/quasimondolibs/com/quasimondo/geom/ColorMatrix.as

Related

Instead of using a hex code for a color, make it transparent [AS3]

So lets say I have some code in as3, and it requires a given color (Current one is 0x701100 for example) but instead of giving it a hex color code, I want it to be transparent, aka no color, aka see through, you get what I mean.
This is basically the line of code that determines what color it is: super(0x701100, 0x8D1500); and well the 0x8D1500 represents some other things color, but all I want is the 0x701100 to be transparent/not show.
The color 0x701100 is already "transparent" in that it has no value for an alpha channel. It's the same as 0x00701100. A value such as 0xff701100 would represent a fully opaque color, and 0x80701100 would be about 50% transparent. Obviously, the problem is that your super() method does not support rendering transparency from the hex color.

What is the theoretical mechanism to produce LIGHT COLOR in HTML?

Maybe this has already been answered before but i couldn't find it. I want to generate LIGHT COLOR in HEX format for HTML Background in this format :-( #FFFFFF )
I tried writing codes to always pick the first, third and fifth Numeric in the HEX color String to be greater than 9. But that logic really doesn't necessary include all LIGHT colors.
For ex. #00F890 is a light color too.
I know the perception of "light color" depends on human to human. I'm very curious if there is a way to write a function like this ? (I'm using perl)
sub random_light_color
{
my $lightness_level=shift; ##Let's say between 0-100
#Do some magic
return $HEX;
#Based on lightness_level. 0=>White 100=>BLACK
#Closer $lightness_level to 0, lighter the color
#(BUT ALWAYS RANDOM=>Good mix of RGB)
}
Maybe i'm missing something ?
What you are looking for is a way to select colors perceived as "light" by the human eye/brain. To do this you need to work in the HSL color space.
HSL is a way of expressing colors as Hue, Saturation and Lightness, instead of Red, Green and Blue. What you'll need to do is research the algorithm for converting from HSL to RGB (there are lots of resources available on the web, including online converters).
You can cycle through all possible combinations of Hue and Saturation, limiting yourself to colors with lightness above some threshold. Then run those combinations through the conversion algorithm to get the RGB equivalents.

Masking in ActionScript3

I am trying to understand masks in actionscript..Everything seems to make sense to me but one part of the code
function mouseM(event:MouseEvent):void {
if (mouseclick == 1) {
mask_mc.graphics.beginFill(0x000000);
mask_mc.graphics.drawEllipse(mouseX, mouseY, 70, 60);
mask_mc.graphics.endFill();
}
}
I am not sure how to exactly ask this question but here it goes. why does the mask have "begin fill" with a black color? wouldn't that paint the the image in black (I know it doesn't, it just reveals it)? what is the exact function of beginfill (besides revealing the image lool)? like how does it exactly work? sorry if it sounds ridiculously off.. but that part of the code was really screwing me up in understanding masks
What you are doing is drawing a shape to be used as a mask. In this case, a circle.
It doesn't matter what colour it is as Flash is only interested in the shape of the mask, not the colour.
Once the circle is drawn, Flash checks what part of the circle overlap the object you're masking so that every pixel the circle is not covering will be invisible. I guess it should really be called an anti-mask as the circle dictates which parts of your image wont be masked but it's just become the general convention to call the circle (or whatever shape you use) the mask.
Again, you're just creating a shape to be used as a mask. Setting the colour is just so the object can essentially exist.. because you can't exactly have a transparent circle.
Feel free to change the colour to anything and you'll see it makes no difference, the shape is all that matters.

Finding close colors of a given color

I´d like to know, how, through actionscript 3, to get an array of ARGB (hexadecimal) colors, that is close to a given color.
Example:
0xFF00FF00
A green.
How to get variations of green?
I´m trying to get some green colors of a bitmapdata.
I´ve tried to get it by making a loop getting the colors using getPixels32.
The problem is, I think the bits colors of each position are different from the bits of the bitmap rendered.
It´s for a pathfinder.
Each green bit sets a node in a map, as walkable.
So I need to know what are these colors to set it as walkable for the pathfinder.
Any suggestions?
RGB space is terrible for interpreting whether colors are similar to one another. A different color space that matches closer to human perception of color is HSV (hue saturation and value). Here are the steps you should follow:
Convert your value from RGB space to HSV (http://www.cs.rit.edu/~ncs/color/t_convert.html)
Modify the saturation and value to obtain different shades of the same green hue.
You can even modify the hue a little with a defined tolerance level you specify
Reconvert back to HSV to RGB
I believe technically..one color space is smaller than the other, meaning it is not always a 1:1 conversion - but it should serve your purpose.

Random Non-White Colors That Look Okay As Background for Black Text

I'd like to generate random, non-white colors using hue, saturation and brightness that can be used as a background for black text. I've created a generator for random colors, but when I scan the numbers, I can't see any clear pattern in the colors that look too dark.
How can I generate random non-white background colors for black text? Feel free to answer with code or pseudo-code, but it's definitely not necessary.
Only generate colors with high brightness values - for example, if you were using the range 0-255 for each of {H,S,V}, you'd generate H in [0,255], S in [0,255], V in [168,255]. That should give you colors that are bright enough. You may want to restrict saturation as well (e.g. S in [0,192]), since black on full-bright, full-saturation colors may not be very readable.
You'll probably need to play with the values to get ranges that will give you usable colors.
I don't know color theory, but you can try randomly generating the 3 components in RGB (xxx,xxx,xxx) in a way that the sum of the components is greater than X (X depends of the contrast you want), and the convert to HSB.
HSV and HSL are broken models than have nothing to do with perception. You should generate your colors in YUV space (also known as YCbCr) where the intensity (Y) channel is not simply R+G+B but rather models the perceptual intensities of red, green, and blue. A good starting point would be to try random Y values at least 200 and random U and V values between -50 and 50.