package { import flash.display.Sprite; import flash.display.LineScaleMode; import flash.events.MouseEvent; import flash.geom.PerspectiveProjection; import flash.geom.Utils3D; import flash.geom.Vector3D; import flash.geom.Matrix3D; import flash.geom.*; import flash.events.Event; import flash.utils.Dictionary; import flash.display.GraphicsPath; import flash.display.IGraphicsData; import flash.display.GraphicsStroke; import flash.display.GraphicsSolidFill; import flash.display.JointStyle; import flash.display.CapsStyle; import flash.display.StageAlign; import flash.display.StageScaleMode; [SWF(backgroundColor="0x000000", width="800", height="600", frameRate="30")] public class dandelion_final extends Sprite { public function dandelion_final() { init(); } private function init():void { stage.align = StageAlign.TOP_LEFT; stage.scaleMode = StageScaleMode.NO_SCALE; // 25 lines begins here! var vertices:Vector. = new Vector.(); var pvts:Vector. = new Vector.(); var spores:Vector. = new Vector.(); var sporesDct:Dictionary = new Dictionary(true); for(var lat:Number= 0; lat < Math.PI; lat+=0.01){ vertices.push( 10*Math.cos(lat*50)*Math.sin(lat), 10*Math.cos(lat), 10*Math.sin(lat*50)*Math.sin(lat), 70*Math.cos(lat*50)*Math.sin(lat), 70*Math.cos(lat), 70*Math.sin(lat*50)*Math.sin(lat), (70 + 10)*Math.cos(lat*50-Math.random()*0.1)*Math.sin(lat-Math.random()*0.05), (70 + 10)*Math.cos(lat-Math.random()*0.05), (70 + 10)*Math.sin(lat*50-Math.random()*0.1)*Math.sin(lat-Math.random()*0.05), (70 + 10)*Math.cos(lat*50+Math.random()*0.1)*Math.sin(lat-Math.random()*0.05), (70 + 10)*Math.cos(lat-Math.random()*0.05), (70 + 10)*Math.sin(lat*50+Math.random()*0.1)*Math.sin(lat-Math.random()*0.05), (70 + 10)*Math.cos(lat*50+Math.random()*0.1)*Math.sin(lat+Math.random()*0.05), (70 + 10)*Math.cos(lat+Math.random()*0.05), (70 + 10)*Math.sin(lat*50+Math.random()*0.1)*Math.sin(lat+Math.random()*0.05), (70 + 10)*Math.cos(lat*50-Math.random()*0.1)*Math.sin(lat+Math.random()*0.05), (70 + 10)*Math.cos(lat+Math.random()*0.05), (70 + 10)*Math.sin(lat*50-Math.random()*0.1)*Math.sin(lat+Math.random()*0.05)); spores[spores.push(addChild(new Sprite()))-1].transform.matrix = new Matrix(1,0,0,1,stage.stageWidth/2,stage.stageHeight/2); sporesDct[spores[spores.length-1]] = {xp:70*Math.cos(lat*50)*Math.sin(lat),yp:70*Math.cos(lat),zp:70*Math.sin(lat*50)*Math.sin(lat), firstVertex: vertices.length-18, lastVertex: vertices.length-1, velocity: {xv:0, yv:0, zv:0, xr:0, yr:0, zr:0} }; spores[spores.length-1].addEventListener(MouseEvent.MOUSE_OVER, function(event:MouseEvent):void {sporesDct[event.target]["velocity"]={xv:Math.random()*2 - 1, yv:Math.random()*2 - 1, zv:Math.random()*2 - 1, xr:Math.random()*2 - 1, yr:Math.random()*2 - 1, zr:Math.random()*2 - 1}}); } addEventListener(Event.ENTER_FRAME, function(event:Event):void { var m:Matrix3D = new PerspectiveProjection().toMatrix3D(); m.prependTranslation(0,0,10); spores.forEach(function(spore:Sprite, ind:int, a:Vector.):void { var spv:Vector. = new Vector.(); var m2:Matrix3D = new Matrix3D(); m2.appendTranslation(sporesDct[spore].velocity.xv,sporesDct[spore].velocity.yv,sporesDct[spore].velocity.zv); m2.appendRotation(0.5, sporesDct[spore].velocity.xv == 0 ? Vector3D.Y_AXIS:new Vector3D(sporesDct[spore].velocity.xr,sporesDct[spore].velocity.yr,sporesDct[spore].velocity.zr)); m2.transformVectors(vertices.slice(sporesDct[spore].firstVertex,sporesDct[spore].lastVertex+1),spv); vertices.splice(sporesDct[spore].firstVertex,18,spv[0],spv[1],spv[2],spv[3],spv[4],sporesDct[spore].zp = spv[5],spv[6],spv[7],spv[8],spv[9],spv[10],spv[11],spv[12],spv[13],spv[14],spv[15],spv[16],spv[17]); }); Utils3D.projectVectors(m, vertices, pvts, Vector.([])); for(var i:int = 0; i < pvts.length; i+=12){ spores[i/12].graphics.clear(); spores[i/12].graphics.drawGraphicsData(Vector.([new GraphicsStroke((100 - 2*sporesDct[spores[i/12]].zp)/100,false,LineScaleMode.NORMAL,CapsStyle.NONE,JointStyle.ROUND,3,new GraphicsSolidFill(0xFFFFFF,sporesDct[spores[i/12]].zp > -135 ? 1: 0)),new GraphicsPath(Vector.([1,2,2,1,2,1,2,1,2]),Vector.([ pvts[i],pvts[i+1], pvts[i+2],pvts[i+3], pvts[i+4],pvts[i+5], pvts[i+2],pvts[i+3], pvts[i+6],pvts[i+7], pvts[i+2],pvts[i+3], pvts[i+8],pvts[i+9], pvts[i+2],pvts[i+3], pvts[i+10],pvts[i+11]]))])); } }); // 25 lines ends here! } } }