はてなロクロがおもしろいね、マネてみた

『 はてなロクロ サービス終了のお知らせ』


線を描くと立体になっておもしろい


線の太さがあってもいいのかなぁ〜って思います
空間がもっと楽しくなりそう
あと、ベジェ曲線で描けるようにとか


んまぁ、はてなのサービスはゆる〜ぃ感じがいいですね


楽しいので、マネてみた


  • ステージをクリックすれば描けます
  • Yのアングルのみをグリグリしています
  • 座標(0, 0)から謎の線が入るが、ウホッ放置

Rokuro.as

package {

    import flash.display.MovieClip;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.display.Graphics;
    import Point3D;


    public class Rokuro extends MovieClip {

        private var points: Array;
        private var breakPoints: Array;
        
        private var numLines:  Number = 0;
        private var numPoints: Number = 0;

        private var fl: Number = 1000;
        private var ax: Number = .1;
        private var ay: Number = .1;
        private var vpX: Number = stage.stageWidth / 2;
        private var vpY: Number = stage.stageHeight / 2;



        /**
         * Constructor
         */
        public function Rokuro () {

            init();
            
        }



        /**
         * init
         */
        private function init (): void {
            
            points = new Array();
            breakPoints = new Array();

            addEventListener(Event.ENTER_FRAME, draw);

            stage.addEventListener(MouseEvent.MOUSE_DOWN, function (): void {
                addEventListener(Event.ENTER_FRAME, addPoints);
            });

            stage.addEventListener(MouseEvent.MOUSE_UP, function (): void {
                breakPoints[numLines] = numPoints;
                numLines++;
                removeEventListener(Event.ENTER_FRAME, addPoints);
            });

        }



        /**
         * addPoints
         */
        private function addPoints (e: Event): void {

            points.push(new Point3D(mouseX - vpX, mouseY - vpY));
            numPoints++;

        };



        /**
         * draw
         */
        private function draw (e: Event): void {
            
            if (!numPoints) return;
            
            var i: uint;
            var j: uint = 0;

            graphics.clear();
            graphics.lineStyle(2, 0xffffff, .8);
            graphics.moveTo(points[0].x, points[0].y);
			
            for (i = 0; i < numPoints; i++) {
                
                if (breakPoints[j] == i) {
                    graphics.endFill();
                    graphics.lineStyle(2, 0xffffff, .8);
                    graphics.moveTo(points[i].x, points[i].y);
                    j++;
                }

                var p: Point3D = points[i];
                //rotateX(p, ax);
                rotateY(p, ay);
                doPerspective(p);
                graphics.lineTo(p.x, p.y);

            }

        }



        /**
         * rotateX
         * @param p  Point3D
         * @param ax Number
         */
        private function rotateX (p: Point3D, ax: Number):void {
			
            var cx: Number = Math.cos(ax);
            var sx: Number = Math.sin(ax);
            var y1: Number = p.py * cx - p.pz * sx;
            var z1: Number = p.pz * cx + p.py * sx;
            p.py = y1;
            p.pz = z1;
		
        }
        /**
         * rotateY
         * @param p  Point3D
         * @param ay Number
         */
        private function rotateY (p: Point3D, ay: Number):void {
			
            var cy: Number = Math.cos(ay);
            var sy: Number = Math.sin(ay);
            var x1: Number = p.px * cy - p.pz * sy;
            var z1: Number = p.pz * cy + p.px * sy;
            p.px = x1;
            p.pz = z1;
		
        }



        /**
         * doPerspective
         * @param p Point3D
         */
        private function doPerspective (p: Point3D):void {

            var scale: Number = fl / (fl + p.pz);
            p.x = vpX + p.px * scale;
            p.y = vpY + p.py * scale;

        }


    }
}

Point3D.as

package {

    import flash.display.Sprite;

    public class Point3D extends Sprite {

        private var _px: Number = 0;
        private var _py: Number = 0;
        private var _pz: Number = 0;

        public function set px (n: Number): void { _px = n; }
        public function set py (n: Number): void { _py = n; }
        public function set pz (n: Number): void { _pz = n; }
        public function get px (): Number { return(_px); }
        public function get py (): Number { return(_py); }
        public function get pz (): Number { return(_pz); }


        /**
         * Constructor
         * @param inX: X 座標
         * @param inY: Y 座標
         * @param inZ: Z 座標
        **/
        public function Point3D (

            inX: Number = 0,
            inY: Number = 0,
            inZ: Number = 1
        
        ) {
			
            px = inX;
            py = inY;
            pz = inZ;

        }
    }
}