Recent

Author Topic: FloodFill, FPC and lack of understanding  (Read 2863 times)

yugorin

  • New member
  • *
  • Posts: 7
FloodFill, FPC and lack of understanding
« on: December 31, 2021, 07:59:11 pm »
Hi

I'm asking for help again because I don't understand what I'm doing wrong. I have read in the manual

FloodFill(x: SmallInt; y: SmallInt; Border: ColorType)

Example - if I draw a circle with a red border and point to the center of that circle (which is black) with a boundary of Red

FloodFill( 21, 21, red)

This circle should fill with the color set by SetColor

However, when I type

FloodFill (
then the compiler requests 4 parameters from me (para_1 (HDC??), para_2 (longInt), para_3(LongInt) and para_4 (LongInt)).

To put it simply - I've gone crazy :) Can someone help me change the code to make this little circle fill with any color (other than black).

Code: Pascal  [Select][+][-]
  1. program q;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   {$IFDEF UNIX}{$IFDEF UseCThreads}
  7.   cthreads,
  8.   {$ENDIF}{$ENDIF}
  9.   Classes,
  10.   sysutils, video, crt,dos,graph, WinCrt, Windows;
  11.  
  12. var error, tryb, sterownik : smallint;
  13. var i, pozycjax1, pozycjay1, pozycjax2, pozycjay2 : integer;
  14. var maksX, maksY : string;
  15. ustawienia_tekstu : TextSettingsType;
  16.  
  17. //===========================================================
  18. // Graph init                                              //
  19. //===========================================================
  20. begin
  21.   sterownik := D4bit;
  22.   tryb := m640x480;
  23.   initgraph(sterownik,tryb,'');
  24.   { Make sure you always check graphresult! }
  25.   error := graphResult;
  26.   if (error <> grOk) Then
  27.     begin
  28.     writeln('640x200x15 is not supported!');
  29.     halt(1)
  30.     end;
  31.   { We are now in 640x200x15 }
  32.   //setColor(cyan);
  33.  
  34.  { maksX := IntToStr(getmaxx);
  35.   maksY := IntToStr(getmaxy);
  36.   SetTextStyle(TSCRFont,0,3);
  37.   MoveTo(0,0);
  38.  
  39.   OutText(maksX);
  40.   MoveTo(0,30);
  41.   OutText(maksY);
  42.   MoveTo(0,60);
  43.   OutText('To jest tekst');
  44.  }
  45.  
  46.   setColor(red);
  47.   setfillstyle(solidfill,12);
  48.   Circle(20,20,5);
  49.  
  50.   // setfillstyle(solidfill,random(14)+1);
  51. // floodfill(21,20,15);
  52.   FloodFill ( 26, 21, red, green );
  53.  // FloodFill(22,28,2,red);
  54.  
  55.  
  56.  SetLineStyle(0,1,2);
  57.   setColor(green);
  58.  
  59.   Line(0,0,getmaxx,0);
  60.   Line(getmaxx,0,getmaxx,getmaxy);
  61.   Line(getmaxx,getmaxy,0,getmaxy);
  62.   Line(0,0,0,getmaxy);
  63.  
  64. {  for i:=0 to 1 do
  65.  
  66.   begin
  67.   setColor(red);
  68.   Line(0,i,getmaxx,i);
  69.  
  70.   setColor(red);
  71.   Line(0,i+1,639,i+1);
  72.  
  73.  
  74.   setColor(blue);
  75.   Line(0,i+2,639,i+2);
  76.   setColor(blue);
  77.   Line(0,i+3,639,i+3);
  78.  
  79.   setColor(yellow);
  80.   Line(0,i+4,639,i+1);
  81.   setColor(yellow);
  82.   Line(0,i,639,i);
  83.  
  84.   setColor(red);
  85.   Line(0,i,639,i);
  86.   setColor(red);
  87.   Line(0,i,639,i);
  88.  
  89.   setColor(white);
  90.   Line(0,i,639,i);
  91.   setColor(white);
  92.   Line(0,i,639,i);
  93.  }
  94.  // end;
  95.  
  96.  
  97.  { GetTextSettings(ustawienia_tekstu);
  98.   writeln ('Font : ', ustawienia_tekstu.Font);
  99.   writeln ('Kierunek : ', ustawienia_tekstu.direction);
  100.   writeln ('Wielkosc font : ', ustawienia_tekstu.charsize);
  101.   writeln ('Pozioma pozycja : ', ustawienia_tekstu.horiz);
  102.   writeln ('Pionowa pozycja : ', ustawienia_tekstu.vert);
  103.   }
  104.   readln();
  105.   end.
  106.  

Thank You
all the best
Yugorin

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: FloodFill, FPC and lack of understanding
« Reply #1 on: December 31, 2021, 08:18:57 pm »
Hi!

Place your  cursor on FloodFill and press Alt-CursorUp - and you see the definition of FloodFill:

Code: Pascal  [Select][+][-]
  1.  procedure FloodFill(X, Y: Integer; FillColor: TColor;
  2.                         FillStyle: TFillStyle);

where FillStyle is defined:

Code: Pascal  [Select][+][-]
  1. TGraphicsFillStyle =
  2.   (
  3.     fsSurface, // fill till the color (it fills all except this color)
  4.     fsBorder   // fill this color (it fills only connected pixels of this color)
  5.   );
  6.  
 


If you want to fill a black circle with color and the center of the circle is 100/100 you have to do:

Code: Pascal  [Select][+][-]
  1. Canvas.Floodfill(100,100,clBlack fsSurface);

Winni
« Last Edit: December 31, 2021, 08:25:14 pm by winni »

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: FloodFill, FPC and lack of understanding
« Reply #2 on: December 31, 2021, 08:26:20 pm »
You are programming a console application for Windows only ("uses ... Windows;"), consequently the FloodFill() you call is simply a Pascal wrapper round the Windows gdi32.dll routine of that name which has 4 parameters.

You found information about the LCL Floodfill routine in the Graphics unit which you are not using, since yours is a console, not a GUI app.

yugorin

  • New member
  • *
  • Posts: 7
Re: FloodFill, FPC and lack of understanding
« Reply #3 on: December 31, 2021, 08:37:41 pm »
Hi!

Place your  cursor on FloodFill and press Alt-CursorUp - and you see the definition of FloodFill:

Code: Pascal  [Select][+][-]
  1.  procedure FloodFill(X, Y: Integer; FillColor: TColor;
  2.                         FillStyle: TFillStyle);
WOW :) great shortcut

