GLBasic forum

Other languages => GLBasic - de => Topic started by: CptnRoughnight on 2010-Feb-08

Title: Rekursion
Post by: CptnRoughnight on 2010-Feb-08
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
Title: Re: Rekursion
Post by: Moru on 2010-Feb-08
You have to be careful with too deep recursion, depends on stack-space.
Title: Re: Rekursion
Post by: CptnRoughnight on 2010-Feb-08
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.
Title: Re: Rekursion
Post by: Kitty Hello on 2010-Feb-09
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



Title: Re: Rekursion
Post by: CptnRoughnight on 2010-Feb-09
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
Title: Re: Rekursion
Post by: Schranz0r on 2010-Feb-09
Hau in die Tasten ;)