Rekursion

Previous topic - Next topic

CptnRoughnight

Hi leute,
hab mich mal dran gemacht ein Paint-Programm für meinen WIZ zu coden, brauche jetzt allerding Hilfe, da meine Floodfill-Routine net hinhaut, sitze da schon seit ewiger Zeit dran  :rant:

Code (glbasic) Select
FUNCTION fill: x%,y%,rand,farbe

IF (pix_map[x][y] <> rand)
pix_map[x][y]=farbe       
fill(x,y+1,rand,farbe)
fill(x,y-1,rand,farbe)
fill(x+1,y,rand,farbe)
fill(x-1,y,rand,farbe)

ENDIF
RETURN
ENDFUNCTION


Jetzt ist das im Endeffekt der Algorithmus der in Wikipedia zu finden ist, denke auch das der Code in C funzen würde, allerdings wenn ich compiliere und ausführe (GLBasic 7.250) dann beendet es das Programm wenn ich eine Fläche füllen möchte.
Meine Vermutung ist das GLBasic die Rekursion nicht mag, oder liegts woanders?

Bitte um schnelle Hilfe!

MfG

Moru

You have to be careful with too deep recursion, depends on stack-space.

CptnRoughnight

Yes, that is already known to me, it's only the 1st Stage and it does not work. The depth test is added later when it is finally time to see what to do.

Kitty Hello

Code (glbasic) Select


FUNCTION myFill: x,y,rand, farbe
local bufx[], bufy[]
dimpush bufx[], x
dimpush bufy[], y

while len(bufx[])
  local x = bufx[-1]
  local y = bufy[-1]

  if pix_map[x-1][y]<> rand and pix_map[x-1][y]<>farbe // nicht nochmal mit farbe füllen!!
    dimpush bufx[], x-1
    dimpush bufy[], y
  endif
...


wend


ENDFUNCTION




CptnRoughnight

Hi "Kitty Hello"

vielen Dank für den Post, hat mich mal in die richtige Richtung gebracht    :good:
mal sehen obs nun ein "Gimp" für den WIZ wird  =D

MfG

Schranz0r

Hau in die Tasten ;)
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard