Recent

Author Topic: [solved]Pascal:problems of drawing a circle with colour  (Read 10915 times)

7vinbaby

  • Jr. Member
  • **
  • Posts: 59
  • Hi ! Bless you have a good day.
[solved]Pascal:problems of drawing a circle with colour
« on: October 10, 2016, 06:22:00 am »
Could i draw a circle with colour? And what are the functions i need?
I only know how to draw a circle but not in colour.
Please give me some help....
« Last Edit: October 10, 2016, 11:40:53 am by 7vinbaby »
7vinbaby

Thaddy

  • Hero Member
  • *****
  • Posts: 17157
  • Ceterum censeo Trump esse delendam
Re: Pascal:problems of drawing a circle with colour
« Reply #1 on: October 10, 2016, 06:50:11 am »
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   form1.canvas.brush.color := clGreen;   // is the fillcolor for the circle
  4.   form1.canvas.Ellipse(100,100,200,200);
  5.   form1.canvas.Pen.color := clRed; // Is the color for drawing lines
  6.   form1.canvas.MoveTo(100,100);
  7.   form1.canvas.LineTo(200,200);
  8. end;  
  9.  
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

7vinbaby

  • Jr. Member
  • **
  • Posts: 59
  • Hi ! Bless you have a good day.
Re: Pascal:problems of drawing a circle with colour
« Reply #2 on: October 10, 2016, 07:06:43 am »
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   form1.canvas.brush.color := clGreen;   // is the fillcolor for the circle
  4.   form1.canvas.Ellipse(100,100,200,200);
  5.   form1.canvas.Pen.color := clRed; // Is the color for drawing lines
  6.   form1.canvas.MoveTo(100,100);
  7.   form1.canvas.LineTo(200,200);
  8. end;  
  9.  

i am using pascal 2.6.4 .
I think the coding above is not applicate in that version,am i right or not?
7vinbaby

Thaddy

  • Hero Member
  • *****
  • Posts: 17157
  • Ceterum censeo Trump esse delendam
Re: Pascal:problems of drawing a circle with colour
« Reply #3 on: October 10, 2016, 07:39:10 am »
That should work with older Lazarus versions and older fpc versions too, but you should really upgrade if you are still using an old and unsupported version. Hey, its free!

So: This also works with fpc 2.6.4. and an older Lazarus.

What problems do you have, if any?
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

7vinbaby

  • Jr. Member
  • **
  • Posts: 59
  • Hi ! Bless you have a good day.
Re: Pascal:problems of drawing a circle with colour
« Reply #4 on: October 10, 2016, 08:08:21 am »
That should work with older Lazarus versions and older fpc versions too, but you should really upgrade if you are still using an old and unsupported version. Hey, its free!

So: This also works with fpc 2.6.4. and an older Lazarus.

What problems do you have, if any?

actually i follow what you do but some errors happen such as 'Not found canvas' or 'Not found clred.
Do i need to declare sth or do i miss some important?
7vinbaby

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Pascal:problems of drawing a circle with colour
« Reply #5 on: October 10, 2016, 08:21:48 am »
Quote
...but some errors happen such as 'Not found canvas' or 'Not found clred.
Works out of the box with Lazarus/fpc 2.6.4 a fresh new form with a button, adding the event through object inspector so ...erhm... you must have messed something up there.

Attach your project (only .lpr, .lfm and .pas files).

wp

  • Hero Member
  • *****
  • Posts: 12864
Re: Pascal:problems of drawing a circle with colour
« Reply #6 on: October 10, 2016, 10:02:18 am »
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   form1.canvas.brush.color := clGreen;   // is the fillcolor for the circle
  4.   form1.canvas.Ellipse(100,100,200,200);
  5.   form1.canvas.Pen.color := clRed; // Is the color for drawing lines
  6.   form1.canvas.MoveTo(100,100);
  7.   form1.canvas.LineTo(200,200);
  8. end;  
  9.  
Thaddy, is this your code seriously? Why do you show an obviously unexperienced user to use the name of the instance in the code of the class? The correct code would be
Code: Pascal  [Select][+][-]
  1. [code=pascal]
  2. procedure TForm1.Button1Click(Sender: TObject);
  3. begin
  4.   Canvas.brush.color := clGreen;   // is the fillcolor for the circle
  5.   Canvas.Ellipse(100,100,200,200);
  6.   Canvas.Pen.color := clRed; // Is the color for drawing lines
  7.   Canvas.MoveTo(100,100);
  8.   Canvas.LineTo(200,200);
  9. end;  

