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

ribbons

Get Adobe Flash player
by ysle 28 Jul 2012
    Embed
/**
 * Copyright ysle ( http://wonderfl.net/user/ysle )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/j2IX
 */

package 
{
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.filters.BlurFilter;
    import flash.geom.Point;

    public class Main extends Sprite 
    {
        private var bg:BitmapData
        private var point:Point = new Point()
        private var blur:BlurFilter = new BlurFilter(1.1, 1.1, 3)
        private var ribbons:Vector.<Ribbon> = new Vector.<Ribbon>
        private var target:Point = new Point()
        private var over:Boolean = false

        public function Main():void 
        {
            
            Wonderfl.capture_delay(5);
            
            for (var i:int = 0; i < 5; i++) ribbons.push(new Ribbon(.2 +i*.2, .9 - i * .05, i*120))
            addChild(new Bitmap(bg = new BitmapData(stage.stageWidth, stage.stageHeight, false, 0)))
            stage.addEventListener(Event.ENTER_FRAME, onEnterFrame)
            
            stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove)
            stage.addEventListener(Event.MOUSE_LEAVE, onMouseLeave)
        }

        private function onMouseMove(e:MouseEvent):void { if (!over) over = true }
        private function onMouseLeave(e:Event):void { over = false }
        
        private function onEnterFrame(e:Event):void 
        {
            if (over)
            {
                target.x = mouseX
                target.y = mouseY
            }
            else if (Math.random() < .1)
            {
                target.x = Math.random()*stage.stageWidth
                target.y = Math.random()*stage.stageHeight
            }
            for each (var r:Ribbon in ribbons) bg.draw(r.update(target.x,target.y))
            bg.applyFilter(bg, bg.rect, point, blur)
        }
    }
}


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

class Ribbon extends Sprite
{
    private var c:Point = new Point() // current
    private var v:Point = new Point() // velocity
    private var d:Number = .9 // damp
    private var s:Number = .2; // spring

    private var la:Point = new Point() // last anchor point
    private var lc:Point = new Point() // last control point
    
    public var clr:Number = 0 // color
    private static var rules:Array =
    [
        {r:0xff, g:0, b:0, dr:0, dg:1, db:0 },
        {r:0xff, g:0xff, b:0, dr: -1, dg:0, db:0 },
        {r:0, g:0xff, b:0, dr:0, dg:0, db: +1 },
        {r:0, g:0xff, b:0xff, dr:0, dg: -1, db:0 },
        {r:0, g:0, b:0xff, dr: +1, dg:0, db:0 },
        {r:0xff, g:0, b:0xff, dr:0, dg:0, db: -1 }
    ]    
    
    public function Ribbon(spring:Number, damp:Number, color:Number):void
    {
        s = spring
        d = damp
        clr = color
    }

    public function update(x:Number,y:Number):Ribbon
    {
        v.x += (x - c.x) * s;        v.y += (y - c.y) * s
        v.x *= d;                    v.y *= d
        lc.x = c.x;                    lc.y = c.y
        c.x += v.x;                    c.y += v.y
        
        clr += 5
        graphics.clear()
        graphics.lineStyle(0, getColor(clr))
        graphics.moveTo(la.x, la.y)
        graphics.curveTo(lc.x, lc.y , la.x = (c.x + lc.x) / 2, la.y = (c.y + lc.y) / 2 )
        return this
    }
    
    private function getColor(value:Number):Number
    {
        var d:Number = (value = value % 0x5fa) % 0xff
        var r:Object = rules[int(value / 0xff)]
        return ((r.r+r.dr*d)<<16)+((r.g+r.dg*d)<<8)+(r.b+r.db*d)
    }    
}