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

forked from: forked from: Light Paint - forked from: LineThing

マウスの軌跡に沿った曲線の謎を知りたくてForkしてみる
/**
 * Copyright hacker_bikxc44i ( http://wonderfl.net/user/hacker_bikxc44i )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/8vu6
 */

// forked from esukei's forked from: Light Paint - forked from: LineThing
// forked from kto12's Light Paint - forked from: LineThing
// forked from milkmidi's LineThing
/**
 * マウスの軌跡に沿った曲線の謎を知りたくてForkしてみる
 * 
 */
package  {    
    
    import flash.display.Graphics;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.utils.getTimer;
    [SWF(frameRate = "8", backgroundColor = "#000000")]    
    public class LineThing extends Sprite{
        private var points:Array = new Array();
        private var draw_mc:Sprite = new Sprite();
                private var line_mc:Sprite = new Sprite();
        
        //_________________________Constructor
        public function LineThing() {    
                    this.addChild(line_mc);    
            this.addChild(draw_mc);

            this.addEventListener(Event.ENTER_FRAME,onEventEnterFrame);
        }


        private function onEventEnterFrame(e:Event):void  {
            draw_mc.graphics.clear();
            draw_mc.graphics.lineStyle(1, 0x0000FF);
                        draw_mc.alpha = 1;
                        
                        line_mc.graphics.clear();
                        line_mc.graphics.lineStyle(1, 0xFF0000);
            
            var pLen:Number = points.push({x:this.mouseX, y:this.mouseY, life:getTimer()});
            for (var i:Number = 0; i < pLen; i++) {
                if (!points[i]) {
                        continue;
                }
                if (getTimer() - points[i].life > 1000) {                    
                    points.splice(i--, 1);
                } 
                else {
                    if (i!=0 && points[i]) {                
                        //draw_mc.alpha *= 1.1;
                        
                        var cx:Number = points[i - 1].x;
                        var cy:Number = points[i - 1].y;
                        draw_mc.graphics.curveTo(cx, cy, (points[i].x + cx) / 2, (points[i].y + cy) / 2);
line_mc.graphics.lineTo(cx, cy);
                    } 
                    else {
                        draw_mc.graphics.moveTo(points[i].x, points[i].y);
                                                line_mc.graphics.moveTo(points[i].x, points[i].y);
                    }
                }
            }
        };
    }
    
}