forked from: 要素の軌跡にパーティクルを出す
//////////////////////////////////////////////////////////////////////////////
要素の軌跡にパーティクルを出す
//////////////////////////////////////////////////////////////////////////////
// forked from twistcube's 要素の軌跡にパーティクルを出す
////////////////////////////////////////////////////////////////////////////////
//
// 要素の軌跡にパーティクルを出す
//
////////////////////////////////////////////////////////////////////////////////
package
{
import flash.display.* ;
import flash.events.* ;
import flash.net.* ;
import flash.system.* ;
[SWF(width="500", height="500", backgroundColor="0x33302E", frameRate="30")]
public class Stardust2 extends Sprite
{
private var _distance:Object = { min:200, max:300 } ; // 落ちる距離
private var _move_spd:Object = { min:0.01, max:0.03 } ; // 落ちる速さ
private var _clear_spd:Object = { min:0.02, max:0.06 } ; // 消える速さ
private var _scale_spd:Object = { min:0.02, max:0.06 } ; // 消える速さ
private var _rotation:Number = 0 ;
private var _prevX:Number = 0 ;
private var _prevY:Number = 0 ;
private var _renderCount:uint = 0 ;
private var _yoyo:Yoyo ;
public function Stardust2( )
{
init( ) ;
}
private function init( ):void
{
stage.scaleMode = StageScaleMode.NO_SCALE ;
stage.align = StageAlign.TOP_LEFT ;
// stage.quality = StageQuality.LOW ;
_yoyo = new Yoyo( ) ;
addChild( _yoyo ) ;
addEventListener( Event.ENTER_FRAME, onRender );
}
public function xRotation( ):Number
{
return _rotation ;
}
private function onRender( event:Event ):void
{
if ( _prevX == _yoyo.x && _prevY == _yoyo.y )
{
return ;
}
_rotation = Math.atan2( _prevX - _yoyo.x, _prevY - _yoyo.y ) * 180 / Math.PI + 90 ;
_prevX = _yoyo.x ;
_prevY = _yoyo.y ;
for ( var i:Number=0; i<3; i++ )
{
// パーティクルを生成
var obj:StarSprite = new StarSprite( _distance, _move_spd, _clear_spd, _scale_spd, _rotation ) ;
obj.x = _yoyo.x ;
obj.y = _yoyo.y ;
obj.addEventListener( Event.COMPLETE, onComplete ) ;
addChild( obj ) ;
// 4個に1個だけ大きくする
if ( _renderCount == 4 )
{
obj.scaleX = obj.scaleY = Math.random( ) * 2 + 0.8 ;
_renderCount = 0 ;
}
else
{
obj.scaleX = obj.scaleY = Math.random( ) * .4 + .4 ;
_renderCount++ ;
}
}
// 常に最前面にする
addChild( _yoyo ) ;
}
private function onComplete( event:Event ):void
{
var obj:StarSprite = event.target as StarSprite ;
removeChild( obj ) ;
obj = null ;
}
}
}
import flash.display.* ;
import flash.events.* ;
import flash.geom.* ;
import flash.filters.* ;
class Yoyo extends Sprite
{
private const SPRING:Number = .1 ;
private const FRICTION:Number = .9 ;
private var _vect:Point ;
private var _source:Sprite ;
public function Yoyo( )
{
addEventListener( Event.ADDED_TO_STAGE, init ) ;
addEventListener( Event.REMOVED_FROM_STAGE, unload ) ;
}
private function init( event:Event ):void
{
removeEventListener( Event.ADDED_TO_STAGE, init ) ;
_source = new Sprite( ) ;
x = stage.stageWidth / 2 ;
y = stage.stageHeight / 2 ;
_source.graphics.beginFill( 0xe3f23e ) ;
_source.graphics.drawCircle( 0, 0, 10 ) ;
_source.graphics.endFill( ) ;
addChild( _source ) ;
_vect = new Point( 100 * Math.random( ) - 50, 100 * Math.random( ) - 50 ) ;
filters= [ new BlurFilter( 10, 10, 3 ) ] ;
//filters = [ new DropShadowFilter( 10, 45, 0x7c863d, 0.5, 5, 5, 5 ) ] ;
addEventListener( Event.ENTER_FRAME, onRender ) ;
}
private function unload( event:Event = null ):void
{
removeEventListener( Event.REMOVED_FROM_STAGE, unload ) ;
removeEventListener( Event.ENTER_FRAME, onRender ) ;
}
private function onRender( event:Event ):void
{
_vect.x += ( stage.mouseX - x ) * SPRING ;
_vect.y += ( stage.mouseY - y ) * SPRING ;
_vect.x *= FRICTION ;
_vect.y *= FRICTION ;
x += _vect.x ;
y += _vect.y ;
}
}
import flash.display.* ;
import flash.events.* ;
import flash.filters.* ;
class StarSprite extends Sprite
{
private var _distance:Number ; // 落ちる距離
private var _move_spd:Number ; // 落ちる速さ
private var _clear_spd:Number ; // 消える速さ
private var _scale_spd:Number ; // 拡大/縮小する速さ
private var _rotation:Number ;
private var _vx:Number ;
private var _vy:Number ;
public function StarSprite( _distance:Object, _move_spd:Object, _clear_spd:Object, _scale_spd:Object, _rotation:Number ):void
{
this._distance = _distance.min + Math.random( ) * ( _distance.max - _distance.min ) ;
this._move_spd = _move_spd.min + Math.random( ) * ( _move_spd.max - _move_spd.min ) ;
this._clear_spd = _clear_spd.min + Math.random( ) * ( _clear_spd.max - _clear_spd.min ) ;
this._scale_spd = _scale_spd.min + Math.random( ) * ( _scale_spd.max - _scale_spd.min ) ;
this._rotation = _rotation ;
addEventListener( Event.ADDED_TO_STAGE, init ) ;
addEventListener( Event.REMOVED_FROM_STAGE, unload ) ;
}
private function init( event:Event ):void
{
removeEventListener( Event.ADDED_TO_STAGE, init ) ;
graphics.clear( ) ;
graphics.beginFill( 0xa6a53f );
graphics.drawCircle( 0, 0, 4 ) ;
graphics.drawCircle( 0, 0, 2 ) ;
graphics.endFill( ) ;
//filters = [ new DropShadowFilter( 10, 45, 0x7c863d, 0.5, 5, 5, 5 ) ] ;
xAction( ) ;
}
private function unload( event:Event = null ):void
{
removeEventListener( Event.REMOVED_FROM_STAGE, unload ) ;
removeEventListener( Event.ENTER_FRAME, onRender ) ;
}
private function xAction( ):void
{
var rot:Number = _rotation + Math.random( ) * 120 - 60 ;
var theta:Number = rot * Math.PI / 180 ;
_vx = x - Math.cos( theta ) * _distance ;
_vy = y + Math.sin( theta ) * _distance ;
addEventListener( Event.ENTER_FRAME, onRender ) ;
}
private function onRender( event:Event ):void
{
x += ( _vx - x ) * _move_spd ;
y += ( _vy - y ) * _move_spd ;
alpha -= _clear_spd ;
scaleX += _scale_spd ;
scaleY += _scale_spd ;
if ( alpha < 0 )
{
dispatchEvent( new Event( Event.COMPLETE ) ) ;
}
}
}