* * *

Author Topic: Can't fill ellipse  (Read 1535 times)

KEY G

  • New member
  • *
  • Posts: 5
Can't fill ellipse
« on: May 04, 2017, 07:13:09 pm »
Hello! I have a problem, i'm a begginer and currently trying to draw a bird on free pascal. I managed to floodfill the circles but it just doesn't to seem work right when i do the same with the ellipses. Help would be appreciated!
Here is the code:
Code: Pascal  [Select]
  1. Program putns;
  2. uses graph;
  3. var draiveris,x,y,r, tips:integer;
  4. begin
  5. Draiveris:=detect;
  6. initgraph(draiveris,tips,' ');
  7. writeln(GetMaxX,' ',GetMaxY);
  8. bar(100,80,60,120);
  9.  ellipse(105,190,0,360,20,40);
  10.  ellipse(295,190,0,360,20,40);
  11.   circle(140,100,50);
  12.  setfillstyle(1,white);
  13.  floodfill(140,100,white);
  14.  circle(260,100,50);
  15.  floodfill(260,100,white);
  16.  circle(200,200,100);
  17.  setfillstyle(1,14);
  18.  floodfill(200,200,white);
  19.  pieslice(180,160,270,360,40);
  20.  setfillstyle(1,green);
  21.  floodfill(180,160,white);
  22.  setfillstyle(1,black);
  23.  setcolor(black);
  24.  circle(150,110,20);
  25.  floodfill(150,110,black);
  26.  circle(250,110,20);
  27.  floodfill(250,110,black);
  28. readln;
  29. closegraph;
  30. end.
  31.  

molly

  • Hero Member
  • *****
  • Posts: 1692
Re: Can't fill ellipse
« Reply #1 on: May 04, 2017, 08:37:01 pm »
Please forgive my ignorance but, what graphical output are you expecting exactly ?

The flood is limited to the bounds of the given colour (in case there is such a bound).

If i fill the ellipse directly after it is drawn then it is filled correctly, so that probably isn't the graphical output you're expecting.

Perhaps the fillellipse function would be more suited for what you are trying to accomplish ? In that case the ellipse would have to be drawn drawn at the end of your drawing sequence (see also attachment)
« Last Edit: May 04, 2017, 09:37:45 pm by molly »

RAW

  • Sr. Member
  • ****
  • Posts: 309
Re: Can't fill ellipse
« Reply #2 on: May 05, 2017, 12:31:05 pm »
Oh come on molly... a bird with a red and a blue wing? What kind of a bird is that, such a bird would probably never accepted by his bird friends. I don't even think such a bird would be able to fly ...  :P
I think the wings must be green or if absolutely necessary yellow... but only if absolutely necessary...

Code: Pascal  [Select]
  1. PROGRAM BIRDY;
  2.  USES Graph;
  3.  
  4.  VAR
  5.   iVar: SmallInt;
  6.   iRes: SmallInt;
  7.  
  8. BEGIN
  9.  InitGraph(iRes, iVar, '');
  10.   Try
  11.     SetColor     (White);
  12.     SetFillStyle (1, Green);
  13.  
  14.    Ellipse      (105, 190, 0, 360, 20, 40);
  15.     FloodFill    (105, 190, White);
  16.  
  17.    Ellipse      (295, 190, 0, 360, 20, 40);
  18.     FloodFill    (295, 190, White);
  19.  
  20.    Circle       (140, 100, 50);
  21.     SetFillStyle (1, White);
  22.     Floodfill    (140, 100, White);
  23.  
  24.    Circle       (260, 100, 50);
  25.     FloodFill    (260, 100, White);
  26.  
  27.    Circle       (200, 200, 100);
  28.     SetFillStyle (1, 14);
  29.  
  30.    PieSlice     (180, 160, 270, 360, 40);
  31.     SetFillStyle (1, Green);
  32.     FloodFill    (180, 160, White);
  33.  
  34.     SetFillStyle (1, Black);
  35.     SetColor     (Black);
  36.  
  37.    Circle       (150, 110, 20);
  38.     FloodFill    (150, 110, Black);
  39.  
  40.    Circle       (250, 110, 20);
  41.     FloodFill    (250, 110, Black);
  42.  
  43.    Readln;
  44.   Finally
  45.    CloseGraph;
  46.   End;
  47. END.
  48.  
Windows 7 Pro (x64 Sp1) And Windows XP Pro (x86 Sp3) - LAZARUS 1.6.4 FPC 3.0.2

lainz

  • Hero Member
  • *****
  • Posts: 1889
  • Nace una flor, todos los días sale el sol...
    • BGRABitmap
