Antialised wave
/**
* Copyright signedvoid ( http://wonderfl.net/user/signedvoid )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/hYCU
*/
// forked from 9re's flash on 2011-2-19
package {
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.events.Event;
import flash.display.StageScaleMode;
import flash.display.StageAlign;
import flash.display.Sprite;
public class FlashTest extends Sprite {
private static const LEFT:Number = -5, TOP:Number = 5,
RIGHT:Number = 5, BOTTOM:Number = -5,
K:Number = 6;
private var _canvas:Bitmap;
public function FlashTest() {
addChild(_canvas = new Bitmap);
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(event:Event = null):void {
if (event) removeEventListener(Event.ADDED_TO_STAGE, init);
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.addEventListener(Event.RESIZE, draw);
stage.dispatchEvent(new Event(Event.RESIZE));
}
private function draw(e:Event):void {
var bd:BitmapData = _canvas.bitmapData;
if (bd) bd.dispose();
var w:int = stage.stageWidth, h:int = stage.stageHeight;
bd = new BitmapData(w, h);
bd.lock();
var r:Number, x:Number, y:Number, threshold:Number;
const border:Number = 0.15;
for (var i:int = 0; i < w; ++i) {
r = i / w;
x = (1 - r) * LEFT + r * RIGHT;
for (var j:int = 0; j < h; ++j) {
r = j / h;
y = (1 - r) * TOP + r * BOTTOM;
threshold = Math.sin(K * Math.sqrt(x * x + y * y));
if (y > threshold + border) {
bd.setPixel(i, j, 0xff0000);
}
else
if (y > threshold)
{
if (i < 230)
{
bd.setPixel(i, j, 0xFF0000);
}
else
{
var t:Number = (threshold + border - y) / border;
var white:int = 255.0 * t;
var color:uint = (0xFF0000 | white << 8 | white) ;
bd.setPixel(i, j, color);
}
}
}
}
bd.unlock();
_canvas.bitmapData = bd;
}
}
}