Recent

Author Topic: help: i want to draw polygon in pascal  (Read 11287 times)

zanghaohieu

  • New Member
  • *
  • Posts: 10
help: i want to draw polygon in pascal
« on: August 16, 2014, 05:08:38 pm »
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

  • Hero Member
  • *****
  • Posts: 3051
Re: help: i want to draw polygon in pascal
« Reply #1 on: August 16, 2014, 05:14:31 pm »
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).
« Last Edit: August 16, 2014, 05:43:43 pm by typo »

zanghaohieu

  • New Member
  • *
  • Posts: 10
Re: help: i want to draw polygon in pascal
« Reply #2 on: August 17, 2014, 08:29:05 am »
retrieve data from array coordinates to draw

zanghaohieu

  • New Member
  • *
  • Posts: 10
Re: help: i want to draw polygon in pascal
« Reply #3 on: August 17, 2014, 08:36:38 am »
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

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: help: i want to draw polygon in pascal
« Reply #4 on: August 17, 2014, 10:52:31 am »
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

  • Hero Member
  • *****
  • Posts: 4144
Re: help: i want to draw polygon in pascal
« Reply #5 on: August 17, 2014, 02:40:21 pm »
From his code snippet it seems zanghaohieu wants to draw polygons in console window, not in a GUI environment.

zanghaohieu

  • New Member
  • *
  • Posts: 10
Re: help: i want to draw polygon in pascal
« Reply #6 on: August 17, 2014, 04:06:05 pm »
I want to enter data in console windowns, and then draw in the graphical environment

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: help: i want to draw polygon in pascal
« Reply #7 on: August 17, 2014, 04:19:55 pm »
I want to enter data in console windowns, and then draw in the graphical environment

Go all graphical and forget about the console window.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

zanghaohieu

  • New Member
  • *
  • Posts: 10
Re: help: i want to draw polygon in pascal
« Reply #8 on: August 17, 2014, 04:31:12 pm »
so as not to draw polygons by taking the data from the array to draw?

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: help: i want to draw polygon in pascal
« Reply #9 on: August 17, 2014, 04:38:13 pm »
As to get the input from a graphical interface too instead of a console window.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

zanghaohieu

  • New Member
  • *
  • Posts: 10
Re: help: i want to draw polygon in pascal
« Reply #10 on: August 17, 2014, 05:02:58 pm »
please give me examples

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: help: i want to draw polygon in pascal
« Reply #11 on: August 17, 2014, 05:22:44 pm »
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
« Last Edit: August 17, 2014, 06:27:07 pm by Bart »

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: help: i want to draw polygon in pascal
« Reply #12 on: August 17, 2014, 06:03:05 pm »
Here a simple example (attached). Click on the form to set points.
« Last Edit: August 17, 2014, 06:05:19 pm by typo »

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: help: i want to draw polygon in pascal
« Reply #13 on: August 17, 2014, 06:27:27 pm »
And another example to show how to use a different mouse event. This example draws just the polygon perimeter.

zanghaohieu

  • New Member
  • *
  • Posts: 10
Re: help: i want to draw polygon in pascal
« Reply #14 on: August 18, 2014, 03:13:43 pm »
thanks typo
but i have problem, you can see in this picture

 

TinyPortal © 2005-2018