Re: Can't fill ellipse
« Reply #3 on: May 05, 2017, 02:50:55 pm »
I like the bird, is really cute.

molly

  • Hero Member
  • *****
  • Posts: 1692
Re: Can't fill ellipse
« Reply #4 on: May 05, 2017, 03:19:37 pm »
@RAW:
My bird simply has a severe case of rgb-flu  :P

KEY G

  • New member
  • *
  • Posts: 5
Re: Can't fill ellipse
« Reply #5 on: May 05, 2017, 03:34:51 pm »
Please forgive my ignorance but, what graphical output are you expecting exactly ?

The flood is limited to the bounds of the given colour (in case there is such a bound).

If i fill the ellipse directly after it is drawn then it is filled correctly, so that probably isn't the graphical output you're expecting.

Perhaps the fillellipse function would be more suited for what you are trying to accomplish ? In that case the ellipse would have to be drawn drawn at the end of your drawing sequence (see also attachment)
This is nice but i need the wings to be behind the body of the bird. Could you please show me your code so i undertsand it?

KEY G

  • New member
  • *
  • Posts: 5
Re: Can't fill ellipse
« Reply #6 on: May 05, 2017, 03:35:46 pm »
Oh come on molly... a bird with a red and a blue wing? What kind of a bird is that, such a bird would probably never accepted by his bird friends. I don't even think such a bird would be able to fly ...  :P
I think the wings must be green or if absolutely necessary yellow... but only if absolutely necessary...

Code: Pascal  [Select]
  1. PROGRAM BIRDY;
  2.  USES Graph;
  3.  
  4.  VAR
  5.   iVar: SmallInt;
  6.   iRes: SmallInt;
  7.  
  8. BEGIN
  9.  InitGraph(iRes, iVar, '');
  10.   Try
  11.     SetColor     (White);
  12.     SetFillStyle (1, Green);
  13.  
  14.    Ellipse      (105, 190, 0, 360, 20, 40);
  15.     FloodFill    (105, 190, White);
  16.  
  17.    Ellipse      (295, 190, 0, 360, 20, 40);
  18.     FloodFill    (295, 190, White);
  19.  
  20.    Circle       (140, 100, 50);
  21.     SetFillStyle (1, White);
  22.     Floodfill    (140, 100, White);
  23.  
  24.    Circle       (260, 100, 50);
  25.     FloodFill    (260, 100, White);
  26.  
  27.    Circle       (200, 200, 100);
  28.     SetFillStyle (1, 14);
  29.  
  30.    PieSlice     (180, 160, 270, 360, 40);
  31.     SetFillStyle (1, Green);
  32.     FloodFill    (180, 160, White);
  33.  
  34.     SetFillStyle (1, Black);
  35.     SetColor     (Black);
  36.  
  37.    Circle       (150, 110, 20);
  38.     FloodFill    (150, 110, Black);
  39.  
  40.    Circle       (250, 110, 20);
  41.     FloodFill    (250, 110, Black);
  42.  
  43.    Readln;
  44.   Finally
  45.    CloseGraph;
  46.   End;
  47. END.
  48.  
I tried using the code but it shows ''try not found''. :(

molly

  • Hero Member
  • *****
  • Posts: 1692
Re: Can't fill ellipse
« Reply #7 on: May 05, 2017, 03:53:34 pm »
This is nice but i need the wings to be behind the body of the bird.
That is why i asked what you expected ;-)

It can be a bit difficult to express what you want when talking graphics.

Ok, indeed in that case your 'problem' is related to the floodfill function and the boundaries it uses. e.g. the area that gets filled is bound by the given 'border' color and that is haunting you.

Quote
Could you please show me your code so i undertsand it?

Sure, here is my corrected code with the 'wings' in the back.
Code: Pascal  [Select]
  1. Program test3;
  2.  
  3. uses
  4.   graph;
  5.  
  6. var
  7.   draiveris,x,y,r, tips:integer;
  8.  
  9. begin
  10.   Draiveris:=detect;
  11.   initgraph(draiveris,tips,' ');
  12.   writeln(GetMaxX,' ',GetMaxY);
  13.  
  14.   bar(100,80,60,120);
  15.  
  16.   setColor(red);
  17.   setfillstyle(1,red);
  18.   FillEllipse(105,190,20,40);
  19.  
  20.   setColor(blue);
  21.   setfillstyle(1,blue);
  22.   FillEllipse(295,190,20,40);
  23.  
  24.   setColor(white);
  25.   circle(140,100,50);
  26.   setfillstyle(1,white);
  27.   floodfill(140,100,white);
  28.  
  29.   circle(260,100,50);
  30.   floodfill(260,100,white);
  31.  
  32.   circle(200,200,100);
  33.   setfillstyle(1,14);
  34.   floodfill(200,200,white);
  35.  
  36.   pieslice(180,160,270,360,40);
  37.   setfillstyle(1,green);
  38.   floodfill(180,160,white);
  39.  
  40.   setfillstyle(1,black);
  41.   setcolor(black);
  42.   circle(150,110,20);
  43.   floodfill(150,110,black);
  44.  
  45.   circle(250,110,20);
  46.   floodfill(250,110,black);
  47.  
  48.   readln;
  49.   closegraph;
  50. end.
  51.  

