//============================// //timeline code actionscript1 // //============================// //Robert Penner's "vector3d_class.as" can be found //here: http://www.robertpenner.com/profmx/ //========================== //grass //========================== #include "vector3d_class.as" Vector3d.prototype.createOvalPoly=function(a,b,NumPts,rotation){ var Pts=[]; var angle=2*Math.PI/NumPts; for(i=0;i<=NumPts-1;i++){ Pts.push(new Vector3d(this.x+a*Math.cos(angle*i+rotation),this.y,this.z+b*Math.sin(angle*i+rotation))); } return Pts; }; Vector3d.prototype.rotateYnew = function (angle) { with (Math) { var ca = cos(angle*Math.PI/180); var sa = sin(angle*Math.PI/180); } with (this) { var tempX = x * ca + z * sa; var tempZ = x * -sa + z * ca; } return new Vector3d(tempX,this.y,tempZ); }; MovieClip.prototype.curveToPts=function(p1,p2){ this.curveTo(p1.x,p1.y,p2.x,p2.y); }; var a1=[]; var a2=[]; var a3=[]; var a4=[]; var a5=[]; var a6=[]; var a7=[]; var a8=[]; a1o=new Vector3d(300,300,100); a1=a1o.createOvalPoly(100,100,4,0); a3o=new Vector3d(a1o.x,a1o.y-150,a1o.z); a3=a3o.createOvalPoly(80,80,6,0); a2o=new Vector3d((a1o.x+a3o.x)/2,(a1o.y+a3o.y)/2,(a1o.z+a3o.z)/2); a2=a2o.createOvalPoly(50,50,4,0); a8o=new Vector3d(a1o.x,a1o.y-20,a1o.z); a4o=new Vector3d((a3o.x+a8o.x)/2,(a3o.y+a8o.y)/2,(a3o.z+a8o.z)/2); a4=a2o.createOvalPoly(50,50,6,0); for(i=0;i<=3;i++){ a1[i].y=a1[i].y-120; } for(i=0;i<=5;i++){ a5[i]=a4[i].rotateYnew(10); a6[i]=a4[i].rotateYnew(-10); } for(i=0;i<=3;i++){ a7[i]=a2[i].rotateYnew(5); a8[i]=a2[i].rotateYnew(-5); } //project all this.lineStyle(2,0x0000FF); this.onEnterFrame=function(){ if(a1o.x<=-60){ a1o=new Vector3d(_xmouse,_ymouse,100); a1=a1o.createOvalPoly(100,100,4,0); a3o=new Vector3d(a1o.x,a1o.y-150,a1o.z); a3=a3o.createOvalPoly(80,80,6,0); a2o=new Vector3d((a1o.x+a3o.x)/2,(a1o.y+a3o.y)/2,(a1o.z+a3o.z)/2); a2=a2o.createOvalPoly(50,50,4,0); a8o=new Vector3d(a1o.x,a1o.y-20,a1o.z); a4o=new Vector3d((a3o.x+a8o.x)/2,(a3o.y+a8o.y)/2,(a3o.z+a8o.z)/2); a4=a2o.createOvalPoly(50,50,6,0); for(i=0;i<=3;i++){ a1[i].y=a1[i].y-120; } for(i=0;i<=5;i++){ a5[i]=a4[i].rotateYnew(10); a6[i]=a4[i].rotateYnew(-10); } for(i=0;i<=3;i++){ a7[i]=a2[i].rotateYnew(5); a8[i]=a2[i].rotateYnew(-5); } } else{ a1o.rotateY(_xmouse/1000); a2o.rotateY(_xmouse/1000); a3o.rotateY(_xmouse/1000); a1o.rotateZ(_ymouse/1000); a2o.rotateZ(_ymouse/1000); a3o.rotateZ(_ymouse/1000); for(i=0;i<=3;i++){ a1[i].rotateY(_xmouse/1000); a7[i].rotateY(_xmouse/1000); a8[i].rotateY(_xmouse/1000); a1[i].rotateZ(_ymouse/1000); a7[i].rotateZ(_ymouse/1000); a8[i].rotateZ(_ymouse/1000); } for(i=0;i<=5;i++){ a3[i].rotateY(_xmouse/1000); a5[i].rotateY(_xmouse/1000); a6[i].rotateY(_xmouse/1000); a3[i].rotateZ(_ymouse/1000); a5[i].rotateZ(_ymouse/1000); a6[i].rotateZ(_ymouse/1000); } } a1o.perProject(); a2o.perProject(); a3o.perProject(); for(i=0;i<=3;i++){ a1[i].perProject(); a7[i].perProject(); a8[i].perProject(); } for(i=0;i<=5;i++){ a3[i].perProject(); a5[i].perProject(); a6[i].perProject(); } this.clear(); this.lineStyle(2,0x0000FF); this.moveTo(a1o.x,a1o.y); this.curveToPts(a2o,a3o); for(i=0;i<=3;i++){ this.moveTo(a1o.x,a1o.y); this.curveToPts(a7[i],a1[i]); this.moveTo(a1o.x,a1o.y); this.curveToPts(a8[i],a1[i]); } for(i=0;i<=5;i++){ this.moveTo(a3o.x,a3o.y); this.curveToPts(a5[i],a3[i]); this.moveTo(a3o.x,a3o.y); this.curveToPts(a6[i],a3[i]); } } //========================== //cube //========================== #include "vector3d_class.as" Vector3d.prototype.createOvalPoly=function(a,b,NumPts,rotation){ var Pts=[]; var angle=2*Math.PI/NumPts; for(i=0;i<=NumPts-1;i++){ Pts.push(new Vector3d(this.x+a*Math.cos(angle*i+rotation),this.y,this.z+b*Math.sin(angle*i+rotation))); } return Pts; }; MovieClip.prototype.curveToPts=function(p1,p2){ this.curveTo(p1.x,p1.y,p2.x,p2.y); }; var p=new Vector3d(100,200,0); var q=new Vector3d(100,100,0); var x=[]; var y=[]; var z=[]; var o=new Vector3d((p.x+q.x)/2,(p.y+q.y)/2,(p.z+q.z)/2); x=p.createOvalPoly(50,50,4,0); y=q.createOvalPoly(50,50,4,0); z=o.createOvalPoly(60,60,4,0); this.lineStyle(2,0x0000FF); this.onEnterFrame=function(){ this.clear(); this.beginFill(0x00CC22,40); for(i=0;i<=3;i++){ if(Key.isDown(Key.UP)){x[i].rotateY(1); y[i].rotateY(1); z[i].rotateY(1); } if(Key.isDown(Key.DOWN)){x[i].rotateZ(1); y[i].rotateZ(1); z[i].rotateZ(1); } x[i].rotateY(_xmouse/20); y[i].rotateY(_xmouse/20); z[i].rotateY(_xmouse/20); x[i].rotateZ(_ymouse/20); y[i].rotateZ(_ymouse/20); z[i].rotateZ(_ymouse/20); x[i].perProject(); y[i].perProject(); z[i].perProject(); this.lineStyle(2,0x0000FF); this.moveTo(y[i].x,y[i].y); this.curveToPts(z[i],x[i]); } for(i=0;i<=2;i++){ this.beginFill(0x00CC22,40); this.moveTo(y[i].x,y[i].y); this.lineTo(x[i].x,x[i].y); this.lineTo(x[i+1].x,x[i+1].y); this.lineTo(y[i+1].x,y[i+1].y); } this.beginFill(0x00CC22,40); this.moveTo(y[3].x,y[3].y); this.lineTo(x[3].x,x[3].y); this.lineTo(x[0].x,x[0].y); this.lineTo(y[0].x,y[0].y); this.endFill(); } //========================== //curve //========================== //frame1 #include "vector3d_class.as" Vector3d.prototype.createOvalPoly=function(a,b,NumPts,rotation){ var Pts=[]; var angle=2*Math.PI/NumPts; for(i=0;i<=NumPts-1;i++){ Pts.push(new Vector3d(this.x+a*Math.cos(angle*i+rotation),this.y,this.z+b*Math.sin(angle*i+rotation))); } return Pts; }; MovieClip.prototype.curveToPts=function(p1,p2){ this.curveTo(p1.x,p1.y,p2.x,p2.y); }; var p=new Vector3d(100,200,0); var q=new Vector3d(100,100,0); var x=[]; var y=[]; var z=[]; var o=new Vector3d((p.x+q.x)/2,(p.y+q.y)/2,(p.z+q.z)/2); x=p.createOvalPoly(50,50,4,0); y=q.createOvalPoly(50,50,4,0); z=o.createOvalPoly(60,60,4,0); this.lineStyle(2,0x0000FF); this.onEnterFrame=function(){ this.clear(); for(i=0;i<=3;i++){ if(Key.isDown(Key.UP)){x[i].rotateY(1); y[i].rotateY(1); z[i].rotateY(1); } if(Key.isDown(Key.DOWN)){x[i].rotateZ(1); y[i].rotateZ(1); z[i].rotateZ(1); } x[i].rotateY(_xmouse/20); y[i].rotateY(_xmouse/20); z[i].rotateY(_xmouse/20); x[i].perProject(); y[i].perProject(); z[i].perProject(); this.lineStyle(2,0x0000FF); this.moveTo(y[i].x,y[i].y); this.curveToPts(z[i],x[i]);} } //frame50 #include "vector3d_class.as" Vector3d.prototype.createOvalPoly=function(a,b,NumPts,rotation){ var Pts=[]; var angle=2*Math.PI/NumPts; for(i=0;i<=NumPts-1;i++){ Pts.push(new Vector3d(this.x+a*Math.cos(angle*i+rotation),this.y,this.z+b*Math.sin(angle*i+rotation))); } return Pts; }; MovieClip.prototype.curveToPts=function(p1,p2){ this.curveTo(p1.x,p1.y,p2.x,p2.y); }; var p=new Vector3d(300,200,0); var q=new Vector3d(300,250,0); var x=[]; var y=[]; var z=[]; var o=new Vector3d((p.x+q.x)/2,(p.y+q.y)/2,(p.z+q.z)/2); x=p.createOvalPoly(50,50,4,0); y=q.createOvalPoly(50,50,4,0); z=o.createOvalPoly(60,60,4,0); this.lineStyle(2,0x0000FF); this.onEnterFrame=function(){ for(i=0;i<=3;i++){ if(Key.isDown(Key.UP)){x[i].rotateY(1); y[i].rotateY(1); z[i].rotateY(1); } if(Key.isDown(Key.DOWN)){x[i].rotateZ(1); y[i].rotateZ(1); z[i].rotateZ(1); } x[i].rotateY(_xmouse/20); y[i].rotateY(_xmouse/20); z[i].rotateY(_xmouse/20); y[i].perProject(); z[i].perProject(); this.lineStyle(2,0x0000FF); this.moveTo(y[i].x,y[i].y); this.curveToPts(z[i],x[i]);} } //frame90 #include "vector3d_class.as" Vector3d.prototype.createOvalPoly=function(a,b,NumPts,rotation){ var Pts=[]; var angle=2*Math.PI/NumPts; for(i=0;i<=NumPts-1;i++){ Pts.push(new Vector3d(this.x+a*Math.cos(angle*i+rotation),this.y,this.z+b*Math.sin(angle*i+rotation))); } return Pts; }; MovieClip.prototype.curveToPts=function(p1,p2){ this.curveTo(p1.x,p1.y,p2.x,p2.y); }; var p=new Vector3d(500,200,0); var q=new Vector3d(500,250,0); var x=[]; var y=[]; var z=[]; var o=new Vector3d((p.x+q.x)/2,(p.y+q.y)/2,(p.z+q.z)/2); x=p.createOvalPoly(50,50,4,0); y=q.createOvalPoly(50,50,4,0); z=o.createOvalPoly(60,60,4,0); this.lineStyle(2,0x0000FF); this.onEnterFrame=function(){ for(i=0;i<=3;i++){ if(Key.isDown(Key.UP)){x[i].rotateY(1); y[i].rotateY(1); z[i].rotateY(1); } if(Key.isDown(Key.DOWN)){x[i].rotateZ(1); y[i].rotateZ(1); z[i].rotateZ(1); } x[i].rotateY(_xmouse/20); y[i].rotateY(_xmouse/20); z[i].rotateY(_xmouse/20); x[i].rotateZ(_ymouse/20); y[i].rotateZ(_ymouse/20); z[i].rotateZ(_ymouse/20); x[i].perProject(); y[i].perProject(); z[i].perProject(); this.lineStyle(2,0x0000FF); this.moveTo(y[i].x,y[i].y); this.curveToPts(z[i],x[i]);} }Book: Robert Penner's Programming Macromedia Flash MX
Tuesday, April 22, 2008
examples of Robert Penner's Vector3d(AS1.0)
Friday, April 18, 2008
Robert Penner's snow effect(AS1.0)
I just make a little change to Robert Penner's original work.
source.
Book: Robert Penner's Programming Macromedia Flash MX
Thursday, April 10, 2008
Loop Enlarge effect
This is a test for my loop effect.
source:
package { import flash.display.*; import flash.events.*; import flash.geom.*; public class Panorama2D extends Sprite { var g:Sprite = new Sprite(); var image:BitmapData = new source(0,0); /*your panoramic picture - suppose to be W*(H=256)(class name "source")in the lib*/ var output:BitmapData = new BitmapData(256,256,true,0); var bounds:Rectangle = output.rect; var origin:Point = new Point(); var dx:Number = 0; var dy:Number = 0; var matrix:Matrix = new Matrix(); public function Panorama2D():void { var container:Bitmap = new Bitmap(output); addChild(container); addEventListener(Event.ENTER_FRAME,onEnterFrame); } function onEnterFrame(event:Event):void { dx = dx + (128 - mouseX) / 8; matrix.tx=dx; g.graphics.beginBitmapFill(image, matrix, true); g.graphics.drawRect(0, 0,256,256); g.graphics.endFill(); matrix.tx=0; matrix.ty=0; output.fillRect(bounds, 0); output.draw(g, matrix); g.graphics.clear(); } }//end of class }//end of package
Saturday, April 5, 2008
Panorama-2D(AS3.0)
This code(from http://lab.andre-michelle.com/) is used for displaying panoramic pictures;I just rewrited it into as3.0.
code:
package { import flash.display.*; import flash.events.*; import flash.geom.*; public class Panorama2D extends Sprite { var g:Sprite = new Sprite(); var image:BitmapData = new source(0, 0); /*your panoramic picture - suppose to be W*(H=256)(class name "source")in the lib*/ var output:BitmapData = new BitmapData(256, 256, true, 0); var bounds:Rectangle = output.rect; var origin:Point = new Point(); var dx:Number = 0; var dy:Number = 0; var matrix:Matrix = new Matrix(); public function Panorama2D():void { var container:Bitmap = new Bitmap(output); addChild(container); addEventListener(Event.ENTER_FRAME,onEnterFrame); } function onEnterFrame(event:Event):void { dx = dx + (128 - mouseX) / 8; matrix.tx=dx; g.graphics.beginBitmapFill(image, matrix, true); g.graphics.drawRect(0, 0, 256, 256); g.graphics.endFill(); matrix.tx=0; matrix.ty=0; output.fillRect(bounds, 0); output.draw(g, matrix); g.graphics.clear(); } }//end of class }//end of package
Thursday, April 3, 2008
R3D:my flash-3d engine
Here is a simple demo of my 3d engine for flash (uncompleted).
I was rewriting a Java 3D engine into action script 2.0.
However, before I complete, the great PAPERVISION3D
come out, and I heard that flash 10 will support 3D,
so I stopped this project.
Just enjoy!
Use arrow keys, space and enter key to control the camera
in order to change the view .
Ported from the source code of Developing Games in Java (Nice book to learn and start your software 3D rendering engine).
Preview of Fractal Nature Demo
(点击展开中文翻译)
纯actionscript3.0完成,未使用loader,lib也是空的。
flash9之前忙着用as2.0写3D引擎,完成了大约25%,结果备受打击——PPV与flash9-as3
的发布,让我只好放弃,差点连flash和as也放弃了。
(其实还要感谢它们让我及时摆脱幻想,现在看看swfz就明白了)
之后开始学习Direct3D,感到很是压抑,三维太难驾驭了。
一段漫长无聊的时间过后,还是回来了。
不过一切都要重新开始。
于是对照着书本,练习把过去写的小动画改写成as3.0.
好在一些还都顺利,自己还自作聪明把几个小动画整合成了这个小东西。
因为大部分代码都是匆忙之中完成的,源代码又长又乱,未经任何优化,也没有注释。
虽然几乎全部代码都是oop格式的,过于脏乱,实在不敢拿出来分享了。
其实这段动画比自己预期要做的还少很多很多,完成度最多算个50%,
但现在又有了新目标,够自己折腾一阵子,不会再有时间去完善这些代码了。
演示:http://www.geocities.com/zhoubu1988/nature/naturedemo.htm
==============================
Here is the screen snap of my Fractal Nature Demo, all created by action script3.0.
Fractal Nature is a collection of natural scenery created by action script; it is the
most impressive part of my F.L.A.S.W.F engine.
coming soon!

update:
https://flaswf.googlecode.com/svn/trunk/flaswfblog/old_homepage/naturedemo.swf
(refresh that page to get a random differnt one.)