GradationType-Frocessing Powered by Adobe kuler
forkeボタンがもうなかったので
こちらをお借りして自己確認用テスト
http://wonderfl.net/code/7ed2d650b9d513edf9a499fb704c19ecb7aa4694
[ GradationType-Frocessing Powered by Adobe kuler ]
*
* @author : +light <9hundred.net>
*
* Adobe kuler API の Highest Rated Themes から
* 2種類のテーマをチョイスしてFrocessingでグラデーション
*
/**
* Copyright ninehundred ( http://wonderfl.net/user/ninehundred )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/x2db
*/
// forked from checkmate's Saqoosha challenge for amateurs
//
// forkeボタンがもうなかったので
// こちらをお借りして自己確認用テスト
// http://wonderfl.net/code/7ed2d650b9d513edf9a499fb704c19ecb7aa4694
/**
* [ GradationType-Frocessing Powered by Adobe kuler ]
*
* @author : +light <9hundred.net>
*
* Adobe kuler API の Highest Rated Themes から
* 2種類のテーマをチョイスしてFrocessingでグラデーション
*
*/
package
{
import flash.display.*;
import flash.events.*;
import flash.system.*;
import flash.text.*;
import flash.utils.*;
import flash.geom.*;
import flash.net.*;
import com.flashdynamix.motion.*;
import fl.motion.easing.*;
[SWF(width=465, height=465, backgroundColor=0xFFFFFF, frameRate=60)]
public class FrocessingTest extends Sprite
{
// ================================================== //
// パラメーター
// ================================================== //
private var Upper :Sprite;
private var Lower :Sprite;
private const SW :int = 465;
private const SH :int = 465;
private const KulerURL :String = 'http://kuler-api.adobe.com//feeds/rss/get.cfm?timeSpan=0&listType=rating';
private var _colorList :Array =
[
0xb2b2b2, 0xf8f8f8, 0x8bdbe8, 0x9ab8e9, 0xe5e5ff, 0xf6e7ff, 0xe89b9b, 0xe5da8e,
0xf1f4d4, 0xbfd774, 0x66c08f, 0xc5f4eb, 0x8bc9bf, 0x9b9bbf, 0xc8c0d6, 0xb2b2b2,
];
private const _infoList :Array = [ 'NOW LOADING', 'NOW LOADING.', 'NOW LOADING..', 'NOW LOADING...' ];
private var _infoID :Timer;
private var _infoTf :TextField;
private var _infoCnt :int = 0;
private var _kulerLoader :URLLoader;
private var _gradationBmp :Bitmap;
private var _timeID :Timer;
// ================================================== //
// コンストラクタ&準備
// ================================================== //
public function FrocessingTest()
{
if(stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init():void
{
Wonderfl.disable_capture();
removeEventListener(Event.ADDED_TO_STAGE, init);
Upper = addChildAt(new Sprite(), 0) as Sprite;
Lower = addChildAt(new Sprite(), 0) as Sprite;
// ロード中をアナウンス
initInformation();
initStage(); // ステージの基本設定準備
getKuler(); // kulerからXMLを取得
}
/**
* NOW LOADING
*/
// ================================================== //
// NOW LOADINGを表示
// ================================================== //
private function initInformation():void
{
_infoTf = addChild(addText(_infoList[_infoCnt])) as TextField;
_infoTf.x = int(SW/2) - int(_infoTf.width/2);
_infoTf.y = int(SH/2) - int(_infoTf.height/2);
_infoID = new Timer(1000/5);
_infoID.addEventListener(TimerEvent.TIMER, setInformation);
_infoID.start();
}
private function setInformation(e:TimerEvent=null):void
{
_infoCnt = _infoCnt+1 >= _infoList.length ? 0 : _infoCnt+1;
_infoTf.text = _infoList[_infoCnt];
}
private function clearInformation():void
{
_infoID.reset();
_infoID.removeEventListener(TimerEvent.TIMER, setInformation);
_infoID = null;
removeChild(_infoTf); _infoTf=null;
}
/**
* LOAD KULER XML DATA & PARSE
*/
// ================================================== //
// kuler highest rated themesを取得
// ================================================== //
private function getKuler():void
{
//Security.loadPolicyFile("http://kuler.adobe.com/crossdomain.xml");
_kulerLoader = new URLLoader();
_kulerLoader.dataFormat = URLLoaderDataFormat.TEXT;
_kulerLoader.addEventListener(Event.COMPLETE, loadedKuler);
_kulerLoader.addEventListener(IOErrorEvent.IO_ERROR, errorKuler);
_kulerLoader.load(new URLRequest(KulerURL));
}
private function loadedKuler(e:Event=null):void
{
// NOW LOADINGを削除
clearInformation();
// パースの仕方はこちらをお借りしました(http://www.mrlittlebig.com/blog/034/)
var myXml:XML = new XML(e.target.data);
var colorList:Array = [];
for each(var items:XML in myXml..item)
{
var kuler:Namespace = myXml.namespace("kuler");
var arr:Array = [];
for each(var swatch:XML in items.kuler::themeItem[0].kuler::themeSwatches[0].kuler::swatch)
{
var colorStr:String = swatch.kuler::swatchHexColor[0];
arr.push(Number("0x" + colorStr));
}
colorList.push(arr);
}
// ちょっとここブサイク...(シャッフルして2テーマ+最初の色)
colorList = shuffle(colorList);
_colorList = [];
for(var i:int=0; i<2; i++)
{
var list:Array = colorList[i]
for(var j:int=0; j<list.length; j++) _colorList.push(list[j]);
}
_colorList.push(colorList[0][0])
// レンダリングスタート
go();
// 後片付け
myXml = null; colorList=null;
_kulerLoader.removeEventListener(Event.COMPLETE, loadedKuler);
_kulerLoader.removeEventListener(IOErrorEvent.IO_ERROR, errorKuler);
_kulerLoader = null;
}
private function errorKuler(e:IOErrorEvent=null):void
{
// NOW LOADINGを削除
clearInformation();
// デフォルトのカラー配列を用いてレンダリングスタート
go();
// 後片付け
_kulerLoader.removeEventListener(Event.COMPLETE, loadedKuler);
_kulerLoader.removeEventListener(IOErrorEvent.IO_ERROR, errorKuler);
_kulerLoader = null;
}
/**
* MAIN METHOD
*/
// ================================================== //
// Render
// ================================================== //
private function go():void
{
Lower.alpha = 0;
var grad:Gradation = new Gradation(_colorList);
for (var y:int = 0; y < 465; y++)
{
// getColorでグラデーションを構成する中間色を取り出す。
// 渡す値は0〜1。滑らかにこの値を変化させることでグラデーションを作り出す。
Lower.graphics.beginFill(grad.getColor(y/464));
Lower.graphics.drawRect(0, y, 465, 1);
Lower.graphics.endFill();
}
var tween:TweensyTimeline = Tweensy.to(Lower, {alpha:1}, 1, Sine.easeInOut, 0.25);
}
/**
* COMMON METHOD
*/
// ================================================== //
// ステージ設定
// ================================================== //
private function initStage():void
{
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.quality = StageQuality.HIGH;
stage.displayState = StageDisplayState.NORMAL;
stage.frameRate = 60;
stage.showDefaultContextMenu = false;
}
// ================================================== //
// テキスト
// ================================================== //
public function addText(txt:String, obj:Object=null):TextField
{
var prop:Object = obj ? obj : { font:'_ゴシック', size:10, color:0xCC0000 };
var tf:TextField = new TextField();
tf.defaultTextFormat = new TextFormat(prop['font'], prop['size'], prop['color']);
tf.selectable = false;
tf.autoSize = TextFieldAutoSize.LEFT;
tf.text = txt;
return tf;
}
// ================================================== //
// 配列のシャッフル
// ================================================== //
private function shuffle(_arr:Array):Array
{
var arr:Array = [];
arr = _arr;
var i:Number = arr.length;
while (i--)
{
var j:Number = Math.floor(Math.random()*(i+1));
var t:* = arr[i];
arr[i] = arr[j];
arr[j] = t;
}
return arr;
}
}
}
import frocessing.color.ColorLerp;
import org.libspark.betweenas3.core.easing.IEasing;
import org.libspark.betweenas3.easing.Linear;
class Gradation
{
private var _colors:Array;
private var _easing:IEasing;
public function Gradation(list:Array)
{
_colors = list;//args.concat();
_easing = Linear.linear;
}
public function setEasing(easing:IEasing):void
{
_easing = easing;
}
public function getColor(position:Number):uint
{
position = (position < 0 ? 0 : position > 1 ? 1 : position) * (_colors.length - 1);
var idx:int = position;
var alpha:Number = _easing.calculate(position - idx, 0, 1, 1);
if (alpha == 0)
{
return _colors[idx];
}
else
{
return ColorLerp.lerp(_colors[idx], _colors[idx + 1], alpha);
}
}
}