곡선을 as로 표현할 때 어떻게 적용되는지 궁금해서 테스트를 해봤습니다.
재미를 위해 enterframe 으로 돌려봤습니다.
moveTo() 는 시작점을 나타내는 것이므로..
드로잉 툴을 이용한다고 가정 했을 때, 가상의 x,y좌표로 마우스를 가져간다고 보시면 됩니다.
lineTo()는 일직선을 그리므로 목표지점 x,y 좌표를 찍어주면 되지만~
이와달리 curveTo()는 인자를 4개 받는군요.
curveTo(controlX:Number, controlY:Number, anchorX:Number, anchorY:Number)
여기서 controlX, controlY 는 거쳐갈 점을 의미합니다.
즉, 어느 쪽으로 얼마나 휘게 될지는 controlX, controlY에 의해 좌우된다고 보시면 되겠습니다.
anchorX,Y는 lineTo의 목표지점과 같은 의미이고요.
아래 예제에서 보시면 아시겠지만~
목표지점을 라인이 통과하지 않습니다. 베지어 곡선의 형태로

위와같이 작동합니다.
그림대로라면
moveTo()의 x,y는 P0
controlX, Y 는 P1 이 되겠고요..
anchorX, Y 는 P2 가 되겠네요.
아래는 실행 예제 입니다.
======================================== source =========================================
package
{
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;
[SWF(width='1024', height='700', backgroundColor='#ffffff', frameRate='30')]
public class DrawCurve extends Sprite
{
private var roundObject : Shape;
public function DrawCurve()
{
super();
this.roundObject = new Shape();
this.addChild( roundObject );
this.addEventListener( Event.ENTER_FRAME, onEnter );
}
private function onEnter( e:Event ):void
{
this.roundObject.graphics.clear();
roundObject.graphics.lineStyle( 1, 0x000000 );
roundObject.graphics.moveTo( 100 , 100);
roundObject.graphics.curveTo(this.mouseX, this.mouseY, 400, 400);
}
}
}
[출처] # as3 기초. curveTo 를 이용한 베지어 곡선 그리기.|작성자 위니
댓글 없음:
댓글 쓰기