Earth (2)
Earth (2)
Earth (Sprite) [Papervision3D]
ActionScript3 source code
/**
* Copyright ProjectNya ( http://wonderfl.net/user/ProjectNya )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/7tKm
*/
////////////////////////////////////////////////////////////////////////////////
// Earth (2)
// Earth (Sprite) [Papervision3D]
////////////////////////////////////////////////////////////////////////////////
package {
import flash.display.Sprite;
import flash.display.StageScaleMode;
import flash.display.StageAlign;
import flash.ui.Keyboard;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.system.Security;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.cameras.Camera3D;
import org.papervision3d.view.Viewport3D;
import org.papervision3d.render.BasicRenderEngine;
import org.papervision3d.materials.BitmapFileMaterial;
import org.papervision3d.objects.primitives.Sphere;
[SWF(backgroundColor="#000000", width="465", height="465", frameRate="30")]
public class Main extends Sprite {
private var scene:Scene3D;
private var camera:Camera3D;
private var viewport:Viewport3D;
private var renderer:BasicRenderEngine;
//
private var basePath:String = "http://assets.wonderfl.net/images/related_images/";
private var filePath:String = "9/98/9880/98804c60f1a9b901909a93c2f28e384c8f70808c";
private var degrees_int:int = 60;
private var centerx_int:int = 0;
private var centerz_int:int = 0;
private var diameter_int:int = 2000;
private var speed_int:int = 1;
private var earth:Sphere;
public function Main() {
Security.allowDomain("assets.wonderfl.net");
Security.loadPolicyFile("http://assets.wonderfl.net/crossdomain.xml");
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
init();
}
private function init():void {
graphics.beginFill(0x000000);
graphics.drawRect(0, 0, 465, 465);
graphics.endFill();
//
scene = new Scene3D();
camera =new Camera3D();
camera.focus = 500;
camera.zoom = 3;
camera.x = 0;
camera.y = 0;
camera.z = -8000;
viewport = new Viewport3D(0, 0, true, false);
addChild(viewport);
renderer = new BasicRenderEngine();
addEventListener(Event.ENTER_FRAME, render, false, 0, true);
//
var material:BitmapFileMaterial = new BitmapFileMaterial(basePath + filePath);
earth = new Sphere(material, 100, 30, 30);
earth.useOwnContainer = true;
scene.addChild(earth);
//
stage.addEventListener(KeyboardEvent.KEY_DOWN, press, false, 0, true);
}
private function render(evt:Event):void {
earth.x = Math.sin(degrees_int * Math.PI/180) * diameter_int + centerx_int;
earth.z = Math.cos(degrees_int * Math.PI/180) * diameter_int + centerz_int;
earth.rotationY += 4;
degrees_int += speed_int;
degrees_int %= 360;
renderer.renderScene(scene, camera, viewport);
}
private function press(evt:KeyboardEvent):void {
switch (evt.keyCode) {
case 39 :
camera.y += 100;
break;
case 37 :
camera.y -=100;
break;
case 38 :
camera.z += 100;
break;
case 40 :
camera.z -= 100;
break;
}
}
}
}