### Bookstore

 Computer Math and Games in Pascal (preview) Lazarus Handbook

### Author Topic: Please help me understand arc  (Read 406 times)

#### Tirans

• Newbie
• Posts: 2
##### Please help me understand arc
« on: September 18, 2020, 04:11:03 pm »
Hello ive been tasked to make the first letter from my letter in pascal, but i cant figure out how to draw the arc.
Line(20,10,20,110);// a mala
Line(20,110,40,110); // b mala
Line(40,110,40,60); // c mala
Line(40,60,60,60);  // d mala
Line(60,60,80,110); // e mala
Line(80,110,100,110); // f mala
Line(100,110,80,60);  //g mala
Line(20,10,60,10); //h mala
Line(40,25,40,45); //i mala
Line(40,25,55,25); //j mala
Line(40,45,55,45); //k mala

this is what i currently have i need to add the two arcs but i cant manage to do it, can someone please help me out?

#### Zoran

• Hero Member
• Posts: 1611
##### Re: Please help me understand arc
« Reply #1 on: September 18, 2020, 04:55:43 pm »
There is TCanvas.Arc method. However, the meaning of all these parameters is not quite easy to understand...
Perhaps this topic can help you: https://forum.lazarus.freepascal.org/index.php?topic=36607.0

#### Handoko

• Hero Member
• Posts: 3913
• My goal: build my own game engine using Lazarus
##### Re: Please help me understand arc
« Reply #2 on: September 18, 2020, 05:00:58 pm »
It also can be the Arc in Graph unit:

https://www.freepascal.org/docs-html/rtl/graph/arc.html

#### Blaazen

• Hero Member
• Posts: 2994
• POKE 54296,15
##### Re: Please help me understand arc
« Reply #3 on: September 18, 2020, 05:21:01 pm »
I made this:
Code: Pascal  [Select][+][-]
1. Arc(45, 25, 65, 45, 90*16, -180*16);
2. Arc(45, 7, 90, 63, 60*16, -120*16);

The parameters are:
1,2: left/top point of ellipse
3,4: right/bottom point of ellipse
5: start degree (in 1/16 degrees, i.e. need multiply by 16)
6: angle (also need multiply by 16)

Docs says that angle 0 (i.e. the fifth parameter) is at 3 o'clock.
Lazarus 2.1.0 r64115 FPC 3.3.1 r40507 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

#### wp

• Hero Member
• Posts: 7752
##### Re: Please help me understand arc
« Reply #4 on: September 18, 2020, 06:28:02 pm »
In addition to what Blaazen wrote, there is also a second version of Arc which has four integers after the ellipse corner points:
Code: Pascal  [Select][+][-]
1. procedure TCanvas.Arc(ALeft, ATop, ARight, ABottom, SX, SY, EX, EY: Integer);
2.
These identify the x and y coordinates of the start and end points of the arc. They can be anywhere in the xy plane. In your mind, connect the center of the ellipse with the start point - this line will somewhere intersect the ellipse, and this is the point where the arc begins. And in the same way, the line between the ellipse center and the other point intersects the ellipse somewhere in the end point of the arc.

Study the attached demo. The scroll bars in the left side of the form move the start and end point across the xy plane, and you can see how the arc adapts to the position of these points.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

#### BobDog

• Jr. Member
• Posts: 68
##### Re: Please help me understand arc
« Reply #5 on: September 19, 2020, 02:21:31 pm »

Windows.
GDI has a tricky arc and an easy arc.
Naturally I choose the easy arc.
Code: Pascal  [Select][+][-]
1.
2. program arc;
3.
4. uses
5.  Windows;
6.
7.     const
8.     DC_BRUSH=18;
9.     const
10.     DC_PEN=19;
11.     const
12.     pi=3.141592653589793;
13.
14.   function SetDCBrushColor(p:hdc;colour:COLORREF): COLORREF; stdcall external 'gdi32.dll' name 'SetDCBrushColor';
15.   function SetDCPenColor(p:hdc;colour:COLORREF): COLORREF; stdcall external 'gdi32.dll' name 'SetDCPenColor';
16.    {NOTE: Don't need brush color here}
17.
18.    function rgb(r:byte;g:byte;b:byte) :COLORREF;
19.    var
20.    a:colorref;
21.    begin
22.    a:=  ((0 Shl 16) Or ((0) Shl 8) Or (0) Or \$FF000000);
23.    exit (((b Shl 16) Or ((g) Shl 8) Or (r) Or \$FF000000) - a);
24.    end;
25.
26.
27.  function GetConsoleHandle(): HWND;
28. type
29.  StringName = array[0..1024] of char;
30. var
31.  hwndFound: hwnd;
32.  pszNewWindowTitle, pszOldWindowTitle: StringName;
33. begin
34.  GetConsoleTitle(pszOldWindowTitle, 1024);
35.  wsprintf(pszNewWindowTitle, '%d/%d');
36.  SetConsoleTitle(pszNewWindowTitle);
37.  Sleep(40);
38.  hwndFound := FindWindow(nil, pszNewWindowTitle);
39.  SetConsoleTitle(pszOldWindowTitle);
40.  exit(hwndFound);
41. end;
42.
43. var
44. p:hwnd;
45. h:hdc;
46. centrex:integer;
47. centrey:integer;
48. radius:integer;
49. startangle:single;
50. sweep:single;
51. position: ppoint; //unused, only need the parameter for movetoex
52.
53.     begin
54.
55. p := GetConsoleHandle;
56. h:=GetDC(p);
57. sleep(40);  // give windows a little space to get the console
58.
59.    setwindowpos(p, HWND_TOPMOST, 0, 0, 800, 600, SWP_SHOWWINDOW);
60.    SelectObject(h,GetStockObject(DC_BRUSH));
61.    SelectObject(h,GetStockObject(DC_PEN));
62.
63. centrex:=400;
64. centrey:=300;
65. radius:=200;
66. startangle:=24;
67. sweep:=90;
68.   SetDCpenColor(h,rgb(200,0,0));
69.   movetoex(h,centrex+trunc(radius*cos(startangle*pi/180)),centrey-trunc(radius*sin(startangle*pi/180)),position);
70.   anglearc(h,centrex,centrey,radius,startangle,sweep);
71.
72. centrex:=600;
73. centrey:=400;
74. radius:=100;
75. startangle:=90;
76. sweep:=270;
77.    SetDCpenColor(h,rgb(0,200,0));
78.    movetoex(h,centrex+trunc(radius*cos(startangle*pi/180)),centrey-trunc(radius*sin(startangle*pi/180)),position);
79.    anglearc(h,centrex,centrey,radius,startangle,sweep);
80.
81.  readln;
82.  end.
83.