Thaddy

  • Hero Member
  • *****
  • Posts: 17157
  • Ceterum censeo Trump esse delendam
Re: Pascal:problems of drawing a circle with colour
« Reply #7 on: October 10, 2016, 10:04:33 am »
Yes, maybe you are right. Anyway I used it this way to show that the canvas is a property of the form.

Maybe this helps (with same issue):
http://freepascal.thaddy.com/1.avi
« Last Edit: October 10, 2016, 10:06:32 am by Thaddy »
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

wp

  • Hero Member
  • *****
  • Posts: 12864
Re: Pascal:problems of drawing a circle with colour
« Reply #8 on: October 10, 2016, 10:23:40 am »
@7vinbaby:  NEVER use the name of the form in the code of the class. If you'll once create another instance of TForm1 - which will have a different name then, of course, - or rename Form1 to MyPaintForm then your code will not work any more.

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Pascal:problems of drawing a circle with colour
« Reply #9 on: October 10, 2016, 10:44:41 am »
@7vinbaby:
Are you perhaps attempting to draw a circle for your air traffic control program ?

If so, then the given advice won't help you as you asked the question in the LCL forums while your program is a dos only program. LCL is using windows and controls which are not suited for a dos program (unless you incorporate your program into a LCL form unit).

For your dos program you would need unit graph to be able to draw circles (and a whole other set of commands), but afaik it has the drawback that you can not write text to a graphics screen with writeln commands.
« Last Edit: October 10, 2016, 10:52:49 am by molly »

7vinbaby

  • Jr. Member
  • **
  • Posts: 59
  • Hi ! Bless you have a good day.
Re: Pascal:problems of drawing a circle with colour
« Reply #10 on: October 10, 2016, 10:59:06 am »
@7vinbaby:
Are you perhaps attempting to draw a circle for your air traffic control program ?

If so, then the given advice won't help you as you asked the question in the LCL forums while your program is a dos only program. LCL is using windows and controls which are not suited for a dos program (unless you incorporate your program into a LCL form unit).

For your dos program you would need unit graph to be able to draw circles (and a whole other set of commands), but afaik it has the drawback that you can not write text to a graphics screen with writeln commands.

yes,it is an assessment of the air traffic control program.
And i also try to use graph but i only know how to draw a circle but not fill in color.
Therefore I want to ask whether i can reach my goal..
7vinbaby

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Pascal:problems of drawing a circle with colour
« Reply #11 on: October 10, 2016, 11:07:44 am »
@7vinbaby
In that case you require the command [urlhttp://www.freepascal.org/docs-html-3.0.0/rtl/graph/fillellipse.html]FillElipse[/url].

A basic example on unit graph usage can be found here but, do note that the example is oriented for how to ue the graphics mode setup.

7vinbaby

  • Jr. Member
  • **
  • Posts: 59
  • Hi ! Bless you have a good day.
Re: Pascal:problems of drawing a circle with colour
« Reply #12 on: October 10, 2016, 11:21:52 am »
@7vinbaby
In that case you require the command [urlhttp://www.freepascal.org/docs-html-3.0.0/rtl/graph/fillellipse.html]FillElipse[/url].

A basic example on unit graph usage can be found here but, do note that the example is oriented for how to ue the graphics mode setup.

i make it but can it possible to make a circle with filled color but not just the colored line.
7vinbaby

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Pascal:problems of drawing a circle with colour
« Reply #13 on: October 10, 2016, 11:33:01 am »
The following snippet will draw a ellipse with colour cyan ( setColor(cyan) ) and fill it with color cyan (SetFillStyle(SolidFill, cyan) )
Code: Pascal  [Select][+][-]
  1.   setColor(cyan);
  2.   SetFillStyle(SolidFill, cyan);
  3.   FillEllipse(100,100, 50, 50);

7vinbaby

  • Jr. Member
  • **
  • Posts: 59
  • Hi ! Bless you have a good day.
Re: Pascal:problems of drawing a circle with colour
« Reply #14 on: October 10, 2016, 11:40:39 am »
thanks all your helps!!!
7vinbaby

 

TinyPortal © 2005-2018