画像を自由変形する
オブジェクトを曲げて表示する。
@author SIBA
// write as3 code here..
package {
import __AS3__.vec.Vector;
import flash.display.Bitmap;
import flash.display.Graphics;
import flash.display.Sprite;
import flash.display.BitmapData;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.events.Event;
import flash.net.URLRequest;
import flash.system.LoaderContext;
import flash.system.Security;
[SWF(width=800, height=600, backgroundColor=0xAADDFF)]
/**
* オブジェクトを曲げて表示する。
* @author SIBA
*/
public class Main03 extends Sprite {
private var image:Bitmap;
private var loader:Loader;
private var bendImage:Sprite = new Sprite();
public function Main03() {
Security.loadPolicyFile("http://farm2.static.flickr.com/crossdomain.xml");
var context:LoaderContext = new LoaderContext(true);
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
loader.load(new URLRequest("http://farm4.static.flickr.com/3180/3115974098_d1b27674ef.jpg?v=0"), context);
bendImage.x = 100;
bendImage.y = 100;
addChild(bendImage);
}
private function onComplete(event:Event):void {
var loaderInfo:LoaderInfo = event.currentTarget as LoaderInfo;
var loader:Loader = loaderInfo.loader;
var bmp:BitmapData = new BitmapData(loader.width, loader.height, true, 0x00FFFFFF);
bmp.draw(loader);
image = new Bitmap(bmp);
createBendImage();
}
private function createBendImage():void {
var vertices:Vector.<Number> = new Vector.<Number>();
var indices:Vector.<int> = new Vector.<int>();
var uvtData:Vector.<Number> = new Vector.<Number>();
for (var xx:int=0; xx<10; xx++) {
for (var yy:int=0; yy<10; yy++) {
vertices[vertices.length] = xx*50-(5-yy)*(5-yy)*5;
vertices[vertices.length] = yy*50-(5-xx)*(5-xx)*5;
uvtData[uvtData.length] = xx/10;
uvtData[uvtData.length] = yy/10;
}
}
for (var i:int=0; i<10-1; i++) {
for (var j:int=0; j<10-1; j++) {
indices.push(i*10+j, i*10+j+1, (i+1)*10+j);
indices.push(i*10+j+1, (i+1)*10+1+j, (i+1)*10+j);
}
}
const g:Graphics = bendImage.graphics;
g.beginBitmapFill(image.bitmapData);
g.drawTriangles(vertices, indices, uvtData);
g.endFill();
}
}
}