SlopeBlindsEffect
//////////////////////////////////////////////////////////////////////////////
外部画像を角度をつけたBlindにて表示
//////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
// 外部画像を角度をつけたBlindにて表示
//
////////////////////////////////////////////////////////////////////////////////
package
{
import flash.display.* ;
import flash.events.* ;
import flash.filters.ColorMatrixFilter ;
import flash.net.* ;
import flash.system.* ;
import flash.utils.getTimer ;
import flash.geom.ColorTransform ;
import caurina.transitions.Tweener ;
[SWF(width="500", height="500", backgroundColor="0xFFFFFF", frameRate="30")]
public class SlopeBlindsEffect extends Sprite
{
private var _loader:Loader ;
private var _loaderInfo:LoaderInfo ;
private var _maskList:SlopeBlindsMask ;
private var _canvas:BitmapData ;
private var _startTime:int ;
public function SlopeBlindsEffect( )
{
init( ) ;
}
private function init( ):void
{
stage.scaleMode = StageScaleMode.NO_SCALE ;
stage.align = StageAlign.TOP_LEFT ;
//stage.quality = StageQuality.LOW ;
Security.loadPolicyFile( "http://www.twist-cube.com/wonderfl/crossdomain.xml" ) ;
var loaderContext:LoaderContext = new LoaderContext( ) ;
loaderContext.checkPolicyFile = true ;
_loader = new Loader( ) ;
_loader.load( new URLRequest( "http://www.twist-cube.com/wonderfl/logo03.png" ), loaderContext ) ;
_loaderInfo = _loader.contentLoaderInfo ;
_loaderInfo.addEventListener( Event.COMPLETE, onLoadComplete ) ;
}
private function onLoadComplete( event:Event ):void
{
_loaderInfo.removeEventListener( Event.COMPLETE, onLoadComplete ) ;
var nStartX:Number = Math.floor( ( stage.stageWidth - _loader.width ) / 2 ) ;
var nStartY:Number = Math.floor( ( stage.stageHeight - _loader.height ) / 2 ) ;
var MASK_NUM:uint = 25 ; // Blindの数
var MASK_ANGLE:Number = 45 ; // Blindの角度
_maskList = new SlopeBlindsMask( _loader, MASK_NUM, MASK_ANGLE ) ;
var mainContainer:Sprite = new Sprite( ) ;
mainContainer.x = nStartX ;
mainContainer.y = nStartY ;
addChild( mainContainer )
var maskContainer:Sprite = new Sprite( ) ;
maskContainer.x = nStartX ;
maskContainer.y = nStartY ;
maskContainer.rotation = MASK_ANGLE ;
addChild( maskContainer ) ;
mainContainer.addChild( _loader ) ;
_loader.mask = maskContainer ;
var mask_sp:Sprite ;
var nLength:uint = _maskList.list.length ;
for ( var i:uint = 0; i < nLength; i++ )
{
mask_sp = _maskList.list[ i ] ;
maskContainer.addChild( mask_sp ) ;
var nTarget:Number = mask_sp.width ;
mask_sp.width = 0 ;
Tweener.addTween(
mask_sp,
{
width : nTarget,
time : .7,
delay : .05 * i,
transition : "easeOutQuad"
}
) ;
}
}
}
}
import flash.display.* ;
class SlopeBlindsMask
{
private var _originImage:DisplayObject ;
private var _num:uint ;
private var _rot:Number ;
private var _list:Array = new Array( ) ;
public function SlopeBlindsMask( _originImage:DisplayObject, _num:uint, _rot:Number )
{
this._originImage = _originImage ;
this._num = _num ;
this._rot = _rot ;
init( ) ;
}
private function init( ):void
{
var size:Object = getMaskSize( ) ;
var mask_sp:Sprite = new Sprite( ) ;
var nMaskWidth:Number = size.width / _num ;
var nMaskY:Number = -_originImage.width * Math.sin( _rot * Math.PI / 180 ) ;
for ( var i:uint = 0; i < _num; i++ )
{
mask_sp = new Sprite( ) ;
mask_sp.y = nMaskY ;
mask_sp.x = nMaskWidth * i ;
// mask_sp.alpha = 0.3
mask_sp.graphics.beginFill( 0xFFFFFF * Math.random( ) ) ;
mask_sp.graphics.drawRect( 0, 0, Math.ceil( nMaskWidth ), size.height ) ;
mask_sp.graphics.endFill( ) ;
list.push( mask_sp ) ;
}
}
private function getMaskSize( ):Object
{
var nW:Number = _originImage.height * Math.cos( _rot * Math.PI / 180 ) + _originImage.width * Math.cos( (90-_rot) * Math.PI / 180 )
var nH:Number = _originImage.height * Math.sin( _rot * Math.PI / 180 ) + _originImage.width * Math.sin( (90-_rot) * Math.PI / 180 )
return { width:nW, height:nH } ;
}
public function get list( ):Array
{
return _list ;
}
public function set list( _list:Array ):void
{
this._list = _list ;
}
}