where FillStyle is defined:

Code: Pascal  [Select][+][-]
  1. TGraphicsFillStyle =
  2.   (
  3.     fsSurface, // fill till the color (it fills all except this color)
  4.     fsBorder   // fill this color (it fills only connected pixels of this color)
  5.   );
  6.  
 


If you want to fill a black circle with color and the center of the circle is 100/100 you have to do:

Code: Pascal  [Select][+][-]
  1. Canvas.Floodfill(100,100,clBlack fsSurface);

Winni

Huh..

Code: Pascal  [Select][+][-]
  1. Kompilowany projekt, Obiekt docelowy: q.exe: Kod wyjścia 1,Błędy: 3,
  2. q.pas(53,1) Error: Identifier not found "Canvas"
  3. q.pas(53,26) Error: Identifier not found "clBlack"
  4. q.pas(53,34) Fatal: Syntax error, ")" expected but "identifier FSSURFACE" found
  5.  

Because I want to (very deliberately) use "DOS" mode for this application. Typically a console graphical version. I think that may be where the problem lies. Is it possible to fill in a drawn circle in this DOS mode?

yugorin

  • New member
  • *
  • Posts: 7
Re: FloodFill, FPC and lack of understanding
« Reply #4 on: December 31, 2021, 08:40:35 pm »
You are programming a console application for Windows only ("uses ... Windows;"), consequently the FloodFill() you call is simply a Pascal wrapper round the Windows gdi32.dll routine of that name which has 4 parameters.

You found information about the LCL Floodfill routine in the Graphics unit which you are not using, since yours is a console, not a GUI app.

Yes, console app. Is it possible to fill in a drawn circle in this DOS/console mode?

I am anxious to get as close as possible to programming in old pascal. E.g. Turbo pascal 7. without modern libraries and add-ons. :)

This is a website with info about floodfill

https://lazarus-ccr.sourceforge.io/docs/rtl/graph/floodfill.html

Question is - anybody can modify my code to fill this small circle under console graph mode?

All the best
Yugorin
« Last Edit: December 31, 2021, 08:52:25 pm by yugorin »

yugorin

  • New member
  • *
  • Posts: 7
Re: FloodFill, FPC and lack of understanding
« Reply #5 on: December 31, 2021, 11:00:17 pm »
Hi

My mistake and fatigue. I did not understand well what you wrote. I removed unnecessary unit from uses and now it looks like this:

Code: Pascal  [Select][+][-]
  1. uses sysutils, crt, dos, graph;
  2.  

And the circle is red!!!

Thank you for your time and help.

Happy New Year!

 

TinyPortal © 2005-2018