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

code on 2008-12-18

Original Code by yamasv@gmail.com
from http://yamasv.blog92.fc2.com/blog-entry-147.html
Get Adobe Flash player
by shidho 18 Dec 2008
    Embed
//Original Code by yamasv@gmail.com
// from http://yamasv.blog92.fc2.com/blog-entry-147.html

package{
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.utils.*;
    import flash.filters.DropShadowFilter;


        public class Mirror2 extends Sprite{
            private var balls:Array = [];
            private var blueBall:Ball = new Ball(0xff, 30);
            private var redBall:Ball = new Ball(0xff0000, 30);
            private var greenBall1:Ball = new Ball(0xff00, 5);
            private var greenBall2:Ball = new Ball(0xff00, 5);

            public function Mirror2(){
                blueBall.x = 200;
                blueBall.y = 100;
                greenBall1.x = greenBall1.y = 30;
                greenBall2.x = greenBall2.y = 300;
                addChild(blueBall);
                addChild(redBall);
                addChild(greenBall1);
                addChild(greenBall2);

                initListener(blueBall);
                initListener(greenBall1);
                initListener(greenBall2);

                cal();
            }

            private function initListener(b:Ball):void{
                b.addEventListener( MouseEvent.MOUSE_DOWN, pickup );
                b.addEventListener( MouseEvent.MOUSE_UP, place );
                b.addEventListener( MouseEvent.MOUSE_MOVE, function(e:*):void{ cal(); });
            }

            public function pickup( event:MouseEvent ):void {
                // ドラッグ処理を開始して、影フィルターをつける
                event.target.startDrag( );
                event.target.filters = [ new DropShadowFilter( ) ];
                // 最前面に表示されるようにする
                setChildIndex( DisplayObject( event.target ), numChildren - 1 );
            }

            public function place( event:MouseEvent ):void {
                // ドラッグ処理を終了して影フィルターをオフ
                event.target.stopDrag( );
                event.target.filters = null;

                cal();
            }

            private function cal() :void{
                var a:Number = (greenBall2.y - greenBall1.y)/(greenBall2.x - greenBall1.x);
                var theta:Number = Math.atan(a);
                var b:Number = greenBall1.y - a*greenBall1.x;

                redBall.x = blueBall.x * Math.cos(2*theta) + blueBall.y * Math.sin(2*theta) - b*Math.sin(2*theta);
                redBall.y = blueBall.x * Math.sin(2*theta) - blueBall.y * Math.cos(2*theta) + b*Math.cos(2*theta) + b;

                graphics.clear();
                graphics.lineStyle(3, 0x0, 0.5);
                graphics.moveTo(greenBall1.x, greenBall1.y);
                graphics.lineTo(greenBall2.x, greenBall2.y);

            }
        }
}

import flash.display.*;

internal class Ball extends Sprite{
    public function Ball(color:int, radius:int){
        graphics.beginFill(color);
        graphics.drawCircle(0,0,radius);
        graphics.endFill();
    }
}