Simple lines

Simple lines
Simple lines

Simple lines This is just something I hastily threw together this morning (damnit boredom!). Here’s the source code in its entirety. const MaxRays: int = 50, MaxVelocity: Number = 1, Resolution: Point = new Point(550, 400); var rays: Array = new Array(), sceneBMD: BitmapData = new BitmapData(Resolution.x, Resolution.y, false, 0), canvasSprite:Sprite = new Sprite(), timer: Timer=new Timer(20); this.addChild(new Bitmap(sceneBMD)); timer.addEventListener(TimerEvent.TIMER, UpdateRays); CreateRays(); timer.start(); function CreateRays() { while (rays.length < MaxRays) { var newRay: Object = new Object(); newRay.point1 = new Point(Math.random() * Resolution.x, Math.random() * Resolution.y); newRay.point2 = new Point(Math.random() * Resolution.x, Math.random() * Resolution.y); newRay.velocity1 = new Point(-MaxVelocity + 2 * Math.random() * MaxVelocity,0); newRay.velocity1.y = (MaxVelocity – Math.abs(newRay.velocity1.x)) + (MaxVelocity – Math.abs(newRay.velocity1.x)) * -2 * int(Math.random() < 0.5); newRay.velocity2 = new Point(-MaxVelocity + 2 * Math.random() * MaxVelocity,0); newRay.velocity2.y = (MaxVelocity – Math.abs(newRay.velocity2.x)) + (MaxVelocity – Math.abs(newRay.velocity2.x)) * -2 * int(Math.random() < 0.5); newRay.color = Math.floor(Math.random() * 256) * 256 * 256 + Math.floor(Math.random() * 256) * 256 + Math.floor(Math.random() * 256); rays.push(newRay); } } function UpdateRays(evt: TimerEvent) { sceneBMD.colorTransform(sceneBMD.rect, new ColorTransform(1, 1, 1, 0.995)); for (var i: int = 0; i < rays.length; i++) with (rays[i]) { point1.x += velocity1.x; point1.y += velocity1.y; point2.x += velocity2.x; point2.y += velocity2.y; velocity1.x = velocity1.x – 2 * velocity1.x * int(point1.x < 0 && velocity1.x Resolution.x && velocity1.x > 0); velocity1.y = velocity1.y – 2 * velocity1.y * int(point1.y < 0 && velocity1.y Resolution.y && velocity1.y > 0); velocity2.x = velocity2.x – 2 * velocity2.x * int(point2.x < 0 && velocity2.x Resolution.x && velocity2.x > 0); velocity2.y = velocity2.y – 2 * velocity2.y * int(point2.y < 0 && velocity2.y Resolution.y && velocity2.y > 0); canvasSprite.graphics.lineStyle(1, color, 0.1); canvasSprite.graphics.moveTo(point1.x, point1.y); canvasSprite.graphics.lineTo(point2.x, point2.y); } sceneBMD.draw(canvasSprite); canvasSprite.graphics.clear(); }

Categories and tags of the game : Demonstration, Single Player