Black Fire Dragon+Face+Wings
Black Fire Dragon..
There is a million and five things that don't work right.
IT IS FREAKING slow on my computer, but all that aside
this is becoming it's own evil enity.
Dragon Face: Brian "Lite Duty" Moore
Wings: Anthony "AW" Wasdas afdafsfasdfg
Progamming and editing: Dave "Leoniadas" M.
USE ARROW KEYS, PGUP & END FOR CAMERA CONTROL
CLICK TO CHANGE POV
/**
* Copyright mfc314159 ( http://wonderfl.net/user/mfc314159 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/yqux
*/
package {
//Black Fire Dragon..
//There is a million and five things that don't work right.
//IT IS FREAKING slow on my computer, but all that aside
//this is becoming it's own evil enity.
//Dragon Face: Brian "Lite Duty" Moore
//Wings: Anthony "AW" Wasdas afdafsfasdfg
//Progamming and editing: Dave "Leoniadas" M.
//USE ARROW KEYS, PGUP & END FOR CAMERA CONTROL
//CLICK TO CHANGE POV
import flash.system.Security;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
import flash.display.DisplayObject;
import flash.filters.BlurFilter;
import flash.filters.GlowFilter;
import flash.geom.Point;
import flash.display.BlendMode;
import flash.display.Sprite;
import flash.filters.BlurFilter;
import flash.filters.GlowFilter;
import org.papervision3d.cameras.Camera3D;
import org.papervision3d.materials.ColorMaterial;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.objects.*
import org.papervision3d.render.BasicRenderEngine;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.view.Viewport3D;
import org.papervision3d.core.math.Number3D;
import org.papervision3d.core.effects.*;
import org.papervision3d.core.effects.utils.*;
import org.papervision3d.view.layer.*;
import org.papervision3d.objects.*;
import org.papervision3d.view.*;
import org.papervision3d.materials.*;
import org.papervision3d.objects.primitives.*;
public class dragonBLACKWFL extends Sprite {
private var bfx:BitmapEffectLayer;
//Papervision init
private var viewport:Viewport3D;
private var scene:Scene3D;
private var renderer:BasicRenderEngine;
private var camera:Camera3D;
private var followOn:int = 1;
private var camPoint:DisplayObject3D;
private var camNum:Number3D;
private var materialsList:MaterialsList;
private var cube:Cube;
private var headR:Plane;
private var headL:Plane;
//--Everyone loves Pie
private const piE:Number = Math.PI / 180;
//--Reusuable id# to use with While loops
private var id:int = 0;
//--Number of segments
private var max:int = 25;
//--Spread of segements
private var spread:int = 1;
private var path:Array = []; //traveled path
private var _dragon:Array = []; //segment objects
private var pathID:Array = []; //segment's path ID#
//--Direction Angles
private var xAng:Number = 0.00;//= Math.random() * 180.00;
private var yAng:Number = 0.00;//= Math.random() * 180.00;
private var zAng:Number = 0.00;//= Math.random() * 180.00;
//--Turing Speeds
private var turnSpeed:Number = 1.00;
private var turnSpeedX:Number = turnSpeed / 6;
private var turnSpeedY:Number = turnSpeed / 9;
private var turnSpeedZ:Number = turnSpeed / 12;
//--Leading Path vars
private var speed:Number = 1.00;
private var course:Number3D = new Number3D();
private var origin:Number3D = new Number3D();
private var cubeSizes:Array = [];
private var pathTotal:Number = 0.00;
private var pttl:int;
private var basePath:String = "http://assets.wonderfl.net/images/related_images/";
private var headR_URL:String = basePath + "9/95/9551/95515707413d8ba1476d6f41d65064f8291dc9e3";
private var headL_URL:String = basePath + "0/0a/0af3/0af3b4a3b726056e282b8766f789e65699f0e35bm";
private var wingR_URL:String = basePath + "c/cb/cbb4/cbb4ef49a84e9740e18b46a6f70bd093be9dff13";
private var wingL_URL:String = basePath + "1/1f/1f32/1f324d5bcc8eb04d1f2d8d39ef26c693dfd8750f";
private var blkHeadR:BitmapFileMaterial;
private var blkHeadL:BitmapFileMaterial;
private var wingR:BitmapFileMaterial;
private var wingL:BitmapFileMaterial;
public function dragonBLACKWFL():void {
Security.loadPolicyFile("http://assets.wonderfl.net/crossdomain.xml");
//-------------------------MAIN INIT
//--PAPERVISION INIT
viewport = new Viewport3D();
viewport.viewportWidth = 1000;
viewport.viewportHeight = 700;
viewport.x = ( this.stage.stageWidth - viewport.viewportWidth ) / 2;
viewport.y = ( this.stage.stageHeight - viewport.viewportHeight ) / 2;
addChild(viewport);
scene = new Scene3D();
camera = new Camera3D();
camera.z = 100;
camPoint = new DisplayObject3D(null);
scene.addChild(camPoint);
renderer = new BasicRenderEngine();
//--effects INIT
//bfx.addEffect(new BitmapLayerEffect(new BlurFilter(4, 4, 1)));
var bmFireEffect:BitmapFireEffect = new BitmapFireEffect();
//bmFireEffect.blueFlame = true;
bmFireEffect.fadeRate = 0.1;
bmFireEffect.flameSpread = .7;
bmFireEffect.flameHeight = 0.7;
bmFireEffect.distortion = 0.5;
bmFireEffect.distortionScale = 0.7;
bmFireEffect.smoke = 0.3;
bfx = new BitmapEffectLayer(viewport, 1000, 700);
bfx.addEffect(bmFireEffect);
viewport.containerSprite.addLayer(bfx);
//---Dragon material BLACK AS THE BLACKEST PITCH with some alpha for cool
var blkMat:ColorMaterial = new ColorMaterial(0x000000, .3);
//var headBlkMat:ColorMaterial = new ColorMaterial(0x000000, 1);
blkHeadR = new BitmapFileMaterial(headR_URL);
blkHeadL = new BitmapFileMaterial(headL_URL);
//headBlkMat.doubleSided = true;
blkHeadR.doubleSided = true;
blkHeadL.doubleSided = true;
wingR = new BitmapFileMaterial(wingR_URL);
wingL = new BitmapFileMaterial(wingL_URL);
wingR.doubleSided = true;
wingL.doubleSided = true;
//--Add dragon material to list
materialsList = new MaterialsList();
materialsList.addMaterial(blkMat , "all");
//--------------------------------------------PATH and CUBE SIZING INIT
//--init course
course.x = speed * Math.sin(piE * xAng);
course.y = speed * Math.cos(piE * yAng);
course.z = speed * Math.sin(piE * zAng);
//Cube Size
//150
//140
//130
//120
//110
//100 dxxxxxxxxxdd
//90 d d
//80 | | | | | | | | | | |
//70 ddd d
//60 dd d
//50 xxxxxx
//40 | | | | | | | d | | |
//30 ddddddd
//20 dd
//10 ddddd
// 0 10 20 30 40 50 60 70 80 90 100
// || = 2.5% Dragon Cube Scale
// x = static sizing d = dynamic sizing
var p1:Point = new Point(0, 50);
var p2:Point = new Point(15, 50);
var p3:Point = new Point(30, 150);
var p4:Point = new Point(60, 150);
var p5:Point = new Point(70, 30);
var p6:Point = new Point(90, 20);
var p7:Point = new Point(100, 10);
id = 0;
var idF:Number;
var cs:Point = new Point();
while(id < 100) {
if((id >= 0) && (id < p2.x)) {
idF = (id - p1.x) / (p2.x - p1.x);
cs = Point.interpolate(p2, p1, idF);
}
if((id >= p2.x) && (id < p3.x)) {
idF = (id - p2.x) / (p3.x - p2.x);
cs = Point.interpolate(p3, p2, idF);
}
if((id >= p3.x) && (id < p4.x)) {
idF = (id - p3.x) / (p4.x - p3.x);
cs = Point.interpolate(p4, p3, idF);
}
if((id >= p4.x) && (id < p5.x)) {
idF = (id - p4.x) / (p5.x - p4.x);
cs = Point.interpolate(p5, p4, idF);
}
if((id >= p5.x) && (id < p6.x)) {
idF = (id - p5.x) / (p6.x - p5.x);
cs = Point.interpolate(p6, p5, idF);
}
if((id >= p6.x) && (id < p7.x)) {
idF = (id - p6.x) / (p7.x - p6.x);
cs = Point.interpolate(p7, p6, idF);
}
cubeSizes[id] = cs.y;
id++;
}
//--------------------------------------------------OBJECTS INIT
//--DRAGON
var segSize:int = 0;
//add segments to the _dragon array
//set pathIDs of segments in _dragon
id = 0;
pathTotal -= (p1.y / 2)
while(id < max) {
segSize = cubeSizes[Math.round(100 * (id / max))];
pathTotal += segSize;
//trace(id, segSize, pathTotal);
if((id != 0) && (id != 10)) {
//Add Cube for segment
_dragon[id] = new Cube(materialsList, segSize, segSize, segSize, 1, 1, 1);
_dragon[id].pitch(-90);
pathID[id] = pathTotal;//int(spread + (id * spread));
//---ADD TO EFFETS LAYER
bfx.addDisplayObject3D(_dragon[id]);
} else if(id == 10) {
_dragon[10] = new DisplayObject3D();
var wingRplane:Plane = new Plane(wingR, 600, 300, 1, 1);
var wingLplane:Plane = new Plane(wingL, 600, 300, 1, 1);
var cube10:Cube = new Cube(materialsList, segSize, segSize, segSize, 1, 1, 1);
wingRplane.pitch(90);
wingRplane.x += 350;
wingRplane.y += 50;
wingLplane.pitch(90);
wingLplane.x -= 350;
wingLplane.y += 50;
_dragon[10].pitch(90);
pathID[10] = pathTotal;//int(spread + (id * spread));
_dragon[10].addChild(wingRplane);
_dragon[10].addChild(wingLplane);
_dragon[10].addChild(cube10);
//---ADD TO EFFETS LAYER
bfx.addDisplayObject3D(wingRplane);
bfx.addDisplayObject3D(wingLplane);
bfx.addDisplayObject3D(cube10);
} else if(id == 0) {
//Add Cube with head dimensions for first segment
//_dragon[0] = new Cube(materialsList, segSize, segSize * 2, segSize, 4, 4, 4);
_dragon[0] = new DisplayObject3D();
//headR = new Plane(headBlkMat, 133, 187, 1, 1);
//headL = new Plane(headBlkMat, 133, 187, 1, 1);
headR = new Plane(blkHeadR, 133, 187, 1, 1);
headL = new Plane(blkHeadL, 133, 187, 1, 1);
headR.x += 48.5;
headL.x -= 48.5;//good enough for goverment work
headR.pitch(-33);
headL.pitch(-33);
headR.yaw(46);
headL.yaw(-46);
_dragon[0].addChild(headR);
_dragon[0].addChild(headL);
pathID[0] = Math.round(p1.y - (p1.y / 2));
//---ADD TO EFFETS LAYER
bfx.addDisplayObject3D(headR);
//---ADD TO EFFETS LAYER
bfx.addDisplayObject3D(headL);
}
scene.addChild(_dragon[id]); //add segment to scene
id++; //next id
}
pttl = Math.round(pathTotal) + 1;
id = 0;
//Fill the path array with init values
setup();
//Camera.z
stage.addEventListener(KeyboardEvent.KEY_DOWN, cameraZ);
//--Change Camera
stage.addEventListener(MouseEvent.CLICK, changeCamera);
//--Generate path from mouse input
stage.addEventListener(MouseEvent.MOUSE_MOVE, mousePath);
//--Change Speed
stage.addEventListener(MouseEvent.MOUSE_WHEEL, changeSpeed);
//--start Main Loop
stage.addEventListener(Event.ENTER_FRAME, mainLoop);
}
//------------------------------------------MOUSE INPUT HANDLERS
private function changeCamera(evt:MouseEvent):void {
followOn *= -1;
if(followOn == 1) {
camera.x = 0;
camera.y = 0;
camera.z = 100;
}
}
private function cameraZ(evt:KeyboardEvent):void {
trace(evt.keyCode, evt.keyLocation, evt.charCode);
if(evt.keyCode == 38) { camera.z += 100; }//in
if(evt.keyCode == 40) { camera.z -= 100; }//out
if(evt.keyCode == 34) { camera.y += 100; }//up
if(evt.keyCode == 35) { camera.y -= 100; }//down
if(evt.keyCode == 39) { camera.x += 100; }//right
if(evt.keyCode == 37) { camera.x -= 100; }//left
}
private function mousePath(evt:MouseEvent):void {
turnSpeedX = .02 * ((evt.stageX - 500) * .05);
turnSpeedY = .02 * ((evt.stageY - 350) * .05);
turnSpeedZ = Math.sqrt((turnSpeedX * turnSpeedX) + (turnSpeedY * turnSpeedY));
}
private function changeSpeed(evt:MouseEvent):void {
if(evt.delta > 0) { speed += .1;
} else { speed -= .1; }
//trace(speed);
}
//----------------------------------------MAIN LOOP
private function mainLoop(evt:Event):void {
//--STAGE 1: Find Next Position
//change angles
xAng += turnSpeedX;
yAng += turnSpeedY;
zAng += turnSpeedZ;
//limit angles
if(xAng > 360) { xAng = xAng - 360; }
if(yAng > 360) { yAng = yAng - 360; }
if(zAng > 360) { zAng = zAng - 360; }
//set new course
course.x = speed * Math.sin(piE * xAng);
course.y = speed * Math.cos(piE * yAng);
course.z = speed * Math.sin(piE * zAng);
//add course coordinates to current position
origin = Number3D.add(origin, course);
camNum = Number3D.add(origin, course);
camNum = Number3D.add(course, camNum);
camPoint.x = camNum.x;
camPoint.y = camNum.y;
camPoint.z = camNum.z;
_dragon[0].lookAt(camPoint);
//--STAGE 2:--Shift and Add positions to path array
//shift path positions down
path.pos.pop();
//add new positions to path
path.pos.unshift(origin);
//--STAGE 3:--Set Positions
id = 1; //reset
_dragon[0].x = path.pos[pathID[0]].x;
_dragon[0].y = path.pos[pathID[0]].y;
_dragon[0].z = path.pos[pathID[0]].z;
while(id < max) {
_dragon[id].x = path.pos[pathID[id]].x;
_dragon[id].y = path.pos[pathID[id]].y;
_dragon[id].z = path.pos[pathID[id]].z;
_dragon[id].lookAt( _dragon[id - 1] );
id++;
}
//--STAGE 4:--Render The Scene
if(followOn == 1) {
} else {
camera.x = _dragon[0].x;
camera.y = _dragon[0].y;
camera.z = _dragon[0].z - 400;
camera.lookAt(camPoint);
}
renderer.renderScene(scene, camera, viewport);
}
private function setup():void {
//fills the path array with values to cut down on inital drawing time
//--path positions array
path["pos"] = new Array(); // 3D position
path["p"] = new Array(); // pitch
path["r"] = new Array(); // roll
path["y"] = new Array(); // yaw
while(id < pttl) {
path.pos[id] = origin.clone();
path.p[id] = Number(0.00);
path.r[id] = Number(0.00);
path.y[id] = Number(0.00);
id++; //next id
}
id = 0; //reset
while(id < pttl){
//--STAGE 1
//find next position
xAng += turnSpeedX;
yAng += turnSpeedY;
zAng += turnSpeedZ;
if(xAng > 360) { xAng = xAng - 360; }
if(yAng > 360) { yAng = yAng - 360; }
if(zAng > 360) { zAng = zAng - 360; }
course.x = speed * Math.sin(piE * xAng);
course.y = speed * Math.cos(piE * yAng);
course.z = speed * Math.sin(piE * zAng);
origin = Number3D.add(origin, course);
//--STAGE 2
//shift positions down
path.pos.pop();
path.p.pop();
path.r.pop();
path.y.pop();
//add new position to path
path.pos.unshift(origin);
path.p.unshift(Number(0.00));
path.r.unshift(Number(0.00));
path.y.unshift(Number(0.00));
id++;
}
}//func
}//class
}//package