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

Power of Trigonometric function

x=cos^n θ,y=sin^n θのぐらふ。
n=0のとき、正方形。
n=1のとき、円。
n=2のとき、菱型。
∞に飛ばせば0になる。

距離空間d_nと関係がありそうって思ったけど
((sin^r x)^n+(sin^r y)^n)^(1/n)=1⇔rn=2っていうだけか
Get Adobe Flash player
by phi16 11 Jan 2014
/**
 * Copyright phi16 ( http://wonderfl.net/user/phi16 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/7Q9M
 */

// forked from phi16's Power of Power
// forked from phi16's forked from: Template
// forked from phi16's Template
package {
    import flash.text.TextFormat;
    import flash.text.TextField;
    import flash.geom.Point;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    public class Tp extends Sprite {
        public var spr:Sprite=new Sprite();
        public var dat:Array=new Array();
        public var mot:Array=new Array();
        public var i:int=0;
        public var stfx:TextField=new TextField(),stfy:TextField=new TextField();
        public function Tp(){
            this.addChild(spr);
            this.addEventListener(Event.ENTER_FRAME,frame);
            for(i=0;i<360;i++){
                dat.push(new Point(0,0));
                mot.push(new Point(0,0));
            }
            stfx.defaultTextFormat=new TextFormat("メイリオ",30,0xffffff);
            stfx.x=20;
            stfx.y=465-100.0;
            stfx.width=465;
            stfx.height=50;
            stfx.text=String("");
            stfy.defaultTextFormat=new TextFormat("メイリオ",30,0xffffff);
            stfy.x=20;
            stfy.y=465-50.0;
            stfy.width=465;
            stfy.height=50;
            stfy.text=String("");
            this.addChild(stfx);
            this.addChild(stfy);
        }
        public function frame(e:Event):void{
            spr.graphics.clear();
            spr.graphics.beginFill(0);
            spr.graphics.drawRect(0,0,465,465);
            spr.graphics.endFill();
            spr.graphics.lineStyle(1.0,0xffffff,0.5);
            spr.graphics.moveTo(465/2.0,0);
            spr.graphics.lineTo(465/2.0,465);
            spr.graphics.moveTo(0,465/2.0);
            spr.graphics.lineTo(465,465/2.0);

            var n:Number=this.mouseX*2.0/465-1.0;
            n=Math.tan(n*Math.PI*0.499);
            var ns:String=String(n).substr(0,6);
            stfx.text="x:cos^"+ns+" θ";
            stfy.text="y:sin^"+ns+" θ";

            spr.graphics.lineStyle(3.0,0x007fff,1);
            spr.graphics.moveTo(mot[0].x*465/4.0+465/2.0,-mot[0].y*465/4.0+465/2.0);
            spr.graphics.lineTo(mot[0].x*465/4.0+465/2.0,-mot[0].y*465/4.0+465/2.0);
            for(i=0;i<360;i++){
                spr.graphics.lineStyle(3.0,Rainbow(i),1);
                if(i!=0)spr.graphics.lineTo(mot[i].x*465/4.0+465/2.0,-mot[i].y*465/4.0+465/2.0);
                var th:Number=i*Math.PI/180;
                var xm:Number=Math.cos(th),ym:Number=Math.sin(th);
                var xs:Number=xm<0?-1:1,ys:Number=ym<0?-1:1;
                dat[i].x=Math.pow(Math.abs(xm),n)*xs;
                dat[i].y=Math.pow(Math.abs(ym),n)*ys;
                mot[i].x+=(dat[i].x-mot[i].x)/4.0;
                mot[i].x=Math.min(Math.max(mot[i].x,-16.0),16.0);
                mot[i].y+=(dat[i].y-mot[i].y)/4.0;
                mot[i].y=Math.min(Math.max(mot[i].y,-16.0),16.0);
            }
            spr.graphics.lineTo(mot[0].x*465/4.0+465/2.0,-mot[0].y*465/4.0+465/2.0);
        }
    }
}

function Rainbow(ra:Number):int{
    var colr:int,colg:int,colb:int;
    colr=(Math.sin(ra*Math.PI/180)+1)*255/2;
    colg=(Math.sin((ra+120)*Math.PI/180)+1)*255/2;
    colb=(Math.sin((ra-120)*Math.PI/180)+1)*255/2;
    return colr*256*256+colg*256+colb;

}