07-12-2003, 06:54 AM
Is it fair to post something you wrote previously?
This one doesn't work like QB's (which stops only at the border color you give it) - it's more like the flood fill tool an image editor might have, which stops at any other color besides the one it's filling over.
This one doesn't work like QB's (which stops only at the border color you give it) - it's more like the flood fill tool an image editor might have, which stops at any other color besides the one it's filling over.
Code:
DECLARE SUB fill (x1%, y1%, fc%)
DEFINT A-Z
TYPE p2d
x AS INTEGER
y AS INTEGER
END TYPE
RANDOMIZE TIMER
SCREEN 13
' Draw some random stuff:
FOR a = 1 TO 13
x1 = INT(RND * 320): y1 = INT(RND * 200)
x2 = INT(RND * 320): y2 = INT(RND * 200)
COLOR INT(RND * 7) + 9
SELECT CASE INT(RND * 4)
CASE 1: CIRCLE (x1, y1), INT(RND * 200) + 1
CASE 2: LINE (x1, y1)-(x2, y2)
CASE 3: LINE (x1, y1)-(x2, y2), , B
END SELECT
NEXT a
' Paint from a random point:
fill INT(RND * 320), INT(RND * 200), 1
END
SUB fill (x1, y1, fc)
IF x1 < 0 OR x1 > 319 OR y1 < 0 OR y1 > 199 THEN EXIT SUB
c = POINT(x1, y1)
IF c = fc THEN EXIT SUB
h = 0
PSET (x1, y1), fc
DIM max AS LONG
max = FRE(-1) \ 4
IF max > 16384 THEN max = 16384
DIM q(1 TO max) AS p2d
s = 1: sm1 = 0: e = 1: q(e).x = x1: q(e).y = y1
DO WHILE e >= s
x = q(s).x: y = q(s).y: sm1 = s: s = s + 1
xm1 = x - 1: ym1 = y - 1: xp1 = x + 1: yp1 = y + 1
IF x > 0 THEN
IF POINT(xm1, y) = c THEN
PSET (xm1, y), fc
e = e + 1
IF e > max THEN
FOR a = s TO max: q(a - sm1) = q(a): NEXT a
e = e - sm1: s = 1: sm1 = 0
END IF
q(e).x = xm1: q(e).y = y
END IF
END IF
IF x < 319 THEN
IF POINT(xp1, y) = c THEN
PSET (xp1, y), fc
e = e + 1
IF e > max THEN
FOR a = s TO max: q(a - sm1) = q(a): NEXT a
e = e - sm1: s = 1: sm1 = 0
END IF
q(e).x = xp1: q(e).y = y
END IF
END IF
IF y > 0 THEN
IF POINT(x, ym1) = c THEN
PSET (x, ym1), fc
e = e + 1
IF e > max THEN
FOR a = s TO max: q(a - sm1) = q(a): NEXT a
e = e - sm1: s = 1: sm1 = 0 ': o = o + 1
END IF
q(e).x = x: q(e).y = ym1
'nh = e - sm1: IF nh > h THEN h = nh
END IF
END IF
IF y < 199 THEN
IF POINT(x, yp1) = c THEN
PSET (x, yp1), fc
e = e + 1
IF e > max THEN
FOR a = s TO max: q(a - sm1) = q(a): NEXT a
e = e - sm1: s = 1: sm1 = 0 ': o = o + 1
END IF
q(e).x = x: q(e).y = yp1
'nh = e - sm1: IF nh > h THEN h = nh
END IF
END IF
LOOP
END SUB