Added boundary fill, and removed unused variables.
This commit is contained in:
parent
89602f1804
commit
bbdb7a3033
3 changed files with 213 additions and 135 deletions
|
|
@ -222,6 +222,78 @@ sub floodfill (startx,starty,fillcolor~&)
|
|||
wend
|
||||
end sub
|
||||
|
||||
sub boundaryfill (startx,starty,fillcolor~&,boundarycolor~&)
|
||||
' Boundary check safety gates
|
||||
if startx < 0 or startx >= _width or starty < 0 or starty >= _height then exit sub
|
||||
|
||||
' If the starting pixel is already the boundary or the fill color, exit immediately
|
||||
dim currentcolor~&
|
||||
currentcolor~& = point(startx,starty)
|
||||
if currentcolor~& = boundarycolor~& or currentcolor~& = fillcolor~& then exit sub
|
||||
|
||||
dim stackx(2000) as integer
|
||||
dim stacky(2000) as integer
|
||||
stackptr=1
|
||||
|
||||
stackx(stackptr)=startx
|
||||
stacky(stackptr)=starty
|
||||
|
||||
while stackptr>0
|
||||
curx=stackx(stackptr)
|
||||
cury=stacky(stackptr)
|
||||
stackptr=stackptr-1
|
||||
|
||||
' Move to the left edge of the region until we hit a boundary or fillcolor
|
||||
x=curx
|
||||
while x>=0
|
||||
currentcolor~& = point(x,cury)
|
||||
if currentcolor~& = boundarycolor~& or currentcolor~& = fillcolor~& then exit while
|
||||
x=x-1
|
||||
wend
|
||||
x=x+1
|
||||
|
||||
spanabove=0
|
||||
spanbelow=0
|
||||
|
||||
' Process the span moving right
|
||||
while x<_width
|
||||
currentcolor~& = point(x,cury)
|
||||
if currentcolor~& = boundarycolor~& or currentcolor~& = fillcolor~& then exit while
|
||||
|
||||
pset (x,cury),fillcolor~&
|
||||
|
||||
' Check row above
|
||||
if cury>0 then
|
||||
dim colorabove~&
|
||||
colorabove~& = point(x,cury-1)
|
||||
if spanabove=0 and colorabove~& <> boundarycolor~& and colorabove~& <> fillcolor~& then
|
||||
stackptr=stackptr+1
|
||||
stackx(stackptr)=x
|
||||
stacky(stackptr)=cury-1
|
||||
spanabove=1
|
||||
elseif spanabove=1 and (colorabove~& = boundarycolor~& or colorabove~& = fillcolor~&) then
|
||||
spanabove=0
|
||||
end if
|
||||
end if
|
||||
|
||||
' Check row below
|
||||
if cury<_height-1 then
|
||||
dim colorbelow~&
|
||||
colorbelow~& = point(x,cury+1)
|
||||
if spanbelow=0 and colorbelow~& <> boundarycolor~& and colorbelow~& <> fillcolor~& then
|
||||
stackptr=stackptr+1
|
||||
stackx(stackptr)=x
|
||||
stacky(stackptr)=cury+1
|
||||
spanbelow=1
|
||||
elseif spanbelow=1 and (colorbelow~& = boundarycolor~& or colorbelow~& = fillcolor~&) then
|
||||
spanbelow=0
|
||||
end if
|
||||
end if
|
||||
x=x+1
|
||||
wend
|
||||
wend
|
||||
end sub
|
||||
|
||||
sub ditheredgradient (x1 as long,y1 as long,x2 as long,y2 as long,fcol as _unsigned long,bcol as _unsigned long)
|
||||
' 1. Get canvas boundaries from the active drawing layer
|
||||
dim canvasw as integer:canvasw=_width(layers(1).ihandle)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue