Every frame you get screen caputre of the stage.
* Generate new frame image with using last frames screen capture.
* This is a starting point of recursive generative art.
/**
* Copyright faseer ( http://wonderfl.net/user/faseer )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/7wEE
*/
// forked from checkmate's fladdict challenge for amateurs
/**
* Every frame you get screen caputre of the stage.
* Generate new frame image with using last frames screen capture.
* This is a starting point of recursive generative art.
*/
package {
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.BlendMode;
import flash.display.GradientType;
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.ColorTransform;
import flash.geom.Matrix;
import flash.geom.Point;
public class Beginner extends Sprite {
/**
* Overwrite this update function.
* Every frame the function is invoked with two bitmaps.
* First one contains reference to the stage bitmap.
* Second one contains static copy of stage.
*/
public var canvas:BitmapData;
public var drawHere:BitmapData;
public var mat:Matrix;
public function update():void{
drawStep();
transformStep();
renderStep();
fadeStep();
}
public function drawStep():void {
offsets[0].x++;
offsets[0].y++;
var f:Number = Math.PI / 180 * .33;
var fx:Number = offsets[0].x * f;
var fy:Number = offsets[0].y * f;
drawHere.perlinNoise( drawHere.width * Math.cos(fx), drawHere.height * Math.sin(fy), 1, 1, false, false, 7, false, offsets);
drawHere.draw(grad, null, new ColorTransform(2, 2, 2, 1, 255, 255, 255), BlendMode.ADD);
drawHere.draw(grad, null, null, BlendMode.OVERLAY);
}
public function transformStep():void
{
mat = new Matrix();
mat.scale(canvas.width / drawHere.width, canvas.height / drawHere.height);
}
public function renderStep():void{
canvas.draw(drawHere, mat);
}
public function fadeStep():void
{
//canvas.colorTransform(drawHere.rect, new ColorTransform(Math.random()*0.4+0.6,Math.random()*0.4+0.6,Math.random()*0.4+0.6,1,0,0,0,0));
}
/**
* ---------------------------------------
* DO NOT CHANGE FOLLOWING CODES
* DO NOT ACCESS FOLLOWING PROPERTIES DIRECTLY
* ---------------------------------------
*/
private var bitmap:Bitmap;
private var grad:Shape = new Shape();
private var offsets:Array = [new Point()];
public function Beginner() {
canvas = new BitmapData(480,480,false,0x000000);
drawHere = new BitmapData(canvas.width*.5, canvas.height*.5, false, 0xFFFFFF);
bitmap = new Bitmap(canvas);
addChild(bitmap);
addEventListener(Event.ENTER_FRAME, _update);
drawGradient(grad, canvas.width*.5);
}
public function _update(e:Event):void{
//if(drawHere)
//drawHere.dispose();
//drawHere = canvas.clone();
update();
}
public function drawGradient(s:Shape, size:Number):void
{
var m:Matrix = new Matrix();
m.createGradientBox(size, size);
s.graphics.clear();
s.graphics.beginGradientFill(
GradientType.RADIAL,
[0x000000, 0x808080], // colors
[ 0, 1], // alphas
[ 0, 255], // ratios
m, // matrix
'pad', 'rgb', 0
);
s.graphics.drawRect(0, 0, size, size);
s.graphics.endFill();
}
}
}