LoginSignup
1
1

More than 5 years have passed since last update.

曲線を描くやつ

Posted at

ActionScript3.0アニメーション本から

DrawingCurve.as
package {
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    public class DrawingCurves extends Sprite {
        private var x0:Number = 100;
        private var y0:Number = 200;
        private var x1:Number;
        private var y1:Number;
        private var x2:Number = 300;
        private var y2:Number = 200;

        public function DrawingCurves() {
            init();
        }

        private function init():void {
            stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
        }

        private function onMouseMove(event:MouseEvent):void {
            x1 = mouseX * 2 - (x0 + x2) / 2; // ここがキモらしい
            y1 = mouseY * 2 - (y0 + y2) / 2;
            graphics.clear();
            graphics.lineStyle(1);
            graphics.moveTo(x0, y0);
            graphics.curveTo(x1, y1, x2, y2);
        }
    }
}
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1