Forum > Beginners

FloodFill, FPC and lack of understanding

(1/2) > >>

yugorin:
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program q; {$mode objfpc}{$H+} uses  {$IFDEF UNIX}{$IFDEF UseCThreads}  cthreads,  {$ENDIF}{$ENDIF}  Classes,  sysutils, video, crt,dos,graph, WinCrt, Windows; var error, tryb, sterownik : smallint;var i, pozycjax1, pozycjay1, pozycjax2, pozycjay2 : integer;var maksX, maksY : string;ustawienia_tekstu : TextSettingsType; //===========================================================// Graph init                                              ////===========================================================begin  sterownik := D4bit;  tryb := m640x480;  initgraph(sterownik,tryb,'');  { Make sure you always check graphresult! }  error := graphResult;  if (error <> grOk) Then    begin    writeln('640x200x15 is not supported!');    halt(1)    end;  { We are now in 640x200x15 }  //setColor(cyan);  { maksX := IntToStr(getmaxx);  maksY := IntToStr(getmaxy);  SetTextStyle(TSCRFont,0,3);  MoveTo(0,0);   OutText(maksX);  MoveTo(0,30);  OutText(maksY);  MoveTo(0,60);  OutText('To jest tekst'); }   setColor(red);  setfillstyle(solidfill,12);  Circle(20,20,5);   // setfillstyle(solidfill,random(14)+1);// floodfill(21,20,15);  FloodFill ( 26, 21, red, green ); // FloodFill(22,28,2,red);   SetLineStyle(0,1,2);  setColor(green);   Line(0,0,getmaxx,0);  Line(getmaxx,0,getmaxx,getmaxy);  Line(getmaxx,getmaxy,0,getmaxy);  Line(0,0,0,getmaxy); {  for i:=0 to 1 do   begin  setColor(red);  Line(0,i,getmaxx,i);   setColor(red);  Line(0,i+1,639,i+1);    setColor(blue);  Line(0,i+2,639,i+2);  setColor(blue);  Line(0,i+3,639,i+3);   setColor(yellow);  Line(0,i+4,639,i+1);  setColor(yellow);  Line(0,i,639,i);   setColor(red);  Line(0,i,639,i);  setColor(red);  Line(0,i,639,i);   setColor(white);  Line(0,i,639,i);  setColor(white);  Line(0,i,639,i); } // end;   { GetTextSettings(ustawienia_tekstu);  writeln ('Font : ', ustawienia_tekstu.Font);  writeln ('Kierunek : ', ustawienia_tekstu.direction);  writeln ('Wielkosc font : ', ustawienia_tekstu.charsize);  writeln ('Pozioma pozycja : ', ustawienia_tekstu.horiz);  writeln ('Pionowa pozycja : ', ustawienia_tekstu.vert);  }  readln();  end. 
Thank You
all the best
Yugorin

winni:
Hi!

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


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- procedure FloodFill(X, Y: Integer; FillColor: TColor;                        FillStyle: TFillStyle);
where FillStyle is defined:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---TGraphicsFillStyle =  (    fsSurface, // fill till the color (it fills all except this color)    fsBorder   // fill this color (it fills only connected pixels of this color)  );  


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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Canvas.Floodfill(100,100,clBlack fsSurface);
Winni

howardpc:
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:

--- Quote from: winni 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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- procedure FloodFill(X, Y: Integer; FillColor: TColor;                        FillStyle: TFillStyle);WOW :) great shortcut

where FillStyle is defined:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---TGraphicsFillStyle =  (    fsSurface, // fill till the color (it fills all except this color)    fsBorder   // fill this color (it fills only connected pixels of this color)  );  


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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Canvas.Floodfill(100,100,clBlack fsSurface);
Winni

--- End quote ---

Huh..


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Kompilowany projekt, Obiekt docelowy: q.exe: Kod wyjścia 1,Błędy: 3,q.pas(53,1) Error: Identifier not found "Canvas"q.pas(53,26) Error: Identifier not found "clBlack"q.pas(53,34) Fatal: Syntax error, ")" expected but "identifier FSSURFACE" found 
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:

--- Quote from: howardpc 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.

--- End quote ---

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

Navigation

[0] Message Index

[#] Next page

Go to full version