Packagegraphics.drawing
Classpublic class DistortPen
InheritanceDistortPen Inheritance Pen Inheritance flash.utils.Proxy

This pen tesselates an area into severals triangles to allow free transform distortion on BitmapData Objects.

Example :

     import graphics.drawing.DistortPen ;
     
     stage.align     = "tl" ;
     stage.scaleMode = "noScale" ;
     
     var shape:Shape = new Shape() ;
     
     shape.x = 0 ;
     shape.y = 0 ;
     
     addChildAt( shape , 0 ) ;
     
     var bmp:BitmapData = new Girl(0,0) ; // Girl a BitmapData linked in the library of the SWF.
     
     var pen:DistortPen = new DistortPen( shape, bmp.width, bmp.height, 4, 4 ) ;
     
     pen.bitmapData = bmp
     
     pen.draw( p1 , p2 , p3 , p4 ) ;
     
     var enterFrame:Function = function (e:Event ):void
     {
         pen.draw( p1, p2, p3, p4 ) ;
     }
     
     var onStartDrag:Function = function( e:Event ):void
     {
         if ( e.target is MovieClip )
         {
             (e.target as MovieClip).startDrag() ;
             (e.target as MovieClip).addEventListener( Event.ENTER_FRAME , enterFrame ) ;
         }
     }
     
     var onStopDrag:Function = function( e:Event ):void
     {
         if ( e.target is MovieClip )
         {
             (e.target as MovieClip).stopDrag() ;
             (e.target as MovieClip).removeEventListener( Event.ENTER_FRAME , enterFrame ) ;
         }
     }
     
     // p1, p2, p3 and p4 are 4 little anchor MovieClip in the stage of the application.
     
     p1.buttonMode    = true ;
     p1.useHandCursor = true ;
     p1.addEventListener( MouseEvent.MOUSE_DOWN , onStartDrag ) ;
     p1.addEventListener( MouseEvent.MOUSE_UP   , onStopDrag  ) ;
     
     p2.buttonMode    = true ;
     p2.useHandCursor = true ;
     p2.addEventListener( MouseEvent.MOUSE_DOWN , onStartDrag ) ;
     p2.addEventListener( MouseEvent.MOUSE_UP   , onStopDrag  ) ;
     
     p3.buttonMode    = true ;
     p3.useHandCursor = true ;
     p3.addEventListener( MouseEvent.MOUSE_DOWN , onStartDrag ) ;
     p3.addEventListener( MouseEvent.MOUSE_UP   , onStopDrag  ) ;
     
     p4.buttonMode    = true ;
     p4.useHandCursor = true ;
     p4.addEventListener( MouseEvent.MOUSE_DOWN , onStartDrag ) ;
     p4.addEventListener( MouseEvent.MOUSE_UP   , onStopDrag  ) ;
     



Public Properties
 PropertyDefined By
 Inheritedalign : uint
Determinates the align value of the pen.
Pen
  bitmapData : BitmapData
Determinates the BitmapData reference of the distort pen.
DistortPen
  bl : *
The bottom left point of the distortion.
DistortPen
  br : *
The bottom right point of the distortion.
DistortPen
 Inheritedfill : IFillStyle
Determinates the fill style object of the pen.
Pen
 Inheritedgraphics : *
Specifies the Graphics object belonging to this Shape object, where vector drawing commands can occur.
Pen
  height : Number
Indicates the height value of the pen.
DistortPen
  hPrecision : uint
Indicates the horizontal precision of the pen.
DistortPen
 Inheritedline : ILineStyle
Determinates the line style object of the pen.
Pen
  smoothing : Boolean = true
Indicates whether or not use pixel smoothing render.
DistortPen
  tl : *
The top left point of the distortion.
DistortPen
  tr : *
The top right point of the distortion.
DistortPen
 InheriteduseClear : Boolean = true
Indicates if the clear() method is invoked at the end of the draw method.
Pen
 InheriteduseEndFill : Boolean = true
Indicates if the endFill() method is invoked at the end of the draw method.
Pen
  vPrecision : uint
Indicates the vertical precision precision of the pen.
DistortPen
  width : Number
Determinates the width of this distort pen.
DistortPen
Public Methods
 MethodDefined By
  
DistortPen(graphic:*, width:Number = 0, height:Number = 0, hPrecision:uint = 2, vPrecision:uint = 2, bitmapData:BitmapData = null)
Creates a new DistorPen instance.
DistortPen
 Inherited
BF(... arguments):void
Defines a shortcut reference to used the beginBitmapFill method.
Pen
 Inherited
C(... arguments):void
Defines a shortcut reference to used the curveTo method.
Pen
 Inherited
CL():void
Defines a shortcut reference to used the clear method.
Pen
  
