In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

PeakToPeak2

PeakToPeak2.as
Get Adobe Flash player
by kadal 03 Apr 2009
    Embed
// forked from kadal's PeakToPeak
/* PeakToPeak2.as */
package {
	import flash.display.*;
	import flash.events.Event;
	import flash.events.MouseEvent;

	import flash.geom.Point;
	import flash.filters.BlurFilter;

        import flash.text.TextField;
        import flash.text.TextFieldAutoSize;
        import flash.text.TextFormat;
        import flash.text.TextFormatAlign;

        [SWF(backgroundColor="#000000", frameRate=30)]

	public class PeakToPeak extends Sprite {
    
		private const SW:Number = stage.stageWidth;
		private const SH:Number = stage.stageHeight;
            
                private var lineG:Sprite = new Sprite();
                private var c1:Circle = new Circle();
                private var c2:Circle = new Circle();
                private var drawArea:Sprite = new Sprite();
              
		public function PeakToPeak() {
    
    
		    c1.graphics.beginFill(0xFFFFFF);
                    c1.graphics.lineStyle(1, 0xFFFFFF, 1);
		    c1.graphics.drawCircle(0, 0, 40);
		    c1.x = (SW - c1.width) * Math.random() + c1.width/2;
		    c1.y = (SW - c1.height) * Math.random() + c1.height/2;
                    c1.myRad = Math.random()*2*Math.PI;
                    c1.mySpeed = Math.random()*15+5;
                    c1.vX = c1.mySpeed * Math.cos(c1.myRad);
                    c1.vY = c1.mySpeed * Math.sin(c1.myRad);
                    c1.vS = Math.random()*0.04-0.02;
                    c1.graphics.endFill();

		    c2.graphics.beginFill(0xFFFFFF);
                    c2.graphics.lineStyle(1, 0xFFFFFF, 1);
		    c2.graphics.drawCircle(0, 0, 40);
		    c2.x = (SW - c2.width) * Math.random() + c2.width/2;
		    c2.y = (SH - c2.height) * Math.random() + c2.height/2;
                    c2.myRad = Math.random()*2*Math.PI;
                    c2.mySpeed = Math.random()*15+5;
                    c2.vX = c2.mySpeed * Math.cos(c2.myRad);
                    c2.vY = c2.mySpeed * Math.sin(c2.myRad);
                    c2.vS = Math.random()*0.04-0.02;
		    c2.graphics.endFill();

                    drawArea.addChild(lineG);
		    drawArea.addChild(c1);
		    drawArea.addChild(c2);

                    c1.buttonMode = true;
                    c2.buttonMode = true;
                    lineG.buttonMode = true;
                    
                    c1.addEventListener(MouseEvent.MOUSE_DOWN,cDown);
                    c1.addEventListener(MouseEvent.MOUSE_UP,cUp);
                    c1.addEventListener(Event.ENTER_FRAME, cMove);
                    c2.addEventListener(MouseEvent.MOUSE_DOWN,cDown);
                    c2.addEventListener(MouseEvent.MOUSE_UP,cUp);
                    c2.addEventListener(Event.ENTER_FRAME, cMove);
                    
                    lineG.addEventListener(MouseEvent.MOUSE_DOWN,gDown);
                    lineG.addEventListener(MouseEvent.MOUSE_UP,gUp);
                    
                    addEventListener(Event.ENTER_FRAME, lineDraw);


		    var filters_array:Array = new Array();
		    var myBlur:BlurFilter = new BlurFilter(2, 2, 1);
		    filters_array.push(myBlur);
		    drawArea.filters = filters_array;

                    addChild(drawArea);
                    
		}

                private function cDown(evt:MouseEvent):void {
                    evt.target.startDrag();
                }
                private function cUp(evt:MouseEvent):void {
                    evt.target.stopDrag();
                }
                
                private function cMove(evt:Event):void {
                    var c:Object = evt.target;
                    
                    if(c.x - c.width/2 < 0){
                        c.x = c.width/2
                        c.vX *= -1
                    } 
                    if(c.x + c.width/2 > SW){
                        c.x = SW - c.width/2
                        c.vX *= -1
                    }
                    if(c.y - c.height/2 < 0){
                        c.y = c.height/2
                        c.vY *= -1
                    } 
                    if(c.y + c.height/2 > SH){
                        c.vY *= -1
                    }
                    c.x += c.vX;
                    c.y += c.vY;

                    c.scaleX -= c.vS;
                    c.scaleY -= c.vS;

                    if(c.scaleX < 0.1 || c.scaleX > 1 || c.scaleY < 0.1 || c.scaleY > 1){
                        c.vS *= -1
                    }

                }
                
                private function gDown(evt:MouseEvent):void {
                    evt.target.parent.startDrag();
                }
                private function gUp(evt:MouseEvent):void {
                    evt.target.parent.stopDrag();
                }
        
                private function lineDraw(evt:Event):void {
                    lineG.graphics.clear();
                    var rad:Number = Math.atan2(c2.y - c1.y, c2.x - c1.x);
                    lineG.graphics.lineStyle(1, 0xFFFFFF, 1);
		    lineG.graphics.beginFill(0xFFFFFF);
                    lineG.graphics.moveTo(c1.x + c1.width/2 * Math.cos(rad-Math.PI/2), c1.y + c1.width/2 * Math.sin(rad-Math.PI/2));
                    lineG.graphics.lineTo(c2.x + c2.width/2 * Math.cos(rad-Math.PI/2), c2.y + c2.width/2 * Math.sin(rad-Math.PI/2));
                    lineG.graphics.lineTo(c2.x + c2.width/2 * Math.cos(rad+Math.PI/2), c2.y + c2.width/2 * Math.sin(rad+Math.PI/2));
                    lineG.graphics.lineTo(c1.x + c1.width/2 * Math.cos(rad+Math.PI/2), c1.y + c1.width/2 * Math.sin(rad+Math.PI/2));
                    lineG.graphics.lineTo(c1.x + c1.width/2 * Math.cos(rad-Math.PI/2), c1.y + c1.width/2 * Math.sin(rad-Math.PI/2));
		    lineG.graphics.endFill();
                }
	}
}

import flash.display.Sprite;
class Circle extends Sprite {
	public var radius:Number;
	public var color:uint;
        public var vX:Number;
        public var vY:Number;
        public var myRad:Number;
        public var mySpeed:Number;
        public var vS:Number;
        public function Circle() {
        }
}