Inverting texture color with AGAL - actionscript-3

I've been using the Genome2D library and wanted to create a filter that inverts all color. After reading Adobe documentation, I can't seem to figure out what's going on with the alpha channel since .rgba doesn't even seem to work.
This Genome2D code desaturates all color:
fragmentCode = "dp3 ft0.xyz, ft0.xyz, fc1.xyz";
fragmentConstants = Vector.<Number>([0.299,0.587,0.114,0]);
Following that example, I wrote this code for inverting color:
fragmentCode = "sub ft0.xyz, fc1.xyz, ft0.xyz"
fragmentConstants = Vector.<Number>([1,1,1,0]);
All of the color inverts, but the alpha channel is fully opaque in places it should be completely transparent. I'm having trouble figuring out how to copy the old alpha values from the original texture.

Related

LibGDX BitmapFont Markup Alpha Value

Alright, so I have a bitmap font with markup enabled. The problem is, I need to set the global alpha value for a whole string of text without setting an individual alpha value for each color code.
For example, I have...
"[#0000ff]this is blue, [#990000]this is red"
I'd like the font text to fade into the background by setting an alpha value. Is there any way to do this without manually parsing color codes and sticking an alpha value into the brackets?
I've also tried adding custom colors with Colors.put(..), but that gets really clunky, as I have to set the alpha value to each color I'm using, with each line of text that I am drawing.
You'll need to use the BitmapFontCache class.
So for example, say your code currently looks like this...
font.drawWrapped(batch, text, x, y, wrapWidth, alignment);
Replace it with the following and you can control the alpha in the way you require...
BitmapFontCache cache = font.getCache();
cache.clear();
TextBounds bounds = cache.addMultiLineText(text, x, y, wrapWidth, alignment);
// This is the useful bit!
cache.setAlphas(alphaTransparency);
cache.draw(batch);
Note - If you're using distance field fonts then the shader most people use for them doesn't support alpha, but it's easy to fix it so it does. Let me know if you hit that problem.

Flash color transform

I'm having difficulty with transforming colour in Flash. It should be easy I think, but for some reason my code isn't working as expected.
I have a bitmap graphic consisting of a colour spectrum from red to yellow to green (you know, like you see in an audio level meter).
I simply want to sample a colour from that bitmap and then tint a movie clip on stage that sampled colour. (the effect I'll be going for is coloured progress - the closer you get to 100% green is displayed, the closer you are to 0% it's red - I haven't implemented that part yet, but I'm not worried about that).
Anyhow, I sample the colour just fine, and tint my clip, but no matter what I tint the clip it comes up a different colour than what I've sampled (the trace is a different colour than what I see on the clip). I can't see where I'm going wrong - I'm hoping it's a stupid mistake and someone can spot it easily.
import flash.display.BitmapData;
var bmd:BitmapData = new BitmapData(mc_colourbar.width, mc_colourbar.height);
bmd.draw(mc_colourbar);
var pixelvalue:uint = bmd.getPixel(0, 1);
trace(pixelvalue.toString(16));
var colourtransform:ColorTransform = mc_box.transform.colorTransform;
colourtransform.color = uint("0xff" + pixelvalue);
mc_box.transform.colorTransform = colourtransform ;
mc_box is the clip on stage I'm trying to tint - it's simply a white square.
Any help is appreciated, thanks in advance!
ColorTransform.color expects an RGB value, and it appears as though you're attempting to give it an ARGB value*.
Change the line:
colourtransform.color = uint("0xff" + pixelvalue);
to just:
colourtransform.color = pixelvalue;
and your code should work as expected.
*Though I don't think the way you're trying to do it here is correct.

How to Change Hue and Saturation of a MovieClip in AS3

I have myself a movieclip that has multiple images in, I want to be able to use AS3
to change the Hue and Saturation so the client can choose a colour and it will change the colour of the movieclip to their settings.
I have tried this
var my_color:ColorTransform = new ColorTransform();
my_color.color = 0x550000;
tempPlayer.transform.colorTransform = my_color;
But the movieclip just becomes completely red, I just want to be able to add a touch of colour, and then make the colour stand out a bit using AS3. Basically something like this
but from grey to one colour
Canvas
For saturation it gets a little more complicated than the traditional ColorTransform. Often, you will need to use ColorMatrixFilter.
This feature is quite complicated, but this blog post describes the process quite well and gives you code for a couple common effects.
That said, you can add just a little color to an object with ColorTransform by using the *Offset and *Multiplier properties like greenOffset and redMultiplier. This lets you offset the red, green or blue values a little to give different effects.

Calculating "artistic" (ryb) Complementary color in AS3

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

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.