Bookstore

 Computer Math and Games in Pascal (preview) Lazarus Handbook

Author Topic: How to draw outlined ellipse?  (Read 19122 times)

Leledumbo

• Hero Member
• Posts: 8496
• Programming + Glam Metal + Tae Kwon Do = Me
How to draw outlined ellipse?
« on: August 20, 2008, 08:04:29 am »
For rectangle, there are Canvas.Rectangle (outlined) and Canvas.FillRect (filled). But for ellipse, there's only Canvas.Ellipse!

DougNettleton

• Jr. Member
• Posts: 84
RE: How to draw outlined ellipse?
« Reply #1 on: August 20, 2008, 05:18:54 pm »
I'm not an expert on this stuff, but ...

Image1.Canvas.Pen.Color := clWhite;
Image1.Canvas.Brush.Color := clWhite;
Image1.Canvas.Rectangle(0,0,Image1.Width, Image1.Height);

and

Image1.Canvas.Pen.Color := clBlack;
Image1.Canvas.Brush.Color := clWhite;
Image1.Canvas.FillRect(0,0,Image1.Width, Image1.Height);

appear to be equivalent

if you try the following ...

Image1.Canvas.Brush.Color := clWhite;
Image1.Canvas.Pen.Color := clRed;
Image1.Canvas.Ellipse(6,6,39,64);

Image1.Canvas.Pen.Color := clBlack;
Image1.Canvas.Brush.Color := clRed;
Image1.Canvas.Ellipse(106,106,139,164);

Image1.Canvas.Rectangle(206,206,239,264);

I think you'll see that Ellipse and Rectangle work the same way, i.e. the shape is the Pen color and they're filled with the Brush color.

If you're trying to draw an ellipse over multiple other objects, without disturbing their contents, I guess you could use Arc like...

Image1.Canvas.Arc(106,6,139,64,139,6,139,6);

or even simpler ...

Image1.Canvas.Arc(106,6,139,64,0,0,0,0);

And for a similar line rectangle ...

Image1.Canvas.MoveTo(206,6);
Image1.Canvas.LineTo(206,64);
Image1.Canvas.LineTo(239,64);
Image1.Canvas.LineTo(239,6);
Image1.Canvas.LineTo(206,6);

or

Image1.Canvas.Polyline([point(206,6),point(206,64),point(239,64),Point(239,6),point(206,6)]);

HTH,

Doug

Leledumbo

• Hero Member
• Posts: 8496
• Programming + Glam Metal + Tae Kwon Do = Me
RE: How to draw outlined ellipse?
« Reply #2 on: August 21, 2008, 08:21:03 am »
Quote
If you're trying to draw an ellipse over multiple other objects, without disturbing their contents, I guess you could use Arc

Quite a lot to type, but better than nothing. Thanks. I'll make a wrapper for it.

johnnylee

• Newbie
• Posts: 4
Re: How to draw outlined ellipse?
« Reply #3 on: February 08, 2018, 05:08:52 pm »
Late, but I think this is a simpler solution, with the current Lazarus as of 2018, and it can still help anyone landing in this thread when they google search, (which included me).

Canvas.Brush.Style := bsClear;