Perlin/Displacement Ball
/**
* Copyright bradsedito ( http://wonderfl.net/user/bradsedito )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/8T5i
*/
//BradSedito 2011
package {
import flash.filters.BevelFilter;
import flash.filters.BlurFilter;
import flash.filters.DisplacementMapFilter;
import flash.filters.BitmapFilterType;
import flash.display.*;
import flash.geom.*;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.BitmapDataChannel;
import flash.filters.BitmapFilterQuality;
[SWF(backgroundColor="#ffffff", frameRate=60)]
public class DispMapTest extends Sprite {
private const STW:uint = stage.stageWidth;
private const STH:uint = stage.stageHeight;
private var sp:Sprite;
private var map:BitmapData;
private var bm:Bitmap;
private var offset:Array = new Array();
private var noiseSeed:Number = 0;
private var channels:uint = BitmapDataChannel.RED;
private var blur:BlurFilter;
private var point1:Point = new Point(0, 0);
private var point2:Point = new Point(0, 0);
private var perlinOffset:Array = [point1, point2];
public function DispMapTest() {
map= new BitmapData(STW, STH, true, 0x00000000);
bm = new Bitmap(map);
addChild(bm);
sp = new Sprite();
sp.graphics.beginFill(0x000000, 1);
sp.graphics.drawCircle(STW/2,STH/2,STW/4);
bm.mask = sp;
var pnt:Point = new Point(0,0);
// sp.x = STW;
// sp.y = STH;
var ch:uint = BitmapDataChannel.RED;
var dispFilter:DisplacementMapFilter = new DisplacementMapFilter(map,pnt,ch,ch);
//dispFilter.scaleX =200;
//dispFilter.scaleY =200;
blur = new BlurFilter();
// blur.blurX = 20;
// blur.blurY = 20;
blur.blurX = 0;
blur.blurY = 0;
blur.quality = BitmapFilterQuality.HIGH;
var bevelFilter:BevelFilter = getBitmapFilter();
var filterTimer:Timer = new Timer(10);
filterTimer.addEventListener(TimerEvent.TIMER , filterTimerFunc);
function filterTimerFunc(evtObj:TimerEvent):void{
perlinOffset[0].x += 6;
perlinOffset[1].x -= 6;
perlinOffset[0].y += 6;
perlinOffset[1].y += 6;
map.perlinNoise(100,100, 1, 1, true, true, channels,false, perlinOffset);
filters = new Array(bevelFilter,blur,dispFilter,blur);
}
filterTimer.start();
}
private function getBitmapFilter():BevelFilter {
var distance:Number = 100;
var angleInDegrees:Number = 45;
var highlightColor:Number = 0xFFFFFF;
var highlightAlpha:Number = 0.2;
var shadowColor:Number = 0x000000;
var shadowAlpha:Number = 0.8;
var blurX:Number = 100;
var blurY:Number = 100;
var strength:Number = 1;
var quality:Number = BitmapFilterQuality.HIGH;
var type:String = BitmapFilterType.INNER;
var knockout:Boolean = false;
return new BevelFilter(distance,
angleInDegrees,
highlightColor,
highlightAlpha,
shadowColor,
shadowAlpha,
blurX,
blurY,
strength,
quality,
type,
knockout);
}
}
}