1 Package2 {3 ImportFlash.display.Bitmap;4 ImportFlash.display.BitmapData;5 ImportFlash.display.MovieClip;6 ImportFlash.display.Sprite;7 Importflash.display.TriangleCulling;8 Importflash.events.Event;9 ImportFlash.geom.Vector3D;Ten One /** A * @author Frost.yen - * @e-mail [email protected] - * @create 2015-9-11 a.m. 10:48:09 the * - */ -[SWF (width="1024x768", height="768")] - Public classStartextureextendsSprite + { -[Embed (source="Test.jpg")] + Private var_img:class; A Private var_bmpd:bitmapdata; at Private var_pointcontainer:sprite; - Private var_graphiccontainer:sprite; - Private var_pointarr:array = []; - Private var_objarr:array = []; - Private var_num:int = 5; - Private var_boo:Boolean;//is the vertex closer to the center point of the Pentagram in Private var_RADIUS1: Number= 100;//distance of the center point of the pentagram from the farther vertex (can be regarded as the radius of the Pentagram circumscribed circle) - Private var_RADIUS2: Number= 40;//the distance of the center point of the pentagram from the nearer vertex (can be regarded as the radius of the inner circle of the pentagram) to Private var_focus: Number= 400; + Public functionstartexture () - { the initviews (); * initeventlisteners (); $ }Panax Notoginseng Private functionInitviews ():void - { the_pointcontainer =NewSprite (); +_graphiccontainer =NewSprite (); A_pointcontainer.x = _graphiccontainer.x = This. stage.stagewidth*0.5; the_pointcontainer.y = _graphiccontainer.y = This. stage.stageheight*0.5; +_BMPD = (New_img () as Bitmap). BitmapData; - This. AddChild (_pointcontainer); $ This. AddChild (_graphiccontainer); $ Createstar (); - } - Private functionIniteventlisteners ():void the { - This. AddEventListener (event.enter_frame,onenterframe);Wuyi } the Private functionOnenterframe (e:event):void{ - for(vari:int=0;i<_pointarr.length;i++){ Wu_pointarr[i]. Z = (_pointarr[i] AsMovieClip). Transform.getrelativematrix3d (_pointcontainer). position.z; -_pointarr[i]. X = (_pointarr[i] AsMovieClip). Transform.getrelativematrix3d (_pointcontainer). position.x* (_focus/(_focus+_pointarr[i]. Z)); About_pointarr[i]. Y = (_pointarr[i] AsMovieClip). Transform.getrelativematrix3d (_pointcontainer). position.y* (_focus/(_focus+_pointarr[i]. Z)); $(_pointarr[i] AsMovieClip). Transform.matrix3D.appendRotation ((mousex-_pointcontainer.x)/50,vector3d.y_axis); -(_pointarr[i] AsMovieClip). Transform.matrix3D.appendRotation ((_pointcontainer.y-mousey)/50,vector3d.x_axis); - } - _graphiccontainer.graphics.clear (); A_objarr = []; + for(i=0;i<_num*2;i++){ the varvertices:vector.< Number> =Newvector.< Number>(); -Vertices.push (_pointarr[_num*2]. X,_POINTARR[_NUM*2]. Y,_pointarr[i]. X,_pointarr[i]. y,_pointarr[(i+1)% (_num*2)]. x,_pointarr[(i+1)% (_num*2)]. y,_pointarr[(i+2)% (_num*2)]. x,_pointarr[(i+2)% (_num*2)]. Y); $ varIndices:vector.<int> =NewVector.<int> ([0,1,2,0,2,3]); the varuvtdata:vector.< Number> = vector.< Number> ([0,0,1,0,1,1,0,1]);//cannot new, if new causes run Flash.display.Graphics.drawTriangles () Run Error: Argumenterror:error #2004: An argument is invalid. Tel me why? the varZ: Number= _pointarr[i]. Z + _pointarr[(i+1)% (_num*2)]. Z; the _objarr.push ({v:vertices,i:indices,u:uvtdata,z:z}); the } -_objarr.sorton ("Z", 18); in for(I =0;i<_objarr.length;i++){ the _graphiccontainer.graphics.beginbitmapfill (_BMPD); the _graphiccontainer.graphics.drawtriangles (_objarr[i]. V,_objarr[i]. I,_objarr[i]. U,triangleculling.none); About _graphiccontainer.graphics.endfill (); the } the } the Private functionCreatestar ():void + { - for(varI:int = 0;i<_num*2;i++){ the varMc:MovieClip=New MovieClip();Bayi _pointcontainer.addchild (MC); the if(_boo) { theMc.x=_radius2*math.cos (2*math.pi/(_num*2) *i); -Mc.y=_radius2*math.sin (2*math.pi/(_num*2) *i); -}Else{ theMc.x=_radius1*math.cos (2*math.pi/(_num*2) *i); theMc.y=_radius1*math.sin (2*math.pi/(_num*2) *i); the } themc.z = 0; - _pointarr.push (MC); the_boo =!_boo; the } the varCENTERMC:MovieClip=New MovieClip();94 _pointcontainer.addchild (CENTERMC); thecentermc.x = 0;CENTERMC.Y = 0;centermc.z =-60; the _pointarr.push (CENTERMC); the }98 } About}
[ActionScript 3.0] AS3 3D Star Map