Can you post the TYPE definition for pix2type? I'd like to run your example, but I'm too lazy to try to reconstruct the TYPE by checking which elements you refer to...
And I think there's a typo:
Code:
CONST maxx = 199 'use this constant for SCREEN 13
199 should be 319, right?
That's a simple test?! Geez, I'd like to see a complex one...
This passes your "simple" tests
Code:
DEFINT A-Z
'$DYNAMIC
SUB fill (x, y, c)
DIM r(32766, 1): cb = POINT(x, y): GOSUB fl: IF v2 = 0 THEN EXIT SUB ELSE v4 = 0
fm: x = r(v4, 0): y = r(v4, 1): GOSUB fl: v4 = v4 + 1: IF v4 > (v2 - 1) THEN v2 = 0: EXIT SUB ELSE GOTO fm
fl: v = POINT(x, y): IF v = c THEN RETURN ELSE IF v <> cb AND v <> c THEN RETURN ELSE v1 = 0: v3 = 0: x3 = x: y3 = y: GOTO pa
ch: IF v <> cb AND v <> c THEN GOTO gb ELSE GOTO pa
pa: PSET (x, y), c: GOSUB u: GOSUB d: x = x + 1: IF x > 319 THEN GOTO gb ELSE GOTO ga
ga: v = POINT(x, y): GOTO ch
gb: x = x3: y = y3: v = POINT(x, y)
pb: IF v <> cb AND v <> c THEN RETURN ELSE PSET (x, y), c: GOSUB u: GOSUB d: x = x - 1: IF x < 0 THEN RETURN ELSE v = POINT(x, y): GOTO pb
u: IF y < 1 THEN RETURN ELSE x2 = x: y2 = y - 1: v = POINT(x2, y2): IF v <> cb AND v <> c THEN v1 = 0: RETURN ELSE IF v = c OR v1 = 1 THEN RETURN ELSE r(v2, 0) = x2: r(v2, 1) = y2: v2 = v2 + 1: v1 = 1: RETURN
d: IF y > 198 THEN RETURN ELSE x2 = x: y2 = y + 1: v = POINT(x2, y2): IF v <> cb AND v <> c THEN v3 = 0: RETURN ELSE IF v = c OR v3 = 1 THEN RETURN ELSE r(v2, 0) = x2: r(v2, 1) = y2: v2 = v2 + 1: v3 = 1: RETURN
END SUB
Load QB with /AH.
If someone tries to use your floodfill, he/she will not ask in which patterrns can it be used, is'nt?.
I think a floodfill must pass every test.
Yeah, well it works now and it's the shortest. SUCKAS!!!!!!!!!!!!!!!!!
After seeing yours, i decided i make one myself. its reasonably small/slim, i included an example with it. I avoided using ugly goto's
. And the array it uses is only 1023 elements and works with "the dot test".
http://hybd.net/~mms/files/FILL.BAS (put it here so the thread didnt get so huge
)
I'd much rather have used recursion, but here is my non-recursive entry:
NOTE: This was written for screen 13. It can easily be adapted to other screen modes by changing the edge-limits (The ABS statements in the long line).
Code:
SUB FloodFill (x%, y%, c%)
'********************** ARGUMENT LIST *************************
'(x%, y%) the point at which to begin flood filling
'c% the color to fill with
'**************************************************************
IF POINT(x%, y%) = c% THEN EXIT SUB ELSE PSET (x%, y%), c%
n% = 1
l& = 1
OPEN "fill.bin" FOR BINARY AS #1
DO
IF POINT(x% + INT(n% MOD 2 + 2 * (n% = 1)), y% + INT(n% MOD 2 XOR 1 + 2 * (n% = 2))) <> c% AND (ABS(159.5 - (x% + INT(n% MOD 2 + 2 * (n% = 1)))) < 160) AND (ABS(99.5 - (y% + INT(n% MOD 2 XOR 1 + 2 * (n% = 2)))) < 100) THEN
x% = x% + INT(n% MOD 2 + 2 * (n% = 1))
y% = y% + INT(n% MOD 2 XOR 1 + 2 * (n% = 2))
PSET (x%, y%), c%
PUT #1, l&, n%
l& = l& + 2
n% = 1
ELSE
IF n% < 4 THEN
n% = n% + 1
ELSE
IF l& > 1 THEN
l& = l& - 2
GET #1, l&, n%
x% = x% - INT(n% MOD 2 + 2 * (n% = 1))
y% = y% - INT(n% MOD 2 XOR 1 + 2 * (n% = 2))
n% = n% - (n% < 4)
ELSE
EXIT DO
END IF
END IF
END IF
LOOP
CLOSE #1
KILL "fill.bin"
END SUB
*peace*
Meg.
when does this challenge end?
Quote:I'd much rather have used recursion, but here is my non-recursive entry...
Meg...I think that "lowercase L" is an unfortunate name for a variable...for code posted to the web...it occupies the *exact* same pixel pattern as the numeral "1" in my web browser...
Btw...nice code you've been doing...I now see why you were asking about Binary files a day or 2 ago