Being Colorful MediaRSS Viewer
///////////////////////////////////////////////////
最初はモノクロ //
クリックして画像を見るとサムネイルがカラフルに! //
写真を見るほどキレイになるよ! //
一定数見ると… //
見えることに感謝! //
///////////////////////////////////////////////////
以下はメモ
クリックで画像拡大表示
拡大表示画像をクリックで縮小
追加予定 → 検索機能,なんかおもしろい見せ方 loadをキレイに描写しよう
表示しているタグに関連したタグを持つ写真を展開できたらいいねw 言語処理的な
画像のロードが失敗するときれいなサークルにならない
機能 30秒で自動更新 更新する度に検索するタグを変更 指定画像の拡大縮小
真ん中のtagテキストをクリックすると回転を停止
表示されている10枚の写真を全てクリックするとカラフル火の玉出現
表示する画像のタグは大体僕が興味あるもの
/**
* Copyright YAZUMA ( http://wonderfl.net/user/YAZUMA )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/DEEf
*/
// forked from Event's Simple MediaRSS Viewer
package {
import flash.text.*;
import flash.net.*;
import flash.display.*;
import flash.display.Shape;
import flash.events.*;
import flash.display.Sprite;
import flash.filters.*;
import flash.utils.Timer;
import frocessing.color.ColorHSV;
import flash.filters.BevelFilter;
[SWF(backgroundColor=0xffffff,width=500,height=400,frameRate=30)]
public class MediaRSSReader extends Sprite {
private var biFlag:Boolean = false;
private var imgArray:Array = new Array();
private var addArray:Array = new Array();
private var fireballArray:Array = new Array();
private var s:Sprite = new Sprite();
private var s1:Sprite = new Sprite();
private var queueArray:Array = ["nature", "winter", "summer", "spring", "fall", "halloween", "japan", "chirstmas", "family","hotel",
"sunset", "ocean", "mountain", "spain", "snow", "dog", "cat", "animal", "people", "vacation", "food",
"trip", "lake", "park", "dinner", "climbing", "nepal", "building", "google", "ski", "summit", "restaurant",
"Europe", "magic_monkey", "desk", "heritage", "war", "peace", "flower", "kyoto", "star", "universe", "sky",
"house", "music", "Disney", "NewYork", "red", "blue", "green", "white", "black", "yellow", "color",
"USA", "Yaman", "Italia", "India", "Iraq", "Austria", "Guinea", "Korea", "China", "Nigeria", "Philippines", "Russia", "earth",
"water", "fire", "beautiful", "car", "train" ,"air", "now", "laugh", "simple", "coffee", "tea", "morning", "moon", "sun",
"card", "country", "coin"];
private var queue:String = queueArray[Math.floor(Math.random()*queueArray.length)];
//private var queue:String = "laugh";
private var _feed:String = "http://api.flickr.com/services/feeds/photos_public.gne?tags="+queue+"&format=rss_200";
private var media:Namespace = new Namespace("http://search.yahoo.com/mrss/");
private var images:Array = new Array();
private var t:TextField = new TextField();
private var qt:TextField = new TextField();
private var qt_degree:Number = 0;
private var timer:Timer = new Timer(1000, 30);
private var loadTimer:Timer = new Timer(1000, 2);
private var qt_c:ColorHSV = new ColorHSV();
private var first:Boolean = true;
private var text_click:Boolean = false;
private var LOADING:Boolean = true;
private var Clicked:int = 0;
public function MediaRSSReader() {
s1.filters = [new BevelFilter()];
t.defaultTextFormat = new TextFormat("Arial", 20);
t.text = "Now Loading...";
t.width = 150;
t.height = 30;
t.x = 175;
t.y = 185;
t.selectable = false;
this.addChild(t);
qt.defaultTextFormat = new TextFormat("Arial", 55);
qt.text = queue;
qt.width = 250;
qt.height = 70;
qt.x = 125;
qt.y = 120;
qt.z = 0;
qt.selectable = false;
qt.autoSize = TextFieldAutoSize.CENTER;
qt.addEventListener(MouseEvent.CLICK, Queuetouch);
qt.addEventListener(Event.ENTER_FRAME, float);
addArray.push(qt);
var ldr:URLLoader = new URLLoader;
ldr.addEventListener(Event.COMPLETE, function _load(e:Event):void {
ldr.removeEventListener(Event.COMPLETE, _load);
onImageLoaded(XML(ldr.data)..media::thumbnail.@url.toXMLString().split('\n'));
});
ldr.load(new URLRequest(_feed));
}
private function Queuetouch(e:MouseEvent):void{
if(LOADING == false)
if(text_click){
text_click = false;
timer.start();
for(var n:int = 0;n < imgArray.length;n++)
if(imgArray[n] != qt)imgArray[n].rotateFlag = true;//回転開始
}else{
text_click = true;
timer.stop();
for(n = 0;n < imgArray.length;n++)
if(imgArray[n] != qt)imgArray[n].rotateFlag = false;//回転開始
}
}
private function float(e:Event):void{
qt_degree += 2;
if(qt_degree >= 360)qt_degree = 0;
qt.y = 120 + 20 * Math.sin(Math.PI * qt_degree / 360);
qt_c.h = qt_degree;
qt.textColor = qt_c.value;
}
public function onImageLoaded($images:Array):void {
addChild(s);
s1.addEventListener(MouseEvent.CLICK, closeImage);
images = $images;
for(var n:int = 0;n < 10;n++){
if(fireballArray.length < 19)var icon:Icon = new Icon($images[n], n, true);
else icon = new Icon($images[n], n, false);
icon.addEventListener(MouseEvent.CLICK, BigImage);
imgArray.push(icon);
addArray.push(icon);
}
loadTimer.addEventListener(TimerEvent.TIMER_COMPLETE, startCircle);
loadTimer.start();
}
private function startCircle(e:TimerEvent):void{
if(first == true){
first = false;
this.removeChild(t);
}
loadTimer.stop();
loadTimer.reset();
loadTimer.removeEventListener(TimerEvent.TIMER_COMPLETE, startCircle);
for(var n:int = 0;n < imgArray.length;n++){
if(imgArray[n] != qt)imgArray[n].rotateFlag = true;//回転開始
}
this.addEventListener(Event.ENTER_FRAME, front);
timer.addEventListener(TimerEvent.TIMER_COMPLETE, Update);
timer.start();
LOADING = false;
}
private function BigImage(e:MouseEvent):void
{
if(biFlag == false){
timer.stop();
biFlag = true;
this.addChild(t);
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.INIT, s1_patch);
var icon:Icon = e.target as Icon;
if(icon.Clicked == false){
icon.Clicked == true;
Clicked++;
}
loader.load(new URLRequest(images[icon.N].split("_s").join("")));
s1.addChildAt(loader, 0);
addChild(s1);
s.filters = [rFilter(0.4)];
icon.resetFilter();
}
}
private function rFilter(n:Number):ColorMatrixFilter{
var M:Array = new Array();
M = M.concat([n, 0, 0, 0, 0]);
M = M.concat([0, n, 0, 0, 0]);
M = M.concat([0, 0, n, 0, 0]);
M = M.concat([0, 0, 0, 0.3, 0]);
return new ColorMatrixFilter(M);
}
private function s1_patch(e:Event):void{
s1.x = 250 - e.target.width / 2;
s1.y = 200 - e.target.height/ 2;
}
private function closeImage(e:MouseEvent):void{
if(biFlag){
biFlag = false;
s1.graphics.clear();
this.removeChild(t);
s1.removeChildAt(0);
s.filters = null;
timer.start();
}
}
private function front(e:Event):void{
addArray.sort(sortOnZ);
for(var i:int = 0;i < addArray.length;i++){
s.addChildAt(addArray[i] , i);
}
}
private function sortOnZ(a:Object, b:Object):Number {
var aZ:Number = a.z;
var bZ:Number = b.z;
if(aZ < bZ) {
return 1;
} else if(aZ > bZ) {
return -1;
} else {
return 0;
}
}
private function Update(e:TimerEvent):void{
for(var n:int = 0;n < Clicked / 2;n++)fireballArray.push(new ball());
Clicked = 0;
LOADING = true;
timer.stop();
timer.reset();
timer.removeEventListener(TimerEvent.TIMER_COMPLETE, Update);
for(n = 0;n < addArray.length;n++){
s.removeChildAt(0);
}
imgArray = new Array();
addArray = new Array();
addArray.push(qt);
for(n = 0;n < fireballArray.length;n++)addArray.push(fireballArray[n]);
queue = queueArray[Math.floor(Math.random()*queueArray.length)];
qt.text = queue;
_feed = "http://api.flickr.com/services/feeds/photos_public.gne?tags="+queue+"&format=rss_200";
var ldr:URLLoader = new URLLoader;
ldr.addEventListener(Event.COMPLETE, function _load(e:Event):void {
ldr.removeEventListener(Event.COMPLETE, _load);
onImageLoaded(XML(ldr.data)..media::thumbnail.@url.toXMLString().split('\n'));
});
ldr.load(new URLRequest(_feed));
}
}
}
import flash.display.*;
import flash.events.*;
import flash.filters.*;
import flash.geom.*;
import flash.net.*;
import flash.system.*;
import flash.text.*;
import flash.utils.*;
import flash.filters.BlurFilter;
class Icon extends Sprite{
private var img:Bitmap;
private var reverseImg:Bitmap;
private var initialX:Number;
private var loader:Loader;
private var loader2:Loader;
private const SIZE:int = 100;
public var degree:Number = 0;
private var sightX:Number;
private var sightY:Number;
public var Clicked:Boolean = false;
public var N:int;
public var rotateFlag:Boolean = false;
private var FilterFlag:Boolean = true;
public function Icon(str:String, n:int, _flag:Boolean):void{
img = new Bitmap();
FilterFlag = _flag
N = n;
degree = -36 * n;
x = 210;
y = 160;
z = 20 + n;
loader = new Loader();
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, function():void { } );
loader.contentLoaderInfo.addEventListener(Event.INIT,init);
loader.load(new URLRequest(str), new LoaderContext(true));
}
private function init(e:Event):void{
loader2 = new Loader();
loader2.contentLoaderInfo.addEventListener(Event.INIT, initCOMP);
loader2.loadBytes(loader.contentLoaderInfo.bytes);
}
private function initCOMP(e:Event):void{
var l:Loader = e.currentTarget.loader;
var scale:Number = 0;
if(loader.height > SIZE){
if (loader.width < loader.height) scale = SIZE / loader.height;
else scale = SIZE / loader.width;
}else{
scale = 1;
}
var matrix:Matrix = new Matrix();
matrix.scale(scale, scale);
var bd:BitmapData = new BitmapData(scale * loader.width, scale * loader.height, false);
bd.draw(l, matrix);
img = new Bitmap(bd);
addChild(img);
if(FilterFlag)img.filters = [mFilter(0.4)];
//Reflect
var reverse:BitmapData = img.bitmapData.clone();
reverseImg = new Bitmap(reverse);
reverseImg.scaleY = -1;
reverseImg.rotationX = -90;
reverseImg.x = img.x;
reverseImg.y = img.height*1.5;
addChild(reverseImg);
reverseImg.filters = [ rFilter(0.95), new BlurFilter(20, 20, 2)];
var degree:Number = 0;
addEventListener(Event.ENTER_FRAME, Circle);
}
private function Circle(e:Event):void{
if(rotateFlag){
degree-=0.5;
if(degree == -360)degree = 0;
e.target.x = 210 + 200 * Math.cos(Math.PI / 180 * degree);
e.target.y = 150 + 35 * Math.sin(Math.PI / 180 * degree);
e.target.z = -200 * Math.sin(Math.PI / 180 * degree);
}
}
private function rFilter(n:Number):ColorMatrixFilter{
var M:Array = new Array();
M = M.concat([n, 0, 0, 0, 0]);
M = M.concat([0, n, 0, 0, 0]);
M = M.concat([0, 0, n, 0, 0]);
M = M.concat([0, 0, 0, 0.3, 0]);
return new ColorMatrixFilter(M);
}
private function mFilter(n:Number):ColorMatrixFilter{
var M:Array = new Array();
M = M.concat([n, n, n, 0.2, 0]);
M = M.concat([n, n, n, 0.2, 0]);
M = M.concat([n, n, n, 0.2, 0]);
M = M.concat([0, 0, 0, 1, 0]);
return new ColorMatrixFilter(M);
}
public function resetFilter():void{
img.filters = null;
reverseImg.filters = [new BlurFilter(20, 20, 2)];
}
}
//ball制御
import flash.geom.Point;
import flash.display.*;
import flash.display.Shape;
import flash.events.*;
import flash.display.Sprite;
import flash.filters.*;
import frocessing.color.ColorHSV;
import flash.filters.BevelFilter;
class ball extends Sprite{
private var COLOR:ColorHSV = new ColorHSV();
private var _x:int = Math.floor(Math.random() * 390);
private var _y:int = Math.floor(Math.random() * 390);
private var _z:Number = -300 + Math.floor(Math.random() * 600);
private var A:Point;
private var B:Point;
private var C:Point;
private var D:Point;
private var E:Point;
private var F:Point;
private var G:Point;
private var H:Point;
private var I:Point;
private var J:Point;
private var time:Number;
public function ball():void{
z = _z;
Bezier_init();
COLOR.h = Math.floor(Math.random() * 360);
COLOR.s = 0.6;
COLOR.a = 0.5;
graphics.beginFill(COLOR.value);
graphics.drawCircle(_x, _y, 5);
filters = [new BlurFilter(5, 5, 2)];
addEventListener(Event.ENTER_FRAME, changeColor);
}
private function changeColor(e:Event):void{
COLOR.h += 0.5;
if(COLOR.h >= 360)COLOR.h = 0;
graphics.clear();
graphics.beginFill(COLOR.value);
Bezier();
}
private function Bezier():void{
E = calcPoint(A, B);
F = calcPoint(B, C);
G = calcPoint(C, D);
H = calcPoint(E, F);
I = calcPoint(F, G);
J = calcPoint(H, I);
graphics.drawCircle(J.x, J.y, 5);
_x = J.x;
_y = J.y;
z += (_z - z) / 200 * time;
time += 0.005;
if(time > 1)Bezier_init();
}
private function Bezier_init():void{
A = new Point(_x, _y);
B = new Point(Math.floor(Math.random() * 450), Math.floor(Math.random() * 450));
C = new Point(Math.floor(Math.random() * 450), Math.floor(Math.random() * 450));
D = new Point(Math.floor(Math.random() * 450), Math.floor(Math.random() * 450));
_z = -300 + Math.floor(Math.random() * 600);
time = 0;
}
private function calcPoint(p1:Point, p2:Point):Point {
return new Point(p1.x + (p2.x - p1.x) * time, p1.y + (p2.y - p1.y) * time);
}
}