### Bookstore

 Computer Math and Games in Pascal (preview) Lazarus Handbook

### Author Topic: Solved: Draw stars inside polygons and Get Rid of extra vertical line  (Read 545 times)

#### Boleeman

• Hero Member
• Posts: 537
##### Solved: Draw stars inside polygons and Get Rid of extra vertical line
« on: May 19, 2024, 09:45:12 am »
Corrected version is attached in the 4th REPLY BELOW.

G'Day All.

I converted some CSharp code ( from http://www.csharphelper.com/howtos/howto_draw_ngon_stars.html  ) to Lazarus and have added a scalefactor to scale the smaller images that get drawn around the center image..

I was trying to get rid of a small vertical line at the bottom, which happens for even values of number of vertices but somehow I cannot find how (as shown in the attached picture).

How to get rid of that small vertical line is what I am trying to do?

Paweld was able to fix this for me in next thread. Thank you Paweld.
« Last Edit: May 19, 2024, 11:40:19 am by Boleeman »

#### paweld

• Hero Member
• Posts: 1061
##### Re: Draw stars inside polygons: How to Get Rid of extra vertical line
« Reply #1 on: May 19, 2024, 10:46:58 am »
Code: Pascal  [Select][+][-]
1. procedure TForm1.DrawScaledStar(ACanvas: TCanvas; x, y: Integer; orig_pts: array of TPoint; skip: Integer; AscaleFactor: Double);
2. var
3.   pts: array of TPoint;
4.   i, pointIndex: Integer;
5. begin
6.   SetLength(pts, NumPoints);
7.   for i := 0 to NumPoints - 1 do
8.   begin
9.     if (skip * 2) = NumPoints then
10.       continue;
11.     pointIndex := (i * skip) mod NumPoints;
12.     pts[i] := Point(Round(x + orig_pts[pointIndex].X * AscaleFactor), Round(y + orig_pts[pointIndex].Y * AscaleFactor));
13.   end;
14.   for i := 0 to High(pts) - 1 do
15.   begin
16.       ACanvas.Line(pts[i].X, pts[i].Y, pts[i + 1].X, pts[i + 1].Y);
17.   end;
18.   ACanvas.Line(pts[High(pts)].X, pts[High(pts)].Y, pts[0].X, pts[0].Y);
19. end;
Best regards / Pozdrawiam
paweld

#### Boleeman

• Hero Member
• Posts: 537
##### Re: Draw stars inside polygons: How to Get Rid of extra vertical line
« Reply #2 on: May 19, 2024, 11:27:28 am »
Paweld to the Rescue. "if (skip * 2) = NumPoints then"   Cant believe it.

It was driving me crazy, trying to remove that one little vertical line.

Thanks for helping me out Paweld.

#### 440bx

• Hero Member
• Posts: 4233
##### Re: Draw stars inside polygons: How to Get Rid of extra vertical line
« Reply #3 on: May 19, 2024, 11:34:42 am »
Paweld to the Rescue. "if (skip * 2) = NumPoints then"   Cant believe it.

It was driving me crazy, trying to remove that one little vertical line.

Thanks for helping me out Paweld.
Just a suggestion: post a corrected version of your program so people don't have to remember that it requires a manual correction to operate properly.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

#### Boleeman

• Hero Member
• Posts: 537
##### Re: Solved: Draw stars inside polygons and Get Rid of extra vertical line
« Reply #4 on: May 19, 2024, 11:38:34 am »
OK 440bx

Attached below is the fixed up version.

#### 440bx

• Hero Member
• Posts: 4233
##### Re: Solved: Draw stars inside polygons and Get Rid of extra vertical line
« Reply #5 on: May 19, 2024, 11:40:03 am »
OK 440bx

Attached below is the fixed up version.
Thank you.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

#### Boleeman

• Hero Member
• Posts: 537
##### Re: Solved: Draw stars inside polygons and Get Rid of extra vertical line
« Reply #6 on: May 19, 2024, 11:41:25 am »
You are welcome 440bx.