Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 190
  • Last Modified:

Ellipse question

I want to follow the line from an Ellipse. So I drop a shape on a form, switch it to stEllipse. I want to draw a character on a start point on the ellipse and then move it over the lineall the way the ellipse round untill it is on the startingpoint again. How do I get the positions of the pixels of the Ellipse?
0
mpoots
Asked:
mpoots
1 Solution
 
gmayoCommented:
procedure EllipsePoint(angle_degrees, left, top, right, bottom : integer; var x, y : integer);
var
      w, h, xc, yc : integer;
begin
      w := (right - left) div 2;
      h := (bottom - top) div 2;
      xc := left + w;
      yc := top + h;
      x := Round(xc + w * Sin(DegToRad(angle_degrees)));
      y := Round(yc + h * Cos(DegToRad(angle_degrees)));
end;

procedure TForm1.Button2Click(Sender: TObject);
var
      i, x, y : integer;
begin
      for i := 0 to 360 do begin
            EllipsePoint(i, 200, 200, 250, 300, x, y);
            Canvas.Pixels[x,y] := clBlack;
      end;
end;


The second routine draws an ellipse based on the parameters passed to EllipsePoint. The angle_degrees is the angle (0 to 360) in degrees that you need. Note that this starts from 6 o'clock and works anti-clockwise, so 90 degrees is 3 o'clock, 180 degrees is 12 o'clock.

The other parameters give the bounding box, and the values are returned in x/y.

Geoff M.
0
 
mpootsAuthor Commented:
Incredible... Big kuddos to you my good man. Awesome stuff.

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now