blur line
...
@author ish-xxxx
// write as3 code here..
package {
import caurina.transitions.*;
import flash.display.*;
import flash.events.*;
import flash.filters.*;
import flash.geom.*;
import flash.ui.Keyboard;
import net.hires.debug.Stats;
/**
* ...
* @author ish-xxxx
*/
[SWF(width="465",height="465",backgroundColor="#000000",frameRate="45")]
final public class Doc extends Sprite {
public static const TIME:uint = 8;
private const NUM_OF_TRIALS:uint = 1000;
private const RANDOM_COLOR:Boolean = true;
private const MAX:uint = 10;
private var stats:Stats;
private var counter:uint = 0;
private var container:Sprite;
private var bmd:BitmapData;
private var bmp:Bitmap;
private var bmp2:Bitmap;
private var _stopCount:uint = 0;
public var _lineAlpha : Number = 0.05;
/**
*
*/
public function Doc() {
init();
}
/**
*
*/
private function init() : void {
stage.quality = StageQuality.HIGH;
setup();
}
/**
*
*/
private function setup() : void {
container = new Sprite;
bmd = getBitmapData();
bmp = new Bitmap( bmd , "auto" , true );
bmp.filters = [ new BlurFilter( 2, 2, 10 ) ];
bmp.alpha = 1;
addChild( bmp );
bmp2 = new Bitmap( bmd , "auto" , true );
addChild( bmp2 );
stats = addChild( new Stats() ) as Stats;
stats.visible = false;
stage.addEventListener( KeyboardEvent.KEY_DOWN , function( ev:KeyboardEvent ) : void { if( ev.ctrlKey ) stats.visible = true } );
stage.addEventListener( KeyboardEvent.KEY_UP , function( ev:KeyboardEvent ) : void { stats.visible = false } );
createCircles();
}
/**
*
* @return
*/
private function getBitmapData() : BitmapData {
return new BitmapData( stage.stageWidth , stage.stageHeight , true , 0x000000 );
}
/**
*
*/
private function createCircles() : void {
if( hasEventListener( Event.ENTER_FRAME ))
removeEventListener( Event.ENTER_FRAME , render );
for ( var i:uint = 0 ; i < MAX ; i++ ) {
var c:CirclePoint = new CirclePoint( i );
c.init( "circle" + String( i ) );
c.color = RANDOM_COLOR ? Math.random() * 0xFFFFFF | 0 : 0xFFFFFF | 0;
c.x = c._x = Math.random() * stage.stageWidth;
c.y = c._y = Math.random() * stage.stageHeight;
addChild( c );
c.addEventListener( CirclePoint.EVENT_STOP , stopCount , false , 0 , false );
}
addEventListener( Event.ENTER_FRAME , render , false , 0 , false );
}
/**
*
* @param e
*/
private function render( e:Event ) : void {
var gr:Graphics = container.graphics;
var c1:CirclePoint;
var c2:CirclePoint;
var p1:Point;
var p2:Point;
if( counter != NUM_OF_TRIALS ) {
gr.clear();
for ( var i:uint = 0 ; i < MAX ; i += 2 ) {
c1 = getChildByName( "circle" + String( i ) ) as CirclePoint;
c2 = getChildByName( "circle" + String( i + 1 ) ) as CirclePoint;
p1 = new Point( c1.x - c1.circle.x , c1.y - c1.circle.y );
p2 = new Point( c2.x - c2.circle.x , c2.y - c2.circle.y );
gr.beginFill( c1.color , 1 / 3 );
gr.drawCircle( p1.x , p1.y , 1 / 2 );
gr.beginFill( c2.color , 1 / 3 );
gr.drawCircle( p2.x , p2.y , 1 / 2 );
var p3:Point = Point.interpolate( p1 , p2 , 0.5 );
gr.lineStyle( 0 , c1.color , _lineAlpha );
gr.moveTo( p1.x , p1.y );
gr.lineTo( p3.x , p3.y );
gr.lineStyle( 0 , c2.color , _lineAlpha );
gr.moveTo( p3.x , p3.y );
gr.lineTo( p2.x , p2.y );
}
bmd.draw( container , null , null , "normal" );
} else {
for ( var it:uint = 0 ; it < MAX ; it += 2 ) {
c1 = getChildByName( "circle" + String( it ) ) as CirclePoint;
c2 = getChildByName( "circle" + String( it + 1 ) ) as CirclePoint;
c1.brake();
c2.brake();
}
Tweener.addTween( this , { _lineAlpha : 0 , time : TIME , transition : "easeOutExpo" } );
}
bmd.colorTransform( bmd.rect, new ColorTransform( 1, 1, 1, 1 ));
counter++;
}
/**
*
* @param e
*/
private function stopCount( e:Event ) : void {
if ( ++_stopCount == MAX ) removeEventListener( Event.ENTER_FRAME , render );
}
/**
*
*/
private function restart( e:MouseEvent ) : void {
/**/
}
public function update() : void {
}
}
}
import flash.display.*;
import flash.events.*;
import flash.geom.*;
import caurina.transitions.*;
/**
* ...
* @author Author
*/
internal class CirclePoint extends Sprite {
public static const EVENT_STOP:String = "eventstop";
public var _x:Number;
public var _y:Number;
public var _rad:Number;
public var _deg:Number;
public var _rx:Number;
public var _ry:Number;
public var _speed:Number;
public var _id:uint;
public var circle:Circle;
public var color:uint;
public function CirclePoint ( __id:uint ) {
_id = __id;
}
public function init( _name : String ) : void {
name = _name;
addEventListener( Event.ADDED_TO_STAGE , setup );
}
private function setup() : void {
removeEventListener( Event.ADDED_TO_STAGE , arguments.callee );
_deg = 0;
_rx = Math.random() * ( _id * 20 );
_ry = Math.random() * ( _id * 20 );
_speed = Math.random() * 3 - Math.random() * 3;
circle = new Circle;
addChild( circle );
addEventListener( Event.ENTER_FRAME , render );
}
private function render( e:Event = null ) : void {
_rad = Pythagoras.RadianToDegree( _deg );
x = ( stage.stageWidth / 2 ) + _rx * Math.cos( _rad );
y = ( stage.stageHeight / 2 ) + _ry * Math.sin( _rad );
_deg += _speed;
}
public function brake() : void {
Tweener.addTween( this , { _speed : 0 , time : Doc.TIME , transition : "easeOutExpo" , onComplete : _stop } );
circle.brake();
}
private function _stop() : void {
removeEventListener( Event.ENTER_FRAME , render );
dispatchEvent( new Event( CirclePoint.EVENT_STOP ) );
}
private function get point() : Point {
return new Point( x , y );
}
public function clear() : void {
graphics.clear();
circle.graphics.clear();
}
public function update() : void {
}
}
/**
* ...
* @author ish-xxxx
*/
internal class Circle extends Shape {
public var _x:Number;
public var _y:Number;
public var _rad:Number;
public var _deg:Number;
public var _rx:Number;
public var _ry:Number;
public var _speed:Number;
public function Circle () {
init();
}
private function init() : void {
addEventListener( Event.ADDED_TO_STAGE , setup );
}
protected function setup() : void {
removeEventListener( Event.ADDED_TO_STAGE , arguments.callee );
_deg = 0;
_rx = Math.max( 100 , Math.random() * 200 );
_ry = Math.max( _rx , Math.random() * 200 );
_speed = Math.random() * 5 - Math.random() * 5;
addEventListener( Event.ENTER_FRAME , render );
}
private function render( e:Event = null ) : void {
_rad = Pythagoras.RadianToDegree( _deg );
x = _rx * Math.cos( _rad );
y = _ry * Math.sin( _rad );
_deg += _speed;
}
public function brake() : void {
Tweener.addTween( this , { _speed : 0 , time : Doc.TIME , transition : "easeOutExpo" , onComplete : _stop } );
}
private function _stop() : void {
removeEventListener( Event.ENTER_FRAME , render );
}
private function get point() : Point {
return new Point( x , y );
}
}
/**
* @author : ish-xxxx
*/
internal class Pythagoras {
public function Pythagoras() : void {};
public static function getRadian( tp:Point, cp:Point ):Number {
var dx:Number = tp.x - cp.x;
var dy:Number = tp.y - cp.y;
return Math.atan2( dy, dx );
}
public static function RadianToDegree( deg : Number ) : Number {
return deg * Math.PI / 180;
}
public static function DegreeToRadian( rad : Number ) : Number {
return rad / ( Math.PI / 180 );
}
}