ブラーの練習
♥0 |
Line 76 |
Modified 2010-06-19 01:25:08 |
MIT License
archived:2017-03-29 12:55:33
ActionScript3 source code
/**
* Copyright hacker_szoe51ih ( http://wonderfl.net/user/hacker_szoe51ih )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/lmzj
*/
package {
import flash.display.*;
import flash.events.*;
import flash.filters.*;
[SWF(width="465",height="465",backgroundColor="0xffffff",fps="45")]
import flash.geom.Point;
public class FlashTest extends Sprite {
public var myBall:Ball;
public var centerX:Number=stage.stageWidth/2;
public var centerY:Number=stage.stageHeight/2;
public var pointX:Number;
public var pointY:Number;
public var blurFilter:BlurFilter;
public function FlashTest() {
init();
}
public function init():void{
pointX=centerX;
pointY=centerY;
blurFilter=new BlurFilter(1,1,1);
myBall=new Ball(0xccccff,0x2255ff,0x1111ff,50);
addChild(myBall);
myBall.x=centerX;
myBall.y=centerY;
stage.addEventListener(MouseEvent.CLICK,onClick);
addEventListener(Event.ENTER_FRAME,enterFrame);
}
public function onClick(e:MouseEvent):void{
pointX=e.stageX;
pointY=e.stageY;
}
public function enterFrame(e:Event):void{
var blurRatio:Number =Math.max(Math.abs((pointX-myBall.x)/5), Math.abs((pointY-myBall.y)/5));
blurFilter.blurX=blurRatio;
blurFilter.blurY=blurRatio;
//blurFilter.blurY=Math.max((pointX-myBall.x)/6,(pointY-myBall.y)/6);
myBall.filters=[blurFilter];
myBall.x+=(pointX-myBall.x)/2*0.2;
myBall.y+=(pointY-myBall.y)/2*0.2;
if(pointX==myBall.x && pointY==myBall.y){
//removeEventListener(Event.ENTER_FRAME,enterFrame);
myBall.filters=[];
pointX=myBall.x;
pointY=myBall.y;
}
}
}
}
import flash.display.*;
import flash.geom.Matrix;
import flash.filters.*;
class Ball extends Sprite{
public var type:String;
public var colors:Array;
public var alphas:Array;
public var rations:Array;
public var spread:String;
public var interpolation:String;
public var focalPoint:Number;
public var mtx:Matrix;
//public var dropshadow:DropShadowFilter;
public function Ball(color1:uint,color2:uint,lineColor:uint,r:Number){
//グラデーションのパラメーターを作る
//引数1
type=GradientType.RADIAL;
//引数2
colors=[color1,color2];
//引数3
alphas=[1,1]
//引数4
rations=[0,255];
//引数5
mtx=new Matrix();
mtx.createGradientBox(2*r,2*r,0,0,0);//幅、高さ、方向を指定する角度、水平移動ピクセル数、垂直移動ピクセル数
mtx.translate(-r,-r);
mtx.rotate(Math.PI/4);
//引数6
spread=SpreadMethod.PAD;
//引数7
interpolation="rgb"
//引数8
focalPoint=0//グラデーションの焦点の位置
graphics.beginGradientFill(type,colors,alphas,rations,mtx,spread,interpolation,focalPoint);
//フィルターの作成
//dropshadow = new DropShadowFilter(5,45,0xcccccc,0.6);
//filters = [dropshadow];
//図形を描く
graphics.lineStyle(1,lineColor);
graphics.drawCircle(0,0,r);
graphics.endFill();
}
}