/**
* Copyright tikudiajitendra825 ( http://wonderfl.net/user/tikudiajitendra825 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/3jia
*/
// forked from hacker_szoe51ih's DisplacementMapFilterの練習
package {
import flash.display.*;
import flash.geom.*;
import flash.utils.*;
import flash.events.*;
import flash.display.MovieClip;
import flash.geom.Point;
import flash.utils.Timer;
import flash.filters.DisplacementMapFilterMode;
import flash.filters.DisplacementMapFilter;
[SWF(width=465,height=465,backgroundColor=0xffffff,frameRate=45)]
import flash.filters.BevelFilter;
public class FlashTest extends Sprite {
public var w:Number=465;
public var h:Number=465;
public var shape:Ball;
public var bmpd:BitmapData;
public var bmp:Bitmap;
public var ctf:ColorTransform;
public var mtx:Matrix;
public var bevel:BevelFilter;
public var myDisplacementMap:DisplacementMapFilter;
//public var filter:Array;
public var rate:Number;
public var octave:uint;
public var stitch:Boolean;
public var fractal:Boolean;
public var channel:uint;
public var point:Point;
public var scale:Number;
public var myTimer:Timer;
public var vx:Number=0;
public function FlashTest() {
// write as3 code here..
init();
}
public function init():void{
bmpd = new BitmapData(w,h,false,0xffffff);
bmp=new Bitmap(bmpd);
addChild(bmp);
filters=new Array();
rate=1/2;
octave=2;
stitch=false;
fractal=true;
channel=BitmapDataChannel.BLUE;
point=new Point(0,0);
scale=25;
shape=new Ball(0xffffff,0x215dd4,0xdfffac,180);
//addChild(shape);
shape.x=w/2;
shape.y=h/2;
myTimer=new Timer(200);
myTimer.addEventListener(TimerEvent.TIMER,wave);
myTimer.start();
}
public function wave(e:TimerEvent):void{
//var random:int=Math.floor(Math.random()*20);
vx+=5;
bmpd.perlinNoise(w*rate,h*rate,octave,vx,stitch,fractal,channel,false);
bevel=new BevelFilter(20,120,0xdddddd,0.6,0x111162,0.6,45,45);
myDisplacementMap=new DisplacementMapFilter(bmpd,point,channel,channel,scale,scale,DisplacementMapFilterMode.IGNORE);
shape.filters=[myDisplacementMap,bevel];
ctf=new ColorTransform();
ctf.alphaMultiplier=0.5;
mtx=new Matrix();
mtx.translate(w/2,h/2);
bmpd.draw(shape,mtx,ctf);
}
}
}
import flash.display.*;
import flash.geom.Matrix;
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 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);
//図形を描く
//graphics.lineStyle(1,lineColor);
graphics.drawCircle(0,0,r);
graphics.endFill();
}
}