package { import away3d.cameras.lenses.PerspectiveLens; import away3d.containers.View3D; import away3d.debug.AwayStats; import away3d.entities.SegmentSet; import away3d.filters.BloomFilter3D; import away3d.primitives.LineSegment; import flash.display.StageAlign; import flash.display.StageScaleMode; import flash.events.Event; import flash.geom.Vector3D; import flash.utils.getTimer; [SWF(frameRate = "60")] public class LinesSphere extends View3D { //---------------------------------------------------------- // // Static Property // //---------------------------------------------------------- private static const parameters:Array = [[0.25, 0xff7700, 1, 2], [0.5, 0xff9900, 1, 1], [0.75, 0xffaa00, 0.75, 1], [1, 0xffaa00, 0.5, 1], [1.25, 0x000833, 0.8, 1], [3.0, 0xaaaaaa, 0.75, 2], [3.5, 0xffffff, 0.5, 1], [4.5, 0xffffff, 0.25, 1], [5.5, 0xffffff, 0.125, 1]]; private static const r:Number = 450; //---------------------------------------------------------- // // Constructor // //---------------------------------------------------------- public function LinesSphere() { stage.scaleMode = StageScaleMode.NO_SCALE; stage.align = StageAlign.TOP_LEFT; antiAlias = 2; backgroundColor = 0x000000; (camera.lens as PerspectiveLens).far = 500000; var list:Array = []; for (var i:int = 0; i < 15000; ++i) { var vector1:Vector3D = new Vector3D(Math.random() * 2 - 1, Math.random() * 2 - 1, Math.random() * 2 - 1); vector1.normalize(); vector1.scaleBy(r); var vector2:Vector3D = vector1.clone(); vector2.scaleBy(Math.random() * 0.09 + 1); list.push([vector1, vector2]); } for (i = 0; i < parameters.length; ++i) { var p:Array = parameters[i]; var lines:SegmentSet = new SegmentSet(); scene.addChild(lines); lines.scale(p[0]); lines.rotationY = Math.random() * 360; for (var j:int = 0; j < list.length; j++) { var color:uint = ((0xFF * p[2]) << 24) + p[1]; lines.addSegment(new LineSegment(list[j][0], list[j][1], color, color, p[3])); } orijinalScales[i] = p[0]; lineSegments[i] = lines; } addChild(new AwayStats(this)); addEventListener(Event.ENTER_FRAME, enterFrameHandler); stage.addEventListener(Event.RESIZE, resizeHandler); resizeHandler(null); } //---------------------------------------------------------- // // Property // //---------------------------------------------------------- private var lineSegments:Array = []; private var orijinalScales:Vector. = new Vector.(); //---------------------------------------------------------- // // Function // //---------------------------------------------------------- private function resizeHandler(e:Event):void { this.width = stage.stageWidth; this.height = stage.stageHeight; var distance:Number = Vector3D.distance(new Vector3D(-1000, 500, 500), new Vector3D(0, 0, 0)); (camera.lens as PerspectiveLens).fieldOfView = 2 * Math.atan2(Math.sqrt(this.width * this.width + this.height * this.height) / 2, distance) * 180 / Math.PI; } private function enterFrameHandler(ev:Event):void { var time:Number = getTimer(); for (var i:int = 0; i < lineSegments.length; i++) { var obj:SegmentSet = lineSegments[i] as SegmentSet; obj.rotationY = time / 125 * (i < 4 ? -i : +i); if (i < 5) obj.scaleX = obj.scaleY = obj.scaleZ = (orijinalScales[i] * (i / 5 + 1) * (1 + 0.5 * Math.sin(time / 1500))); } camera.y += (-mouseY * 2 + 800 - camera.y) * .05; camera.x = 1250 * Math.sin(time / 2000); camera.z = 1250 * Math.cos(time / 2000); camera.lookAt(new Vector3D(0, 0, 0)); render(); } } }