forked from: RoseBlossom

by wwbeyondww1 forked from RoseBlossom (diff: 1)
バラ曲線のリスト
    r = sin(θ * n/d)
このリストは横軸がn(1~8) 縦軸がd(1~8)
♥0 | Line 97 | Modified 2013-07-22 13:45:54 | MIT License
play

ActionScript3 source code

/**
 * Copyright wwbeyondww1 ( http://wonderfl.net/user/wwbeyondww1 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/lyzK
 */

// forked from miyaoka's RoseBlossom
// forked from 178ep3's バラ曲線リスト
//
//      バラ曲線のリスト
//    r = sin(θ * n/d)
//      このリストは横軸がn(1~8) 縦軸がd(1~8)

package 
{
    import flash.display.Sprite;
    import caurina.transitions.Tweener;
    import flash.events.MouseEvent;
    
[SWF(width=465, height=465, frameRate=30, backgroundColor=0xffffff)]    
    public class RoseBlossom extends Sprite
    {
        public function RoseBlossom()
        {
            //wonderfl
            graphics.beginFill(0);
            graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
            Wonderfl.capture_delay(5);
    
            //evt
            stage.addEventListener(MouseEvent.MOUSE_DOWN, function ():void 
            {
                var rt:RoseTween = new RoseTween();
                rt.x = mouseX;
                rt.y = mouseY;
                addChild(rt);
                rt.addEventListener(RoseTween.COMPLETE, function ():void 
                {
                    removeChild(rt);
                    rt = null;
                });
            });
            
        }
    }
}
import flash.display.Shape;
import flash.display.Sprite;
import caurina.transitions.Tweener;
import flash.events.Event;
import flash.display.BlendMode;
import flash.filters.BlurFilter;
import flash.geom.Point;
class RoseTween
extends Sprite
{
    public var d:int = 1;
    public var n:int = 1;
    public var scale:Number = 1.0;
    public static const COMPLETE:String = "CompleteRose";
    private static const TRANS:Array = [
        "easeOutElastic",
        "easeOutBack",
        "easeInOutCirc"
    ];
    public function RoseTween():void 
    {
        blendMode = BlendMode.ADD;
        rotation = Math.random() * 360;
        Tweener.addTween(this, {
            d: d + Math.random() * 5 + 1,
            n: n + Math.random() * 20 + 1,
            scale: scale * (Math.random() * 100 + 30),
            rotation: rotation + Math.random() * 720 - 360,
            time: 1.0 + Math.random() * 3.0,
            transition: TRANS[Math.floor(Math.random() * TRANS.length)],
            onUpdate: function ():void 
            {
                var pt:Point = Point.polar(5, (90 - rotation) * Math.PI / 180);
                x += pt.x;
                y += pt.y;
                while (numChildren > 3) removeChildAt(0);
                if (numChildren > 1) Shape(getChildAt(1)).filters = [new BlurFilter(scale, scale)];
                addChild(new Rose(1 * scale, (n == d) ? ++n : n, d));
            },
            onComplete: function() :void
            {
                dispatchEvent(new Event(COMPLETE));
            }
        });
    }
}

class Rose extends Shape
{
    public function Rose(radius:Number,n:uint,d:uint)
    {
        var c:Number = n/d;
        
        this.graphics.lineStyle(Math.random()*2, 
            (Math.random() * 0x66 | 0x99) << 16 |
            (Math.random() * 0x66 | 0x99) << 8 |
            (Math.random() * 0x66 | 0x99)
        );
        this.graphics.moveTo(0,0);
            
        for(var i:uint=0; i<360*d; i+=2)
        {
            var rad:Number = i * Math.PI /180;
            var v:Number = Math.sin(c * rad);
            var r:Number = radius * v;
                
            var x:Number = r * Math.cos(rad);
            var y:Number = r * Math.sin(rad);
                
            this.graphics.lineTo(x,y);
        }
        this.graphics.endFill();
    }
}