help: i want to draw polygon in pascal lazarus / 39-Graphics ---------------------------------------------------------------------- zanghaohieu · 2014-08-16 15:08 I want to draw polygons with coordinates had been entered from the keyboard into one-dimensional array. Now that the coordinates used to draw polygons. Should I use google translate expressions incoherent ---------------------------------------------------------------------- typo · 2014-08-16 15:14 Use Canvas.Polygon(ArrayOfTPoint). Only be sure that the user enters valid points (by asking him/her to pick the point with the mouse, for instance). ---------------------------------------------------------------------- zanghaohieu · 2014-08-17 06:29 retrieve data from array coordinates to draw ---------------------------------------------------------------------- zanghaohieu · 2014-08-17 06:36 for example type coordinates=record   x,y:integer ;   end;  mang=array[0..30] of coordinates; {Added polygon vertices}  procedure nhapdinh(var n:byte;var p:mang);  var i:byte;  begin       write('verticles :n= ');readln(n);       for i:=1 to n do       begin            write('p[',i,'].x=  ');readln(p.x);            write('p[',i,'].y=  ');readln(p.y);       end;  end; typed arrays used to draw polygons ---------------------------------------------------------------------- User137 · 2014-08-17 08:52 Just change this line to: Code: [Select]mang=array[0..30] of TPoint;You can then use ......Canvas.Polygon(mang);  where Canvas can be from any graphical component like TForm, TImage, TImage.Picture.Bitmap, TPaintBox etc. ---------------------------------------------------------------------- howardpc · 2014-08-17 12:40 From his code snippet it seems zanghaohieu wants to draw polygons in console window, not in a GUI environment. ---------------------------------------------------------------------- zanghaohieu · 2014-08-17 14:06 I want to enter data in console windowns, and then draw in the graphical environment ---------------------------------------------------------------------- taazz · 2014-08-17 14:19 Quote from: zanghaohieu on August 17, 2014, 04:06:05 pmI want to enter data in console windowns, and then draw in the graphical environment Go all graphical and forget about the console window. ---------------------------------------------------------------------- zanghaohieu · 2014-08-17 14:31 so as not to draw polygons by taking the data from the array to draw? ---------------------------------------------------------------------- taazz · 2014-08-17 14:38 As to get the input from a graphical interface too instead of a console window. ---------------------------------------------------------------------- zanghaohieu · 2014-08-17 15:02 please give me examples ---------------------------------------------------------------------- Bart · 2014-08-17 15:22 You coud use a TStringGrid with ColCount = 2, FixedRows = 1, RowCount = Nr of points you want + 1 and set the text of the top cells to 'x' and 'y'. You will have to validate the input (but you would also need to do that when using readln() on the console (your current code (in the example) will crash the program if someone enters a non-valid value). [edit]Attached demo, which lets you input coordinates in a stringgrid[/edit] Bart ---------------------------------------------------------------------- typo · 2014-08-17 16:03 Here a simple example (attached). Click on the form to set points. ---------------------------------------------------------------------- howardpc · 2014-08-17 16:27 And another example to show how to use a different mouse event. This example draws just the polygon perimeter. ---------------------------------------------------------------------- zanghaohieu · 2014-08-18 13:13 thanks typo but i have problem, you can see in this picture ---------------------------------------------------------------------- zanghaohieu · 2014-08-18 13:21 thanks howardpc i have a same problem as ---------------------------------------------------------------------- taazz · 2014-08-18 13:24 you need lazarus to compile the samples. They will not work on the fpc IDE. ---------------------------------------------------------------------- zanghaohieu · 2014-08-18 13:28 so i must install lazarus ---------------------------------------------------------------------- zanghaohieu · 2014-08-18 13:45 i installed lazarus how to use this unit ? ---------------------------------------------------------------------- typo · 2014-08-18 13:54 Probably you will not have any error message. ---------------------------------------------------------------------- taazz · 2014-08-18 13:56 use the menu "project\open project" select the lpi file from the folder you have uncompressed the sample then go to menu "run\Compile" and the select "run\run" to see the application working. Depending on what operating system you are on you might have to change some project options too.