# Lazarus

## Free Pascal => General => Topic started by: Tirans on September 18, 2020, 04:11:03 pm

Post by: Tirans 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?
Post by: Zoran on September 18, 2020, 04:55:43 pm
There is TCanvas.Arc method (https://lazarus-ccr.sourceforge.io/docs/lcl/graphics/tcanvas.arc.html). However, the meaning of all these parameters is not quite easy to understand...
Post by: Handoko 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 (https://www.freepascal.org/docs-html/rtl/graph/arc.html)
Post by: Blaazen on September 18, 2020, 05:21:01 pm
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.
Post by: wp 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.
Post by: BobDog 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;
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;
66. startangle:=24;
67. sweep:=90;
68.   SetDCpenColor(h,rgb(200,0,0));