forked from: 辺がぼよよんってなる四角 2
更に_curveの値をマイナスにして、ちょっとだけ角丸をつけてやる
それを45度ずらして重ねると、結晶っぽくなる
// forked from a24's 辺がぼよよんってなる四角
// 更に_curveの値をマイナスにして、ちょっとだけ角丸をつけてやる
// それを45度ずらして重ねると、結晶っぽくなる
package
{
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.filters.GlowFilter;
import caurina.transitions.Tweener;
[ SWF( width = "465" , height = "465" , backgroundColor = "0x000000" , frameRate = "60" ) ]
public class Main extends Sprite
{
public function Main()
{
stage.addEventListener( MouseEvent.MOUSE_MOVE , create );
}
private function create( e:MouseEvent ):void
{
var _cr:CurveRect = new CurveRect();
_cr.rotation = Math.random() * 45;
_cr.alpha = 0.5 + Math.random() * 0.5;
_cr.x = stage.mouseX;
_cr.y = stage.mouseY;
_cr.scaleX = _cr.scaleY = 0.2 + Math.random() * 0.6;
_cr.lineStyle( 1.0 , 0xFFFFFF , 0 );
_cr.beginFill( 0xFFFFFF , 1.0 );
_cr._width = 20;
_cr._height = 20;
_cr._round = 2; // 角丸値
_cr._curve = -20; // 辺のカーブ値
_cr.draw( true ); //基準点をセンターで描画
_cr.filters = [ new GlowFilter( 0xFFFFFF , 0.8 , 16 , 16 , 1.5 ) ];
var _cr2:CurveRect = new CurveRect();
_cr2.rotation = 45;
_cr2.scaleX = _cr2.scaleY = 0.7;
_cr2.lineStyle( 1.0 , 0xFFFFFF , 0 );
_cr2.beginFill( 0xFFFFFF , 1.0 );
_cr2._width = 20;
_cr2._height = 20;
_cr2._round = 2; // 角丸値
_cr2._curve = -20; // 辺のカーブ値
_cr2.draw( true ); //基準点をセンターで描画
_cr.addChild( _cr2 );
addChild( _cr );
Tweener.addTween( _cr , {
y:_cr.y + 200 * Math.random() ,
alpha:0 ,
rotation:Math.random() * 360 ,
time:Math.random() + 0.2 ,
transition:"easeInQuad" ,
onComplete:function():void{ removeChild( _cr ); }
} );
}
}
}
import flash.display.Sprite;
import flash.display.Graphics;
class CurveRect extends Sprite
{
private var _g:Graphics;
private var _lineStyle:Array;
private var _beginFill:Array;
public var _round:Number;
public var _curve:Number;
public var _width:Number;
public var _height:Number;
public function CurveRect()
{
_g = this.graphics;
_lineStyle = [ 1 , 0x000000 , 1.0 ];
_beginFill = [ 0xFFFFFF , 1.0 ];
_round = 0;
_curve = 0;
}
public function lineStyle( _thickness:Number , _color:uint , _alpha:Number ):void
{
_lineStyle = [ _thickness , _color , _alpha ];
}
public function beginFill( _color:uint , _alpha:Number ):void
{
_beginFill = [ _color , _alpha ];
}
public function draw( _center:Boolean = false ):void
{
var _posX:Number = ( _center ) ? _width/2 : 0;
var _posY:Number = ( _center ) ? _height/2 : 0;
_g.clear();
_g.lineStyle( _lineStyle[0] , _lineStyle[1] , _lineStyle[2] );
_g.beginFill ( _beginFill[0] , _beginFill[1] );
_g.moveTo ( 0 - _posX , _round - _posY );
_g.curveTo ( 0 - _posX , 0 - _posY , _round - _posX , 0 -_posY );
_g.curveTo ( _width/2 - _posX , -_curve - _posY , _width -_round - _posX , 0 - _posY );
_g.curveTo ( _width - _posX , 0 - _posY , _width - _posX , _round - _posY );
_g.curveTo ( _width + _curve - _posX , _height/2 - _posY , _width - _posX , _height -_round - _posY );
_g.curveTo ( _width - _posX , _height - _posY , _width - _round - _posX , _height - _posY );
_g.curveTo ( _width/2 - _posX , _height + _curve - _posY , _round - _posX , _height - _posY );
_g.curveTo ( 0 - _posX , _height - _posY , 0 - _posX , _height - _round - _posY );
_g.curveTo ( -_curve - _posX , _height/2 - _posY , 0 - _posX , _round - _posY );
_g.endFill();
}
}