forked from: Optical Illusion (3)
Optical Illusion (3)
/**
* Copyright Nova ( http://wonderfl.net/user/Nova )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/kMuj
*/
// forked from ProjectNya's Optical Illusion (3)
////////////////////////////////////////////////////////////////////////////////
// Optical Illusion (3)
////////////////////////////////////////////////////////////////////////////////
package {
import flash.display.Sprite;
import flash.display.StageScaleMode;
import flash.display.StageAlign;
import flash.events.Event;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.geom.Matrix;
import flash.geom.Point;
import flash.filters.BlurFilter;
import frocessing.color.ColorHSV;
[SWF(backgroundColor="#000000", width="465", height="465", frameRate="60")]
public class Main extends Sprite {
private static var max:uint = 32;
private var container:Sprite;
private var rotationContainer:Sprite;
private var circles:Array;
private static var center:uint = 125;
private static var radius:uint = 95;
private static var speed:Number = 3.2;
private static var radian:Number = Math.PI/180;
private var bitmapData:BitmapData;
private var canvas:Bitmap;
private var matrix:Matrix;
private var blur:BlurFilter;
public function Main() {
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
init();
}
private function init():void {
graphics.beginFill(0x000000);
graphics.drawRect(0, 0, 465, 465);
graphics.endFill();
//
bitmapData = new BitmapData(465, 465, true, 0x00000000);
canvas = new Bitmap(bitmapData);
addChild(canvas);
//
matrix = new Matrix();
matrix.translate(232, 232);
blur = new BlurFilter(4, 4, 8);
//
rotationContainer = new Sprite();
addChild(rotationContainer);
rotationContainer.x = 232;
rotationContainer.y = 232;
//
container = new Sprite();
rotationContainer.addChild(container);
//container.x = 232;
//container.y = 232;
//
circles = [];
var color:ColorHSV = new ColorHSV();
for (var n:uint = 0; n < max; n ++) {
var line:Sprite = new Sprite();
container.addChild(line);
var angle:Number = (360/max)*n;
line.rotation = angle;
color.h = angle;
var circle:Circle = new Circle(color.value);
//circle.angle = angle*3;
circle.x = center + radius*Math.sin(circle.angle*radian);
line.addChild(circle);
circles.push(circle);
}
//
addEventListener(Event.ENTER_FRAME, update, false, 0, true);
}
private function update(evt:Event):void {
for (var n:uint = 0; n < max; n ++) {
var circle:Circle = circles[n];
circle.angle += speed;
circle.x = center + radius*Math.sin(circle.angle*radian);
}
rotationContainer.rotationY += speed;
//matrix.rotate();
//
bitmapData.lock();
bitmapData.draw(container, matrix);
bitmapData.applyFilter(bitmapData, bitmapData.rect, new Point(), blur);
bitmapData.unlock();
}
}
}
//////////////////////////////////////////////////
// Circle
//////////////////////////////////////////////////
import flash.display.Sprite;
import flash.display.Shape;
class Circle extends Sprite {
public var id:uint;
private var color:uint;
private var _angle:Number = 0;
private static var radius:uint = 6;
public function Circle(c:uint) {
color = c;
init();
}
private function init():void {
var circle:Shape = new Shape();
circle.graphics.beginFill(color);
circle.graphics.drawCircle(0, 0, radius);
circle.graphics.endFill();
addChild(circle);
var circle2:Shape = new Shape();
circle2.graphics.beginFill(color);
circle2.graphics.drawCircle(0,0,radius);
circle2.graphics.endFill();
circle2.rotationY = 90;
addChild(circle2);
}
public function get angle():Number {
return _angle;
}
public function set angle(value:Number):void {
_angle = (value + 360)%360;
}
}