Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package
- {
- import adobe.utils.CustomActions;
- import flash.display.Bitmap;
- import flash.display.BitmapData;
- import flash.display.DisplayObject;
- import flash.display.Graphics;
- import flash.display.Shader;
- import flash.display.Shape;
- import flash.display.Sprite;
- import flash.events.Event;
- import flash.events.MouseEvent;
- import flash.filters.BlurFilter;
- import flash.filters.ColorMatrixFilter;
- import flash.filters.ConvolutionFilter;
- import flash.filters.DropShadowFilter;
- import flash.filters.ShaderFilter;
- import flash.geom.Matrix;
- import flash.geom.Point;
- import flash.geom.Rectangle;
- /**
- * ...
- * @author @bitetti
- */
- public class Ubunted extends Sprite
- {
- [@Embed(source = "start-here-ubuntuoriginal.jpg")]
- static private const BASE:Class;
- // Biblioteca
- [@Embed(source = "brilho.png")]
- static private const BRILHO:Class;
- // Shader copyright de http://www.dasprinzip.com/prinzipiell/2008/06/06/fisheye/
- [@Embed(source = "shaders/fisheye.pbj", mimeType = 'application/octet-stream')]
- private static const Fisheye: Class;
- private var canvas:BitmapData = new BitmapData(150, 150, false, 0xffffffff );
- private var image:BitmapData = new BASE().bitmapData.clone();
- private var mbrilho:BitmapData = new BRILHO().bitmapData.clone();
- private var bmp:BitmapData = new BitmapData(canvas.width, canvas.height, false, 0xffffffff);
- private var _brilho:Shape;
- private var rectangle:Shape;
- private var mat:Matrix = new Matrix;
- private var sc:Number = 0.31;
- private var rot:Number = 0;
- private var _blur:Number = 0;
- private var fisheyeShader:Shader = new Shader ( new Fisheye );
- private var fisheye:ShaderFilter = new ShaderFilter( fisheyeShader );
- private var _fisheye_x:Number = 0.5;
- private var _fisheye_y:Number = 0.5;
- private var _fisheye_rad:int = 0;
- private var _nitidez:Number;
- public function Ubunted()
- {
- addChild( rectangle = new Shape );
- addChild( _brilho = new Shape );
- brilho = 0.4;
- draw();
- addEventListener(MouseEvent.MOUSE_DOWN, dow );
- }
- public function set rotate(v:Number):void
- {
- rot = v;
- draw();
- }
- public function set scale(v:Number):void
- {
- sc = v;
- draw();
- }
- public function set brilho(v:Number):void
- {
- _brilho.alpha = v;
- }
- public function set blur(v:Number):void
- {
- _blur = int( 32 * v );
- draw();
- }
- public function set fish_x(v:Number):void
- {
- _fisheye_x = v;
- draw();
- }
- public function set fish_y(v:Number):void
- {
- _fisheye_y = v;
- draw();
- }
- public function set fish_rad(v:Number):void
- {
- _fisheye_rad = int(400*v);
- draw();
- }
- public function set nitidez(v:Number):void
- {
- _nitidez = v;
- draw();
- }
- public function setupImage( dt:DisplayObject ):void
- {
- trace(dt.width, dt.height );
- var tBmp:BitmapData = image;
- image = new BitmapData( dt.width, dt.height, false, 0xffffffff );
- image.lock();
- image.draw(dt);
- image.unlock();
- draw();
- }
- public function getCanvas():BitmapData
- {
- canvas.lock();
- canvas.fillRect( canvas.rect, 0xffffffff );
- canvas.draw(this);
- canvas.unlock();
- return canvas;
- }
- private function draw( e:Event = null ):void
- {
- mat.identity();
- mat.translate( oldPM.x + pt.x, oldPM.y + pt.y);
- curPM.x = mat.tx;
- curPM.y = mat.ty;
- //mat.tx = 81+ image.width / 2;
- //mat.ty = 81+ image.height / 2;
- mat.scale( sc,sc );
- mat.rotate( rot );
- // filtros
- bmp.lock();
- bmp.fillRect( new Rectangle(0, 0, canvas.width, canvas.height), 0xffffffff );
- bmp.draw(image, mat, null, null, null, true);
- if (_fisheye_rad > 0)
- {
- var tmp:BitmapData = image.clone();
- tmp.lock();
- fisheyeShader.data.radius.value = [ _fisheye_rad ];
- fisheyeShader.data.center_x.value = [ int(tmp.width * _fisheye_x) ];
- fisheyeShader.data.center_y.value = [ int(tmp.height * _fisheye_y) ];
- tmp.applyFilter(tmp,tmp.rect, new Point, fisheye);
- tmp.unlock();
- bmp.draw(tmp, mat, null, null, null, true);
- //bmp.applyFilter( bmp, bmp.rect, new Point(0, 0), fisheye );
- }
- if (_blur > 0)
- bmp.applyFilter( bmp, bmp.rect, new Point(0, 0), new BlurFilter( _blur, _blur, 3 ) );
- var mt:Array;
- mt = new Array;
- if (_nitidez > 0)
- {
- mt=mt.concat([1+8*_nitidez,0,0,0,-40]);// red
- mt=mt.concat([0,1+8*_nitidez,0,0,-40]);// green
- mt=mt.concat([0,0,1+8*_nitidez,0,-40]);// blue
- mt=mt.concat([0,0,0,1,0]);// alpha
- //bmp.applyFilter(bmp, bmp.rect, new Point, new ConvolutionFilter(3,3,mt) );
- bmp.applyFilter(bmp, bmp.rect, new Point, new ColorMatrixFilter(mt) );
- }
- bmp.unlock();
- var g:Graphics = rectangle.graphics;
- g.clear();
- g.lineStyle(0, 0xa0a0a0, 0);
- //g.beginFill(0xffffff, 1);
- //g.beginBitmapFill( image, mat, true, true);
- g.beginBitmapFill( bmp, new Matrix, true, true);
- g.drawRoundRectComplex(5, 8, 138, 138, 24, 24, 26, 0);
- g.endFill();
- g = _brilho.graphics;
- g.lineStyle(0, 0, 0);
- g.clear();
- var bMat:Matrix = new Matrix;
- bMat.translate( -5, -5);
- g.beginBitmapFill( mbrilho, bMat, true, true);
- g.drawRoundRectComplex(5, 8, 138, 138, 24, 24, 26, 0);
- g.endFill();
- rectangle.filters = [
- new DropShadowFilter(
- 0, 45, // dist , angle
- 0x303030, 1, // color, alpha
- 6, 6, //blur
- 1, //strentch
- 3, false,false, false ) // quality
- ];
- //bmp.dispose();
- }
- private var pt:Point = new Point;
- private var oldPM:Point = new Point;
- private var curPM:Point = new Point;
- private var oldX:Number = 0;
- private var oldY:Number = 0;
- private function drag( e:MouseEvent ):void
- {
- pt.x = e.localX - oldX;
- pt.y = e.localY - oldY;
- //oldX = e.stageX;
- //oldY = e.stageY;
- draw();
- }
- private function dow(e:MouseEvent):void
- {
- oldPM.x = curPM.x;
- oldPM.y = curPM.y;
- oldX = e.localX;
- oldY = e.localY;
- stage.addEventListener( MouseEvent.MOUSE_UP, up );
- stage.addEventListener( MouseEvent.MOUSE_MOVE, drag );
- }
- private function up(e:MouseEvent):void
- {
- stage.removeEventListener( MouseEvent.MOUSE_MOVE, drag );
- stage.removeEventListener( MouseEvent.MOUSE_UP, up );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment