why doesnt this basic fill routine work?
why doesnt this basic fill routine work?
https://pasteboard.co/Js7PRjTd.png
https://gofile.io/d/Ri7Og0
it works ok for a bit then just spills out
im scratching my head here. i often get lost with the logic of a program
https://gofile.io/d/Ri7Og0
it works ok for a bit then just spills out
im scratching my head here. i often get lost with the logic of a program
Last edited by 777 on Mon Sep 21, 2020 4:34 pm, edited 1 time in total.
i started programming the spectrum when i was 8 :-
1 plot rnd*255,rnd*175
2 goto 1
1 plot rnd*255,rnd*175
2 goto 1
Re: why doesnt this basic fill routine work?
Link to Screenshot is not working?
Having a short look at your BASIC-program you use x=x+1 together with y=y+1, so you may jump straight diagonally through the pixel you test with POINT.
Also you didn´t test against x or y getting to a value under zero.
Having a short look at your BASIC-program you use x=x+1 together with y=y+1, so you may jump straight diagonally through the pixel you test with POINT.
Also you didn´t test against x or y getting to a value under zero.
Re: why doesnt this basic fill routine work?
My BASIC knowledge has about 35 years of rust on it, but yes, that's what I thought was happening too.
Derek Fountain, author of the ZX Spectrum C Programmer's Getting Started Guide and various open source games, hardware and other projects, including an IF1 and ZX Microdrive emulator.
Re: why doesnt this basic fill routine work?
fixed pic link
i started programming the spectrum when i was 8 :-
1 plot rnd*255,rnd*175
2 goto 1
1 plot rnd*255,rnd*175
2 goto 1
Re: why doesnt this basic fill routine work?
I think it's found a gap... Possibly, anyway...
Here's the line (green) moving towards different parts of the circle (lower left)
The first two pics are fine as the POINT (x,y) identifies the pixel of the boundary (highlighted in grey).
But the third one doesn't hit a black pixel at any point.
Here's the line (green) moving towards different parts of the circle (lower left)
The first two pics are fine as the POINT (x,y) identifies the pixel of the boundary (highlighted in grey).
But the third one doesn't hit a black pixel at any point.
My Speccy site: thirdharmoniser.com
Re: why doesnt this basic fill routine work?
any way round this problem?
it even does this if i plot it vertically
https://pasteboard.co/Js86PoZ.png
https://gofile.io/d/Q5zAlX
it even does this if i plot it vertically
https://pasteboard.co/Js86PoZ.png
https://gofile.io/d/Q5zAlX
i started programming the spectrum when i was 8 :-
1 plot rnd*255,rnd*175
2 goto 1
1 plot rnd*255,rnd*175
2 goto 1
Re: why doesnt this basic fill routine work?
Whats you "d" variable used for? Used for the direction up or down of filling?
Even if we bring this to work, you only fill the right half of the circle.
Maybe you should search a little bit on the net for a good filling routine...
maybe here: https://groups.google.com/g/comp.sys.si ... bcxo?pli=1
https://web.archive.org/web/20100830101 ... asfill.htm
Even if we bring this to work, you only fill the right half of the circle.
Maybe you should search a little bit on the net for a good filling routine...
maybe here: https://groups.google.com/g/comp.sys.si ... bcxo?pli=1
https://web.archive.org/web/20100830101 ... asfill.htm
Re: why doesnt this basic fill routine work?
It's doing something different if you plot vertically. If you look at the top of the circle you'll see a flat bit, then to the side it steps down a pixel to start the curve. When you hit the edge of the flat bit you then step a pixel to the right, which takes you outside the line (actually it takes you onto the line) from where your logic escapes the boundary.
Instead of going back and forth, repeatedly changing direction, try resetting y back to the centre so it always fills outwards?
Derek Fountain, author of the ZX Spectrum C Programmer's Getting Started Guide and various open source games, hardware and other projects, including an IF1 and ZX Microdrive emulator.
Re: why doesnt this basic fill routine work?
d is directionLuzie wrote: ↑Mon Sep 21, 2020 6:02 pm Whats you "d" variable used for? Used for the direction up or down of filling?
Even if we bring this to work, you only fill the right half of the circle.
Maybe you should search a little bit on the net for a good filling routine...
maybe here: https://groups.google.com/g/comp.sys.si ... bcxo?pli=1
https://web.archive.org/web/20100830101 ... asfill.htm
+ not if i start it from further left
i started programming the spectrum when i was 8 :-
1 plot rnd*255,rnd*175
2 goto 1
1 plot rnd*255,rnd*175
2 goto 1
Re: why doesnt this basic fill routine work?
While a floodfill doesn't have to make use of recursion, you generally need some sort of stack to store visited areas. This one:
Edit: This seems to be the same one linked above, originally from Geoff Wearmouth
Will do the job, but slowly. You can do it with stacks instead of GOSUB/RETURN but it gets more complex pretty quickly.
Code: Select all
10 CIRCLE 128,88,40: CIRCLE 128,88,30
20 LET x=100: LET y=100
30 GO SUB 1000: STOP
1000 PLOT x,y
1010 IF NOT POINT (x+1,y) THEN LET x=x+1: GO SUB 1000: LET x=x-1
1020 IF NOT POINT (x-1,y) THEN LET x=x-1: GO SUB 1000: LET x=x+1
1030 IF NOT POINT (x,y+1) THEN LET y=y+1: GO SUB 1000: LET y=y-1
1040 IF NOT POINT (x,y-1) THEN LET y=y-1: GO SUB 1000: LET y=y+1
1050 RETURN
Will do the job, but slowly. You can do it with stacks instead of GOSUB/RETURN but it gets more complex pretty quickly.
Re: why doesnt this basic fill routine work?
Here is the ASM version:
Then:
Code: Select all
ORG 32768
LD C, 94 ; X
LD B, 100 ; Y
Plot:
CALL SetBit
Right:
INC C
CALL GetBit
AND (HL)
JR NZ, SkipRight
PUSH BC
CALL Plot
POP BC
SkipRight:
DEC C
Left:
DEC C
CALL GetBit
AND (HL)
JR NZ, SkipLeft
PUSH BC
CALL Plot
POP BC
SkipLeft:
INC C
Up:
INC B
CALL GetBit
AND (HL)
JR NZ, SkipUp
PUSH BC
CALL Plot
POP BC
SkipUp:
DEC B
Down:
DEC B
CALL GetBit
AND (HL)
JR NZ, SkipDown
PUSH BC
CALL Plot
POP BC
SkipDown:
INC B
RET
GetBit:
PUSH BC
CALL 22AAh ; PIXEL-ADD
POP BC
PUSH BC
LD B, A
INC B
XOR A
SCF
Loop:
RRA
DJNZ Loop
POP BC
RET
SetBit:
CALL GetBit
OR (HL)
LD (HL), A
RET
Code: Select all
10 CIRCLE 128,88,40: CIRCLE 128,88,30
20 RANDOMIZE USR 32768
Re: why doesnt this basic fill routine work?
Another way of filling is DRAWing INVERSEd lines between PLOTs
Code: Select all
10 BORDER 0: PAPER 0: INK 0: BRIGHT 0: CLS
9001 LET x$="055197195055055192189054051043048041037018029043052039106066057088078055048066016"
9002 LET y$="159131124151142116108135088090136137095071065088085066044019024043048030033047065"
9100 GO TO 9400
9200 LET x2=VAL (x$(g TO g+2)): LET y2=VAL (y$(g TO g+2)): RETURN
9300 LET x1=x2: LET y1=y2: RETURN
9400 LET g=1: GO SUB 9200: FOR g=1 TO LEN x$ STEP 3: GO SUB 9300: GO SUB 9200: IF x2<0 THEN LET g=g+1: GO SUB 9200: GO SUB 9300
9500 PLOT INVERSE 1;x1,y1: DRAW INVERSE 1; PAPER 2;x2-x1,y2-y1: NEXT g