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

Renkli Kivitan Cizgiler

Nila'nin odeviymis
Get Adobe Flash player
by eralpkaraduman 25 Mar 2012
/**
 * Copyright eralpkaraduman ( http://wonderfl.net/user/eralpkaraduman )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/d5UW
 */

package
{
    import flash.display.FrameLabel;
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.geom.Point;
    
    /* @author Eralp Karaduman
    */    
    [SWF(width=500,height=500)]
    public class Main extends Sprite
    {
        private var ballBreed:Array = [];
        private var maxBalls:int = 5;
        public const W:Number = 465;
        public const H:Number = 465;
        
        public function Main()
        {
            stage.scaleMode = flash.display.StageScaleMode.NO_SCALE;
            stage.align = flash.display.StageAlign.TOP_LEFT;
            stage.frameRate = 60;
            addEventListener(Event.ENTER_FRAME,update);
            onClk(null);
            
            stage.addEventListener(MouseEvent.CLICK,onClk);
        }
        
        protected function onClk(event:MouseEvent):void
        {
            graphics.clear();
            graphics.beginFill(0x000000,1);
            graphics.drawRect(0,0,W,H);
            graphics.endFill();
            for each(var b:Ball in ballBreed){
                b.dead = true;
                removeChild(b);
                b = null;
            }
            ballBreed = [];
            breed(new Point(Math.random()*W,Math.random()*H),Math.random()*360,Math.random()*0xFFFFFF);
        }
        
        public function update(e:Event):void{
            for each(var b:Ball in ballBreed){
                b.update();
            }
        }
        
        public function hitWall(b:Ball):Boolean{
            if(b.x < 0 || b.x > W || b.y < 0 || b.y > H){
                return true;    
            }else{
                return false;
            }
        }
        
        public function breed(pos:Point,dir:Number,cl:Number=-1):void{
            var b:Ball;
            if(ballBreed.length>maxBalls){
                var b_t:Ball = ballBreed.shift();
                b_t.reInit(this,pos,dir,cl);
                b = b_t;
            }else{
                b = new Ball(this,pos,dir,cl)
            }
            ballBreed.push(b);
        }
        
        public function drawTrail(t:Point, p:Point, color:Number,alph:Number):void
        {
            graphics.lineStyle(3,color,alph,false);
            graphics.moveTo(t.x,t.y);
            graphics.lineTo(p.x,p.y);
        }
    }
}

import flash.display.Sprite;
import flash.geom.Point;

internal class Ball extends Sprite
{
    public var dir:Number;
    public var speed:Number = 1+Math.random()*2;
    public var life:Number;
    public var fullLife:Number = Math.random()*100+100;
    private var t:Point = new Point();
    private var s:Point = new Point();
    private var color:Number;
    private var container:Main;
    public var dead:Boolean = false;
    private var distruption:Number = 0;
    private var head:Sprite = new Sprite();
    
    public function Ball(container:Main,pos:Point,dir:Number,cl:Number=-1){
        
        if(pos.x < 0)pos.x = 0;
        if(pos.x > container.W)pos.x = container.W;
        if(pos.y < 0)pos.y = 0;
        if(pos.y > container.H)pos.y = container.H;
        
        life = fullLife;
        if(color!=-1){
            color = cl;
        }else{
            color = Math.random()*0xFFFFFF;    
        }
        this.container = container;
        head.graphics.lineStyle(1,0xFF0000,1);
        var sz:Number = 3;
        head.graphics.moveTo(-sz,-sz);
        head.graphics.lineTo(sz,0);
        head.graphics.lineTo(-sz,sz);
        head.graphics.lineTo(-sz,-sz);
        //addChild(head);
        this.x = pos.x;
        this.y = pos.y;
        rotation = dir;
        container.addChild(this);
    }
    
    public function reInit(param0:Main, pos:Point, dir:Number, cl:Number):void
    {
        if(pos.x < 0)pos.x = 0;
        if(pos.x > container.W)pos.x = container.W;
        if(pos.y < 0)pos.y = 0;
        if(pos.y > container.H)pos.y = container.H;
        fullLife = Math.random()*100+100;
        distruption = 0;
        speed = 1+Math.random()*2;
        color = Math.random()*0xFFFFFF;    
        this.x = pos.x;
        this.y = pos.y;
        rotation = dir;
    }
    
    public function update():void{
        if(dead ){
            return;
        }
        
        var distrupted_rotation:Number = distrupt(rotation,distruption);
        head.rotation = distrupted_rotation;
        var ang:Number =  distrupted_rotation* Math.PI / 180;
        t.x = x; t.y = y;
        s.x = speed * Math.cos(ang);
        s.y = speed * Math.sin(ang);
        x = x + speed * s.x;
        y = y + speed * s.y;
        container.drawTrail(t,new Point(x,y),color,life/fullLife+.1);
        life-=speed;
        if(life<=0){
            var c1:Number = Math.random()*0xFFFFFF;
            var c2:Number = Math.random()*0xFFFFFF;
            container.breed(new Point(x,y),rotation-35,c2);
            rotation = rotation + 35;
            life = fullLife;
            color = c1;
        }
        
        if(container.hitWall(this)){
            if(x>container.W || x<0)s.x = -s.x;
            if(y>container.H || y<0)s.y = -s.y;
            t.x = x + s.x;
            t.y = y + s.y;
            ang = Math.atan2(t.y-y,t.x-x);
            rotation = ang*180/Math.PI;
        }
    }
    
    private function distrupt(rot:Number, dis:Number):Number
    {
        var inc:Number = .1;
        var an:Number = Math.random()*90+20;
        var dir:int = (dis<0)?-1:1;
        var _d:Number = Math.abs(dis);
        if(dir){
            rot+=(rotation+an*_d);
            distruption+=inc;
        }else{
            rot-=(rotation+an*_d);
            distruption+=inc;
        }
        
        if(distruption>1){
            distruption= 0;
        }
        if(distruption<-1){
            distruption= 0;
        }
        return rot;
    }
    
    private function clnorm(cl:Number):Number
    {
        //if(cl>0xFFFFFF)cl = cl - 0xFFFFFF;
        //if(cl<0)cl = cl=Math.abs(cl);
        return cl;
    }
    
    public function destroy():void
    {
        
    }
    
    
}