ゆらゆら~
なみなみ+なみなみ+がぞー=ゆらゆら~
* @author minon
// forked from minon's なんだかちょっと旗っぽい
// forked from minon's なみなみ
/**
* なみなみ+なみなみ+がぞー=ゆらゆら~
* @author minon
*/
package {
import flash.display.*;
import flash.events.Event;
import flash.geom.*;
import flash.net.URLRequest;
import flash.system.LoaderContext;
import flash.text.TextField;
import flash.utils.getTimer;
[SWF (width="465",height="465",frameRate="60",backgroundColor="#000000")]
public class FlashTest extends Sprite {
public var _outline:Sprite;
public var _canvas:Bitmap;
public var _n:int = 20;
public var _l:int = 320;
public var _pArray:Array = [];
public var _bitmapdata:BitmapData;
public function FlashTest() {
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener( Event.COMPLETE, this.init );
loader.load( new URLRequest("http://labs.minomix.net/img/minon.jpg"), new LoaderContext(true) );
}
public function init(e:Event):void {
var loader:Loader = LoaderInfo( e.target ).loader;
_bitmapdata = Bitmap( loader.content ).bitmapData;
this.addChild( _canvas = new Bitmap( new BitmapData( 465, 465, true, 0x00FF0000 ) ) );
this.addChild( _outline = new Sprite() );
var u:Number = _bitmapdata.width / _n;
for ( var i:int = 0 ; i < _n ; i++ ) {
var bmp:BitmapData = new BitmapData(u, _bitmapdata.height);
bmp.copyPixels( _bitmapdata, new Rectangle( u * i, 0, u, _bitmapdata.height ), new Point() );
_pArray.push( new pt( _l / _n * i + 50, 50, bmp ) );
}
this.addEventListener( Event.ENTER_FRAME, update );
this.addEventListener( Event.ENTER_FRAME, render );
}
private function update(e:Event):void {
var p:pt;
for ( var i:int = 0 ; i < _pArray.length ; i++ ) {
p = _pArray[i];
p.y = p.yy + Math.cos( i - getTimer()/200 ) * ( 8 * ( i / _pArray.length ) * 3 );
}
}
public function render(e:Event):void {
_outline.graphics.clear();
_outline.graphics.lineStyle( 2, 0xFF0000 );
var h:int = 320;
var p:pt;
var p2:pt;
_canvas.bitmapData = new BitmapData( 465, 465, true, 0x00FF0000 );
for ( var i:int = 0 ; i < _pArray.length-1 ; i++ ) {
p = _pArray[i];
p2 = _pArray[i + 1];
var mtx:Matrix = new Matrix( ( p2.x - p.x ) / p.bmp.width, ( p2.y - p.y ) * ( p.bmp.height / h ), 0, h / p.bmp.height, p.x, p.y);
_canvas.bitmapData.draw( p.bmp, mtx, null, null, null, true );
_outline.graphics.moveTo( p.x, p.y );
_outline.graphics.lineTo( p2.x, p2.y );
_outline.graphics.lineTo( p2.x, p2.y+h );
_outline.graphics.lineTo( p.x, p.y+h );
_outline.graphics.lineTo( p.x, p.y );
}
}
}
}
import flash.display.*;
class pt {
public var x:Number;
public var y:Number;
public var xx:Number;
public var yy:Number;
public var bmp:BitmapData;
public function pt( _x:Number = 0, _y:Number = 0, _bmp:BitmapData = null ) {
this.xx = this.x = _x;
this.yy = this.y = _y;
bmp = _bmp;
}
}