Optical Illusion (1)
/**
* Copyright ProjectNya ( http://wonderfl.net/user/ProjectNya )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/oKu1
*/
////////////////////////////////////////////////////////////////////////////////
// Optical Illusion (1)
////////////////////////////////////////////////////////////////////////////////
package {
import flash.display.Sprite;
import flash.display.StageScaleMode;
import flash.display.StageAlign;
import flash.events.Event;
import frocessing.color.ColorHSV;
[SWF(backgroundColor="#000000", width="465", height="465", frameRate="60")]
public class Main extends Sprite {
private static var max:uint = 16;
private var container: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;
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();
//
container = new Sprite();
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);
}
}
}
}
//////////////////////////////////////////////////
// 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);
}
public function get angle():Number {
return _angle;
}
public function set angle(value:Number):void {
_angle = (value + 360)%360;
}
}