linear algebra
renders cross sections of YIQ color space
cf. http://wonderfl.net/c/3AnJ
no gamma logic \:
/**
* Copyright wh0 ( http://wonderfl.net/user/wh0 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/leZD
*/
package {
import flash.events.MouseEvent;
import flash.filters.ColorMatrixFilter;
import flash.geom.Matrix;
import flash.display.*;
public class FlashTest extends Sprite {
private static const s:Number = 10. / 0x4000;
public function FlashTest() {
graphics.clear();
graphics.beginFill(0x000000);
graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
graphics.endFill();
var s1:Shape = new Shape();
s1.graphics.beginGradientFill(
GradientType.LINEAR,
[0x000000, 0x0000ff],
[1, 1],
[0, 255],
new Matrix(0, -stage.stageHeight * s, 1, 0, 0, stage.stageHeight / 2)
);
s1.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
s1.graphics.endFill();
s1.blendMode = BlendMode.ADD;
addChild(s1);
var s2:Shape = new Shape();
s2.graphics.beginGradientFill(
GradientType.LINEAR,
[0x000000, 0x00ff00],
[1, 1],
[0, 255],
new Matrix(stage.stageWidth * s, 0, 0, 1, stage.stageWidth / 2, 0)
);
s2.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
s2.graphics.endFill();
s2.blendMode = BlendMode.ADD;
addChild(s2);
filters = [new ColorMatrixFilter([
1, 1.13489, 0.646535, 0, -228.022,
1, -0.322914, -0.674019, 0, 127.607,
1, -1.31373, 1.77469, 0, -59.0029,
0, 0, 0, 1, 0
])];
stage.addEventListener(MouseEvent.MOUSE_MOVE, adjust);
}
private function adjust(e:MouseEvent):void {
var v:int = (1 - e.stageY / stage.stageHeight) * 255;
v = Math.max(Math.min(v, 255), 0);
graphics.clear();
graphics.beginFill(v << 16);
graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
graphics.endFill();
}
}
}