Welcome to Mars
// forked from makc3d's Menger sponge
package {
import flash.display.*;
import flash.events.*;
import flash.geom.*;
import flash.net.*;
import sandy.core.*;
import sandy.core.data.*;
import sandy.core.scenegraph.*;
import sandy.primitive.*;
import sandy.materials.*;
import sandy.view.*;
[SWF(width=465,height=465)]
public class ArtSpirit extends BasicView {
public function ArtSpirit () {
super (); init (465, 465);
sphere = new Sphere ("menger", 123, 24, 24);
sphere.enableBackFaceCulling = false;
sphere.enableClipping = true;
rootNode.addChild (sphere);
camera.z = 0; camera.fov = 90; camera.near = 1e-3;
stage.quality = "low";
// Spirit Rover at Engineering Flats on Mars
var loader:Loader = new Loader;
loader.contentLoaderInfo.addEventListener (Event.COMPLETE, onLoaded);
loader.contentLoaderInfo.addEventListener (ProgressEvent.PROGRESS, onProgress);
loader.load (new URLRequest ("http://apod.nasa.gov/apod/image/1003/art_spirit.jpg"));
Wonderfl.capture_delay( 10 );
}
override public function simpleRender(pEvt:Event = null):void {
camera.rotateX = 90 * (mouseY / (465/2) - 1);
sphere.pan += 1.0; super.simpleRender (pEvt);
}
private function onProgress (e:ProgressEvent):void {
graphics.clear ();
graphics.lineStyle (2);
graphics.drawRect (80, 220, 304, 34);
graphics.lineStyle ();
graphics.beginFill (0);
graphics.drawRect (82, 222, 300 * e.bytesLoaded / (e.bytesTotal + 1e-4), 30);
graphics.endFill ();
}
private function onLoaded (e:Event):void {
graphics.clear ();
var li:LoaderInfo = LoaderInfo (e.target);
// abuse security hole in FP10
// http://wonderfl.net/code/13ee977b48920d779444c516cf7b220df5ab21b5
var loader:Loader = new Loader;
loader.contentLoaderInfo.addEventListener (Event.COMPLETE, onReady);
loader.loadBytes (li.bytes);
}
private function onReady (e:Event):void {
var li:LoaderInfo = LoaderInfo (e.target);
var bd:BitmapData = new BitmapData (li.content.width, li.content.height + 500, false, 0);
bd.draw (li.content, new Matrix (1,0,0,1,0,250)); sphere.appearance = makeBitmapAppearance (bd); render ();
}
private var sphere:Sphere;
}
}