Der eingebaute Fill braucht eine Begrenzungsfarbe. Habe das mal ergänzt.
Beide Varianten haben Vor- und Nachteile.
Aber eine Erweiterung der Grafikbefehle wäre wirklich wünschenswert.
WindowTitle "DEMO: Iterativer (Stackarray-basierter) Floodfill Algorithmus"
' (D) Demo 2017-02 by P.Specht, Wien(AT)
' um den eingebauten Fill ergänzt
font 2:declare x&[],y&[],stc&
'--------------------------------------------------
cls:Print "\n interner Fill (schnell, aber nur mit deutlicher Begrenzung)"
usepen 0,2,rgb(0,0,0):usebrush 1,rgb(0,0,0)
roundrect 39,39 - 241,141;16;24
usepen 0,2,rgb(255,0,0):usebrush 1,rgb(255,0,0)
roundrect 40,40 - 240,140;16;24
usepen 0,2,rgb(0,0,0):usebrush 1,rgb(255,0,0)
ellipse 80,80 - 140,100
waitinput 2000
usepen 0,2,rgb(0,0,255):usebrush 1,rgb(0,0,255)
Fill 100,100,rgb(0,0,0)
print "\n\n\n\n\n\n\n\n\n\n [TASTE]"
waitinput
'--------------------------------------------------
cls:Print "\n Floodfill-4"
usepen 0,2,rgb(255,0,0):usebrush 1,rgb(255,0,0)
roundrect 40,40 - 240,140;16;24
usepen 0,2,rgb(255,255,0):usebrush 1,rgb(255,0,0)
ellipse 80,80 - 140,100
iter_fill4 100,100,rgb(255,0,0),rgb(0,0,255)
print "\n\n\n\n\n\n\n\n\n\n [TASTE]"
waitinput 5000
proc iter_fill4 :parameters x&,y&,alt&,neu&
inc stc&:x&[stc&]=x&:y&[stc&]=y&
while stc&
x&=x&[stc&]:y&=y&[stc&]:dec stc&
if getPixel(x&,y&)=alt&
setPixel x&,y&,neu&
inc stc&:x&[stc&]=x&+1:y&[stc&]=y& '>
inc stc&:x&[stc&]=x&:y&[stc&]=y&-1 '^
inc stc&:x&[stc&]=x&-1:y&[stc&]=y& '<
inc stc&:x&[stc&]=x&:y&[stc&]=y&+1 'v
endif
endwhile
endproc
'--------------------------------------------------
cls:Print "\n\n Floodfill-8"
usepen 0,2,rgb(255,0,0):usebrush 1,rgb(255,0,0)
roundrect 40,40 - 240,140;16;24
usepen 0,2,rgb(255,255,0):usebrush 1,rgb(255,0,0)
ellipse 80,80 - 140,100
iter_fill8 100,100,rgb(255,0,0),rgb(0,0,255)
print "\n\n\n\n\n\n\n\n\n\n Bei FF-8 ist ein Ellipsenrand 1 zu dünn zum stoppen!"
beep:waitinput:End
proc iter_fill8 :parameters x&,y&,alt&,neu&
inc stc&:x&[stc&]=x&:y&[stc&]=y&
while stc&
x&=x&[stc&]:y&=y&[stc&]:dec stc&
if getPixel(x&,y&)=alt&
setPixel x&,y&,neu&
inc stc&:x&[stc&]=x&+1:y&[stc&]=y& '>
inc stc&:x&[stc&]=x&+1:y&[stc&]=y&-1 '>^
inc stc&:x&[stc&]=x& :y&[stc&]=y&-1 '^
inc stc&:x&[stc&]=x&-1:y&[stc&]=y&-1 '<^
inc stc&:x&[stc&]=x&-1:y&[stc&]=y& '<
inc stc&:x&[stc&]=x&-1:y&[stc&]=y&+1 '<v
inc stc&:x&[stc&]=x& :y&[stc&]=y&+1 'v
inc stc&:x&[stc&]=x&+1:y&[stc&]=y&+1 '>v
endif
endwhile
endproc
'--------------------------------------------------
Alles anzeigen