ff: flash on 2014-6-2 (non-flickering)
♥2 |
Line 51 |
Modified 2014-06-06 21:16:20 |
MIT License
archived:2017-03-20 10:24:50
ActionScript3 source code
/**
* Copyright signedvoid ( http://wonderfl.net/user/signedvoid )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/bWaf
*/
// forked from UnknownOpenID's flash on 2014-6-2
package {
import flash.filters.BlurFilter;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.text.TextFormat;
import flash.text.TextField;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.display.Sprite;
public class FlashTest extends Sprite {
private var image:Bitmap;
private var text:TextField;
private var generation:uint = 0;
private var counter:int = 0;
public function FlashTest()
{
addEventListener(Event.ENTER_FRAME, Update);
image = new Bitmap(new BitmapData(stage.stageWidth, stage.stageHeight, false, 0xffffff));
image.bitmapData.noise(Math.random() * int.MAX_VALUE);
//image.filters = [ new BlurFilter(2,2) ];
addChild(image);
text = new TextField();
text.autoSize = "left";
text.textColor = 0xFF8C3C3C;
addChild(text);
}
public function Update(event:Event):void
{
for(var i:int = 0; i < 2; i++)
{
var clone:Bitmap = new Bitmap(image.bitmapData.clone());
clone.bitmapData.lock();
var bitmapdata:BitmapData = image.bitmapData;
var maxy:int = clone.height - 1;
var maxx:int = clone.width - 1;
for(var y:uint = 1; y < maxy; y++)
{
for(var x:uint = 1; x < maxx; x++)
{
clone.bitmapData.setPixel(x, y,
(bitmapdata.getPixel(x - 1, y - 1) + bitmapdata.getPixel(x + 1, y + 1) + bitmapdata.getPixel(x + 1, y - 1) + bitmapdata.getPixel(x - 1, y + 1)) / 4)
}
}
image.bitmapData = clone.bitmapData;
}
text.text = "Output:\nGeneration: " + generation.toString();
text.setTextFormat(new TextFormat("arial", 32));
generation += 1;
}
}
}