안녕 하세요?
BacTeria 박종민 입니다.
오늘의 팁은 Canvas에 타원 그려주는 함수 입니다.
마지막 인자에 각도에 원하는 라디안 값을 넣어주면 기울어진 타원을 그려줍니다.
그럼 이만...
오늘 하루도 열심히 사세요~
procedure RotatedEllipse(Canvas: TCanvas; Xc, Yc, Ra, Rb: Integer; Angle: Double);
// Canvas is the canvas on which to draw
// (Xc,Yc) is the center of the ellipse, in pixels
// Ra and Rb are the major and minor axes, in pixels
// Angle is the angle of the major axis with respect to the x-axis,
// in radians
var
I, N: Integer;
Incr, X, Y, Ca, Sa: Double;
begin
N := Round(0.5 * Pi * (Ra + Rb));
if N < 10 then N := 10;
Incr := 2 * Pi / N;
Ca := Cos(Angle);
Sa := Sin(Angle);
Canvas.MoveTo(Xc + Round(Ra * Ca), Yc + Round(-Ra * Sa));
for I := 1 to N do
begin
X := Ra * Cos(Incr * I);
Y := Rb * Sin(Incr * I);
Canvas.LineTo(Xc + Round(X * Ca + Y * Sa), Yc + Round(-X * Sa + Y * Ca));
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
RotatedEllipse(Form1.Canvas, 200, 200, 100, 50, math.DegToRad(45));
end;
|