draw(... args):void
[override] Draws the shape and distorts the BitmapData according to the provided Point instances and draws it into the provided Graphics.
DistortPen
  
drawShape():void
[override] This method contains the basic drawing shape algorithm.
DistortPen
 Inherited
EF():void
Defines a shortcut reference to used the endFill method.
Pen
 Inherited
F(... arguments):void
Defines a shortcut reference to used the beginFill method.
Pen
 Inherited
GF(... arguments):void
Defines a shortcut reference to used the beginGradientFill method.
Pen
 Inherited
GS(... arguments):void
Defines a shortcut reference to used the lineGradientStyle method.
Pen
 Inherited
L(... arguments):void
Defines a shortcut reference to used the lineTo method.
Pen
 Inherited
M(... arguments):void
Defines a shortcut reference to used the moveTo method.
Pen
 Inherited
S(... arguments):void
Defines a shortcut reference to used the lineStyle method.
Pen
  
setPen(... args):void
Sets the shape options to defined all values to draw the shape.
DistortPen
  
setPrecision(hPrecision:Number, vPrecision:Number):void
Sets the precision of this distort pen instance and re-initializes the triangular grid.
DistortPen
  
setSize(width:Number, height:Number):void
Sets the size of this pen and re-initializes the triangular grid.
DistortPen
Protected Methods
 MethodDefined By
  
init():void
Tesselates the area into triangles.
DistortPen
Property Detail
bitmapDataproperty
bitmapData:BitmapData

Determinates the BitmapData reference of the distort pen.


Implementation
    public function get bitmapData():BitmapData
    public function set bitmapData(value:BitmapData):void
blproperty 
public var bl:*

The bottom left point of the distortion.

Note : This point must be an object with the x and y attributes (Point, Vector2, generic object, DisplayObject, etc.

brproperty 
public var br:*

The bottom right point of the distortion.

Note : This point must be an object with the x and y attributes (Point, Vector2, generic object, DisplayObject, etc.

heightproperty 
height:Number

Indicates the height value of the pen.


Implementation
    public function get height():Number
    public function set height(value:Number):void
hPrecisionproperty 
hPrecision:uint

Indicates the horizontal precision of the pen.


Implementation
    public function get hPrecision():uint
    public function set hPrecision(value:uint):void
smoothingproperty 
public var smoothing:Boolean = true

Indicates whether or not use pixel smoothing render.

tlproperty 
public var tl:*

The top left point of the distortion.

Note : This point must be an object with the x and y attributes (Point, Vector2, generic object, DisplayObject, etc.

trproperty 
public var tr:*

The top right point of the distortion.

Note : This point must be an object with the x and y attributes (Point, Vector2, generic object, DisplayObject, etc.

vPrecisionproperty 
vPrecision:uint

Indicates the vertical precision precision of the pen.


Implementation
    public function get vPrecision():uint
    public function set vPrecision(value:uint):void
widthproperty 
width:Number

Determinates the width of this distort pen.


Implementation
    public function get width():Number
    public function set width(value:Number):void
Constructor Detail
DistortPen()Constructor
public function DistortPen(graphic:*, width:Number = 0, height:Number = 0, hPrecision:uint = 2, vPrecision:uint = 2, bitmapData:BitmapData = null)

Creates a new DistorPen instance.

Parameters
graphic:* — The Graphics reference to control with this helper. You can passed-in a Shape or Sprite/MovieClip reference in argument.
 
width:Number (default = 0) — The width of the picture to be processed (default 0).
 
height:Number (default = 0) — The height of the picture to be processed (default 0).
 
hPrecision:uint (default = 2) — The horizontal precision value (default 2).
 
vPrecision:uint (default = 2) — The vertical precision value (default 2).
 
bitmapData:BitmapData (default = null)
Method Detail
draw()method
override public function draw(... args):void

Draws the shape and distorts the BitmapData according to the provided Point instances and draws it into the provided Graphics.

Parameters

... args — The position object specifying the coordinates of the top-left corner of the distortion.

drawShape()method 
override public function drawShape():void

This method contains the basic drawing shape algorithm.

init()method 
protected function init():void

Tesselates the area into triangles.

setPen()method 
public function setPen(... args):void

Sets the shape options to defined all values to draw the shape.

Parameters

... args — Point specifying the coordinates of the top-left corner of the distortion.

setPrecision()method 
public function setPrecision(hPrecision:Number, vPrecision:Number):void

Sets the precision of this distort pen instance and re-initializes the triangular grid.

Parameters

hPrecision:Number — The horizontal precision.
 
vPrecision:Number — The vertical precision.

setSize()method 
public function setSize(width:Number, height:Number):void

Sets the size of this pen and re-initializes the triangular grid.

Parameters

width:Number — New width value.
 
height:Number — New height value.