flash on 2009-5-31
/**
* Copyright hacker_eaq6gj3a ( http://wonderfl.net/user/hacker_eaq6gj3a )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/4qaB
*/
package
{
import caurina.transitions.Tweener;
import flash.display.Sprite;
import flash.events.Event;
import flash.filters.BlurFilter;
import flash.utils.setInterval;
import flash.utils.escapeMultiByte;
import flash.xml.*;
import flash.net.*;
import org.papervision3d.cameras.Camera3D;
import org.papervision3d.materials.special.Letter3DMaterial;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.render.BasicRenderEngine;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.typography.Text3D;
import org.papervision3d.typography.fonts.HelveticaBold;
import org.papervision3d.view.Viewport3D;
import org.papervision3d.view.layer.ViewportLayer;
import com.adobe.serialization.json.*;
[SWF(width="465", height="465", backgroundColor="0x000000", frameRate="40")]
public class PV3D_sample03 extends Sprite
{
private var container:Sprite;
private var viewport:Viewport3D;
private var scene:Scene3D;
private var camera:Camera3D;
private var render:BasicRenderEngine;
private var rootNode:DisplayObject3D;
private var words1:Text3D;
private var words2:Text3D;
private var words3:Text3D;
private var theta:Number;
private var delayTime:Number;
private var WordMoveType:Number;
private var text:Array;
private var loader:URLLoader = new URLLoader();
private const zoom:Number=20;
private const focus:Number=30;
private const distance:Number=600;
private const searchWord:String = "leehospital";
public function PV3D_sample03()
{
Wonderfl.capture(stage);
loader.load(new URLRequest("http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q="+escapeMultiByte(searchWord)));
loader.addEventListener(Event.COMPLETE,loadComplete);
}
private function dispersionWords(words:Text3D):void
{
for each(var word:DisplayObject3D in words.letters)
{
word.extra={x:word.x, y:word.y, z:word.z};
word.x=word.y=word.z=word.scale=0;
Tweener.addTween(word, {scale:1, x:Math.random() * 2000 - 1000, y:Math.random() * 2000 - 1000, z:Math.random() * 2000 - 1000, rotationX:Math.random() * 360, rotationY:Math.random() * 360, rotationZ:Math.random() * 360, time:3, delay:2 * Math.random() + 1});
}
}
private function moveWords():void
{
if (WordMoveType % 2 == 0)
{
resetWords(words1);
resetWords(words2);
resetWords(words3);
delayTime=0;
WordMoveType++;
}
else
{
breakWords(words1);
breakWords(words2);
breakWords(words3);
WordMoveType++;
}
}
private function resetWords(words:Text3D):void
{
for each(var word:DisplayObject3D in words.letters)
{
Tweener.addTween(word, {x:word.extra.x, y:word.extra.y, z:word.extra.z, rotationX:0, rotationY:0, rotationZ:0, time:1, transition:"easeOutBounce", delay:delayTime});
Tweener.addTween(word, {rotationY:720, time:1, delay:delayTime + 2});
delayTime+=0.1;
}
}
private function breakWords(words:Text3D):void
{
for each(var word:DisplayObject3D in words.letters)
{
Tweener.addTween(word, {x:Math.random() * 2000 - 1000, y:Math.random() * 2000 - 1000, z:Math.random() * 2000 - 1000, rotationX:Math.random() * 360, rotationY:Math.random() * 360, rotationZ:Math.random() * 360, time:4, delay:3 * Math.random()});
}
}
private function onFrame(e:Event):void
{
camera.x=distance * Math.sin(theta * Math.PI / 180);
camera.z=distance * Math.cos(theta * Math.PI / 180);
theta+=(mouseX-(465/2))*0.005;
setBlur(words1);
setBlur(words2);
setBlur(words3);
render.renderScene(scene, camera, viewport);
}
private function DistanceFromCamera(obj:DisplayObject3D):Number
{
var vecX:Number=obj.sceneX - camera.x;
var vecY:Number=obj.sceneY - camera.y;
var vecZ:Number=obj.sceneZ - camera.z;
return Math.sqrt((vecX * vecX) + (vecY * vecY) + (vecZ * vecZ));
}
private function setBlur(words:Text3D):void
{
for each(var word:DisplayObject3D in words.letters)
{
var vpl:ViewportLayer=word.createViewportLayer(viewport, true);
var d:Number=Math.abs(DistanceFromCamera(word) - distance) / 40;
vpl.filters=[new BlurFilter(d, d, 1)];
}
}
private function loadComplete(e:Event):void {
Wonderfl.capture(stage);
text = new Array();
var json:Object = JSON.decode(e.target.data as String);
for(var i:uint = 0; i < 3; i++){
text[i] = json.responseData.results[i].unescapedUrl;
}
theta=0;
WordMoveType=0;
delayTime=0;
container=new Sprite();
addChild(container);
container.x=stage.stageWidth / 2;
container.y=stage.stageHeight / 2;
viewport=new Viewport3D(0, 0, true, true);
scene=new Scene3D();
camera=new Camera3D();
render=new BasicRenderEngine();
rootNode=scene.addChild(new DisplayObject3D("rootNode"));
addChild(viewport);
camera.target=DisplayObject3D.ZERO;
camera.zoom=zoom;
camera.focus=focus;
var mat:Letter3DMaterial=new Letter3DMaterial();
mat.fillColor=0xFFFFFF;
mat.doubleSided=true;
mat.doubleSided=mat.interactive=true;
words1=new Text3D(text[0], new HelveticaBold(), mat);
words2=new Text3D(text[1], new HelveticaBold(), mat);
words3=new Text3D(text[2], new HelveticaBold(), mat);
rootNode.addChild(words1);
rootNode.addChild(words2);
rootNode.addChild(words3);
words1.y=50;
words2.y=0;
words3.y=-50;
words1.scale=words2.scale=words3.scale=0.4;
dispersionWords(words1);
dispersionWords(words2);
dispersionWords(words3);
setInterval(moveWords, 10000);
addEventListener(Event.ENTER_FRAME, onFrame);
}
}
}