forked from: [1日1Wonderfl]7日目: FlyHigh
1日1Wonderfl 7/30日目
Bitmap なんかの色分解をどうやったら出来るのかやってみたよ。
* 画像はチンカスの人のを拝借しちゃいました。カッコ良いよね :-D
*
* @see http://www.flickr.com/photos/b7ue/3453477278/
* @see http://wonderfl.kayac.com/code/381f195b4aad8c2a14fc00ad03f638df25568a5d
* @see http://wonderfl.kayac.com/code/54ceedfdf45f70cf2aefac5dc6d2c11793b71053
// forked from soundkitchen's [1日1Wonderfl]7日目: FlyHigh
// 1日1Wonderfl 7/30日目
/**
* Bitmap なんかの色分解をどうやったら出来るのかやってみたよ。
* 画像はチンカスの人のを拝借しちゃいました。カッコ良いよね :-D
*
* @see http://www.flickr.com/photos/b7ue/3453477278/
* @see http://wonderfl.kayac.com/code/381f195b4aad8c2a14fc00ad03f638df25568a5d
* @see http://wonderfl.kayac.com/code/54ceedfdf45f70cf2aefac5dc6d2c11793b71053
*/
package
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.BitmapDataChannel;
import flash.display.BlendMode;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageQuality;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.events.SecurityErrorEvent;
import flash.geom.ColorTransform;
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.net.URLRequest;
import flash.system.LoaderContext;
import com.flashdynamix.utils.SWFProfiler;
import frocessing.color.ColorHSV;
import frocessing.color.ColorRGB;
import org.libspark.betweenas3.BetweenAS3;
import org.libspark.betweenas3.easing.*;
[SWF(width=465, height=465, frameRate=30, backgroundColor=0x000000)]
public class Main extends Sprite
{
public static const NUM_SEPARATORS:uint = 15;
public static const IMAGE_URL:String = 'http://farm4.static.flickr.com/3348/3453477278_6e6063a6ee.jpg';
public function Main()
{
addEventListener(Event.ADDED_TO_STAGE, initialize);
}
private function initialize(evt:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE, initialize);
stage.align = StageAlign.TOP_LEFT;
stage.quality = StageQuality.HIGH;
stage.scaleMode = StageScaleMode.NO_SCALE;
SWFProfiler.init(this);
var req:URLRequest,
ctx:LoaderContext,
loader:Loader;
req = new URLRequest(IMAGE_URL);
ctx = new LoaderContext(true);
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
loader.load(req, ctx);
}
private function loadComplete(evt:Event):void
{
var i:uint,
rs:uint, gs:uint, bs:uint,
ds:int, dx:int, dy:int,
sx:Number, sy:Number,
ex:Number, ey:Number,
cAngle:Number, nAngle:Number, length:uint,
rect:Rectangle,
info:LoaderInfo,
original:BitmapData,
destination:BitmapData,
bm:Bitmap, sp:Sprite,
rgb:ColorRGB,
rgbList:Vector.<ColorRGB>;
info = LoaderInfo(evt.target);
original = Bitmap(info.content).bitmapData;
ds = Math.min(original.width, original.height) >> 0;
dx = (original.width - ds) >> 1;
dy = (original.height - ds) >> 1;
rect = new Rectangle(dx, dy, ds, ds);
rs = gs = bs = 0;
rgbList = new Vector.<ColorRGB>(NUM_SEPARATORS, true);
for (i=0; i<NUM_SEPARATORS; i++)
{
rgb = new ColorHSV(360 * i / NUM_SEPARATORS, 1, 1).toRGB();
rs += rgb.r;
gs += rgb.g;
bs += rgb.b;
rgbList[i] = rgb;
}
cAngle = 0;
nAngle = Math.PI * 2 / NUM_SEPARATORS;
length = 500;
ex = stage.stageWidth >> 1;
ey = stage.stageHeight >> 1;
for (i=0; i<NUM_SEPARATORS; i++)
{
rgb = rgbList[i];
sx = ex + Math.cos(cAngle) * length;
sy = ey + Math.sin(cAngle) * length;
destination = new BitmapData(ds, ds, true, 0);
destination.copyPixels(original, rect, new Point());
destination.colorTransform(destination.rect, new ColorTransform(rgb.r/rs, rgb.g/gs, rgb.b/bs, 1, 0, 0, 0, 0));
bm = new Bitmap(destination);
bm.x -= bm.width >> 1;
bm.y -= bm.height >> 1;
sp = new Sprite();
sp.addChild(bm);
sp.blendMode = BlendMode.ADD;
BetweenAS3.serial(
BetweenAS3.tween(sp, {x: ex, y: ey}, {x: sx, y: sy}, 3, Expo.easeOut),
BetweenAS3.tween(sp, {x: sx, y: sy}, {x: ex, y: ey}, 2, Expo.easeIn, 1)
).play();
addChild(sp);
cAngle += nAngle;
}
original.dispose();
info.loader.unload();
}
}
}