fwiw: CAN's example also works but still shows the white drawn lines that were used as boundaries for the flood. You can get his code to compile by adding {$MODE OBJFPC} at the top of your code just beneath the program declaration.

PS: if you draw an ellipse using the 'correct' radius' then you can draw a circle with it ;-)
« Last Edit: May 05, 2017, 04:10:29 pm by molly »

Thaddy

  • Hero Member
  • *****
  • Posts: 4006
Re: Can't fill ellipse
« Reply #8 on: May 05, 2017, 03:54:24 pm »
Oh come on molly... a bird with a red and a blue wing? What kind of a bird is that,
A Macaw.
"Logically, no number of positive outcomes at the level of experimental testing can confirm a scientific theory, but a single counterexample is logically decisive."

molly

  • Hero Member
  • *****
  • Posts: 1692
Re: Can't fill ellipse
« Reply #9 on: May 05, 2017, 03:57:31 pm »
ROFL

KEY G

  • New member
  • *
  • Posts: 5
Re: Can't fill ellipse
« Reply #10 on: May 05, 2017, 05:42:18 pm »
This is nice but i need the wings to be behind the body of the bird.
That is why i asked what you expected ;-)

It can be a bit difficult to express what you want when talking graphics.

Ok, indeed in that case your 'problem' is related to the floodfill function and the boundaries it uses. e.g. the area that gets filled is bound by the given 'border' color and that is haunting you.

Quote
Could you please show me your code so i undertsand it?

Sure, here is my corrected code with the 'wings' in the back.
Code: Pascal  [Select]
  1. Program test3;
  2.  
  3. uses
  4.   graph;
  5.  
  6. var
  7.   draiveris,x,y,r, tips:integer;
  8.  
  9. begin
  10.   Draiveris:=detect;
  11.   initgraph(draiveris,tips,' ');
  12.   writeln(GetMaxX,' ',GetMaxY);
  13.  
  14.   bar(100,80,60,120);
  15.  
  16.   setColor(red);
  17.   setfillstyle(1,red);
  18.   FillEllipse(105,190,20,40);
  19.  
  20.   setColor(blue);
  21.   setfillstyle(1,blue);
  22.   FillEllipse(295,190,20,40);
  23.  
  24.   setColor(white);
  25.   circle(140,100,50);
  26.   setfillstyle(1,white);
  27.   floodfill(140,100,white);
  28.  
  29.   circle(260,100,50);
  30.   floodfill(260,100,white);
  31.  
  32.   circle(200,200,100);
  33.   setfillstyle(1,14);
  34.   floodfill(200,200,white);
  35.  
  36.   pieslice(180,160,270,360,40);
  37.   setfillstyle(1,green);
  38.   floodfill(180,160,white);
  39.  
  40.   setfillstyle(1,black);
  41.   setcolor(black);
  42.   circle(150,110,20);
  43.   floodfill(150,110,black);
  44.  
  45.   circle(250,110,20);
  46.   floodfill(250,110,black);
  47.  
  48.   readln;
  49.   closegraph;
  50. end.
  51.  

fwiw: CAN's example also works but still shows the white drawn lines that were used as boundaries for the flood. You can get his code to compile by adding {$MODE OBJFPC} at the top of your code just beneath the program declaration.

PS: if you draw an ellipse using the 'correct' radius' then you can draw a circle with it ;-)
Thank you very much!  :) 8)

RAW

  • Sr. Member
  • ****
  • Posts: 309
Re: Can't fill ellipse
« Reply #11 on: May 05, 2017, 06:01:29 pm »
Did you recognize the nose ???
I did a surgical operation... now it's better I think:

