Moire
/**
* Copyright miyaoka ( http://wonderfl.net/user/miyaoka )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/oKuS
*/
package
{
import flash.display.*;
import flash.events.*;
import flash.geom.*;
[SWF(width = "465", height = "465", backgroundColor = 0xFFFFFF, frameRate = "60")]
public class Moire extends Sprite
{
public function Moire()
{
var sw:Number = stage.stageWidth;
var sh:Number = stage.stageHeight;
var swh:Number = Math.ceil(sw * 0.5);
var shh:Number = Math.ceil(sh * 0.5);
var radius:Number = Math.ceil(Math.sqrt(Math.pow(sw, 2) + Math.pow(sh, 2))/2);
var ms:MoireShape = new MoireShape(new Rectangle( -radius, -radius, radius * 2, radius * 2), 1,6);
ms.x = swh;
ms.y = shh;
var mX:Number = 0;
var mY:Number = 0;
addEventListener(Event.ENTER_FRAME, function ():void
{
// trace(ms.mouseX, mX);
mX += (mouseX - ms.x - mX) * 0.1;
mY += (mouseY - ms.y - mY) * 0.1;
ms.rotation = Math.atan2( mY, mX ) * 180 / Math.PI - 45;
});
stage.addEventListener(MouseEvent.MOUSE_DOWN, function ():void
{
setBg();
});
var bg:Sprite = new Sprite();
addChild(bg);
addChild(ms);
setBg();
function setBg():void
{
while (bg.numChildren > 0) bg.removeChildAt(0);
var ms1:MoireShape = new MoireShape(new Rectangle(0, 0, swh, shh), Math.random()*5+1, Math.random()*5);
var ms2:MoireShape = new MoireShape(new Rectangle(0, 0, swh, shh), Math.random()*5+1, Math.random()*5);
var ms3:MoireShape = new MoireShape(new Rectangle(0, 0, swh, shh), Math.random()*5+1, Math.random()*5);
var ms4:MoireShape = new MoireShape(new Rectangle(0, 0, swh, shh), Math.random()*5+1, Math.random()*5);
ms2.x = ms4.x = swh;
ms3.y = ms4.y = shh;
bg.addChild(ms1);
bg.addChild(ms2);
bg.addChild(ms3);
bg.addChild(ms4);
}
}
}
}
import flash.display.*;
import flash.geom.*;
class MoireShape
extends Sprite
{
public function MoireShape(rect:Rectangle, span:Number, thickness:Number = 1, clr:uint =0):void
{
var g:Graphics = graphics;
g.beginFill(0, 1);
for (var i:Number = 0; i < rect.width; i += span + thickness)
{
g.moveTo( i, 0);
g.drawRect(i, 0, thickness, rect.height);
}
var bmd:BitmapData = new BitmapData(width, height, true, 0x00000000);
bmd.draw(this);
g.clear();
var bmp:Bitmap = new Bitmap(bmd);
bmp.x = rect.left;
bmp.y = rect.top;
bmp.smoothing = true;
addChild(bmp);
}
}