Need help with coding style of a Fill() routine
Posted: Wed Jun 15, 2005 1:37 am
i am trying to write my own drawing fill routine for my personal usage! i know purebasic has the command FillArea() - but this command doesnt do the job as i need!
So i tried to code a routine that fills any object(s) / background(s) - Even objects where the outline uses more as only color instead the pure command require! (I found an article about this in an basic coding book from 1986 and tried to rewrite it for purebasic)
The trick is to check only for the backgroundcolor you want to fill (or replace)... just take a look to the bad code and you may realise how it would work...
The routine works in my example as long as i unmark the 3rd if condition... I dont like this way (because of resulting an Overflow and i dont like Gotos!!) - If someone can help me to recode the routine and maybe speed it up, would be really cool! Thanks!
Edit: You have to call StartDrawing() before calling MyFill() procedure and call StopDrawing() after MyFill!

So i tried to code a routine that fills any object(s) / background(s) - Even objects where the outline uses more as only color instead the pure command require! (I found an article about this in an basic coding book from 1986 and tried to rewrite it for purebasic)
The trick is to check only for the backgroundcolor you want to fill (or replace)... just take a look to the bad code and you may realise how it would work...
Code: Select all
Procedure MyFill(x,y,lColorSrc.l,lColorDes.l)
If Point(x,y) = lColorDes
;
Else
If Point(x,y) = lColorSrc
;
If x > 0 And y > 0
Plot(x,y,lColorDes)
EndIf
;
; ---- Check nearest pixel ----
;
If Point (x-1, y ) = lColorSrc : MyFill (x-1, y , lColorSrc, lColorDes) : EndIf
If Point (x+1, y ) = lColorSrc : MyFill (x+1, y , lColorSrc, lColorDes) : EndIf
; If Point (x , y-1) = lColorSrc : MyFill (x , y-1, lColorSrc, lColorDes) : EndIf
If Point (x , y+1) = lColorSrc : MyFill (x , y+1, lColorSrc, lColorDes) : EndIf
EndIf
EndIf
EndProcedure
Edit: You have to call StartDrawing() before calling MyFill() procedure and call StopDrawing() after MyFill!