Code: Pascal  [Select]
  1. PROGRAM BIRDY;
  2. {$MODE OBJFPC}
  3.  USES Graph;
  4.  
  5.  VAR
  6.   iVar: SmallInt;
  7.   iRes: SmallInt;
  8.  
  9. BEGIN
  10.  InitGraph(iRes, iVar, '');
  11.   Try
  12.    SetColor     (Blue);
  13.    SetFillStyle (1, Blue);
  14.    FillEllipse  (105, 190, 20, 40);
  15.    FillEllipse  (295, 190, 20, 40);
  16.  
  17.    SetColor     (Green);
  18.    SetFillStyle (1, Green);
  19.    FillEllipse  (200, 200, 100, 100);
  20.  
  21.    SetColor     (White);
  22.    Circle       (140, 100, 50);
  23.    SetFillStyle (1, White);
  24.    Floodfill    (140, 100, White);
  25.  
  26.    Circle       (260, 100, 50);
  27.    FloodFill    (260, 100, White);
  28.  
  29.    SetFillStyle (1, 14);
  30.    PieSlice     (200, 200, 130, 50, 40);
  31.    SetFillStyle (1, Green);
  32.  
  33.    SetFillStyle (1, Black);
  34.    SetColor     (Black);
  35.    Circle       (150, 110, 20);
  36.    FloodFill    (150, 110, Black);
  37.  
  38.    Circle       (250, 110, 20);
  39.    FloodFill    (250, 110, Black);
  40.  
  41.    Readln;
  42.   Finally
  43.    CloseGraph;
  44.   End;
  45. END.
  46.  
Windows 7 Pro (x64 Sp1) And Windows XP Pro (x86 Sp3) - LAZARUS 1.6.4 FPC 3.0.2

Thaddy

  • Hero Member
  • *****
  • Posts: 4006
Re: Can't fill ellipse
« Reply #12 on: May 05, 2017, 06:04:57 pm »
Two eyes looking at a bit of cheese? On a green plate with blue handles? At least molly's effort can not be mistaken for a plate  O:-)
« Last Edit: May 05, 2017, 06:07:48 pm by Thaddy »
"Logically, no number of positive outcomes at the level of experimental testing can confirm a scientific theory, but a single counterexample is logically decisive."

KEY G

  • New member
  • *
  • Posts: 5
Re: Can't fill ellipse
« Reply #13 on: May 05, 2017, 06:10:25 pm »
Did you recognize the nose ???
I did a surgical operation... now it's better I think:

Code: Pascal  [Select]
  1. PROGRAM BIRDY;
  2. {$MODE OBJFPC}
  3.  USES Graph;
  4.  
  5.  VAR
  6.   iVar: SmallInt;
  7.   iRes: SmallInt;
  8.  
  9. BEGIN
  10.  InitGraph(iRes, iVar, '');
  11.   Try
  12.    SetColor     (Blue);
  13.    SetFillStyle (1, Blue);
  14.    FillEllipse  (105, 190, 20, 40);
  15.    FillEllipse  (295, 190, 20, 40);
  16.  
  17.    SetColor     (Green);
  18.    SetFillStyle (1, Green);
  19.    FillEllipse  (200, 200, 100, 100);
  20.  
  21.    SetColor     (White);
  22.    Circle       (140, 100, 50);
  23.    SetFillStyle (1, White);
  24.    Floodfill    (140, 100, White);
  25.  
  26.    Circle       (260, 100, 50);
  27.    FloodFill    (260, 100, White);
  28.  
  29.    SetFillStyle (1, 14);
  30.    PieSlice     (200, 200, 130, 50, 40);
  31.    SetFillStyle (1, Green);
  32.  
  33.    SetFillStyle (1, Black);
  34.    SetColor     (Black);
  35.    Circle       (150, 110, 20);
  36.    FloodFill    (150, 110, Black);
  37.  
  38.    Circle       (250, 110, 20);
  39.    FloodFill    (250, 110, Black);
  40.  
  41.    Readln;
  42.   Finally
  43.    CloseGraph;
  44.   End;
  45. END.
  46.  
Haha, thanks! Btw, anyone got an idea how i could get legs that look like this -
« Last Edit: May 05, 2017, 06:11:56 pm by KEY G »

RAW

  • Sr. Member
  • ****
  • Posts: 309
Re: Can't fill ellipse
« Reply #14 on: May 05, 2017, 06:19:48 pm »
@KEY G:
The yellow FloodFill in your painting is only slowing it down... you can delete it.
I bet you can handle the legs ... :)

Quote
My bird simply has a severe case of rgb-flu  :P
:D

Quote
A Macaw.
I think the macaw's like the same pattern/color on each wing... but really colorful buddies...

Quote
Two eyes looking at a bit of cheese? On a green plate with blue handles? At least molly's effort can not be mistaken for a plate  O:-)
:D  plate... I don't see any plate, that's a beautiful green torso...
You need a surgical operation too...  :P
Windows 7 Pro (x64 Sp1) And Windows XP Pro (x86 Sp3) - LAZARUS 1.6.4 FPC 3.0.2

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus