Looking for a graphic fill routine in 100% BASIC, saw this which is clever as it uses the GOSUB stack. It works well but gives 4: Out of memory errors as it uses a lot of memory for big or complex fills.
5000 PLOT x,y:
5010 IF NOT POINT (x+1,y) THEN LET x=x+1: GO SUB 1000: LET x=x-1
5020 IF NOT POINT (x-1,y) THEN LET x=x-1: GO SUB 1000: LET x=x+1
5030 IF NOT POINT (x,y+1) THEN LET y=y+1: GO SUB 1000: LET y=y-1
5040 IF NOT POINT (x,y-1) THEN LET y=y-1: GO SUB 1000: LET y=y+1
5050 RETURN
Does anyone have anything that is faster and doesn't use as much memory?
Fill subroutine for Spectrum BASIC
Re: Fill subroutine for Spectrum BASIC
Hi,
Yes, at each GO SUB, the BASIC store the line number at the top of memory and add this data each time.
The RETURN delete the previous data and swap to the last one.
This code use the GO SUB stack and add 3 bytes at the top of the RAM for each GO SUB.
A thousand call without RETURN take two thousand bytes.
The faster and simply way to fill the screen, is to get -x and +x from a vertical line.
And trace a line from -x to +x, and go to the last bottom sprite.
But, this code can't fill the isolated top or bottom aeras. Just all lines includes on the vertical pickup sprite.
You had to set several origine sprites to fill the entire of drawing.
Yes, at each GO SUB, the BASIC store the line number at the top of memory and add this data each time.
The RETURN delete the previous data and swap to the last one.
This code use the GO SUB stack and add 3 bytes at the top of the RAM for each GO SUB.
A thousand call without RETURN take two thousand bytes.
The faster and simply way to fill the screen, is to get -x and +x from a vertical line.
And trace a line from -x to +x, and go to the last bottom sprite.
But, this code can't fill the isolated top or bottom aeras. Just all lines includes on the vertical pickup sprite.
You had to set several origine sprites to fill the entire of drawing.
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
Re: Fill subroutine for Spectrum BASIC
Code: Select all
10 LET a=0
20 LET a=a+1
25 PRINT AT 0,0;a
30 GO SUB 20
40 PRINT a
Spectrum 48k: 13801 calls
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
Re: Fill subroutine for Spectrum BASIC
Code: Select all
10 CLS:CIRCLE 100,100,50
20 LET X=100
30 LET Y=50
40 GO SUB 1000
50 STOP
1010 LET MIN=X:LET MAX=X
1020 IF POINT(MIN-1,Y) THEN GO TO 1050
1030 LET MIN=MIN-1:GO TO 1020
1050 IF POINT(MAX+1,Y) THEN GO TO 1100
1060 LET MAX=MAX+1:GO TO 1050
1100 PLOT MAX,Y:DRAW MIN-MAX,0:LET Y=Y+1:IF POINT(X,Y) THEN RETURN
1200 GO TO 1010
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
Re: Fill subroutine for Spectrum BASIC
That does work for open spaces, however, if there is an object in the space it will stop.
For example add
: CIRCLE 90,85,20
after the other circle command and you will see what I mean.
For example add
: CIRCLE 90,85,20
after the other circle command and you will see what I mean.
Re: Fill subroutine for Spectrum BASIC
Yep!
Just place several filling points...
Were is the UDG filling solution, by create a "rectangle" subroutine how put solid 8x8 pixels blocs. And tag triangulars UDG blocs on the vectorial lines...
It's faster, but can't fill all over include surfaces.
An ASM routine is slow too, but more convenient to use.
You also can use the scale or moving vectors solution, by reducing the circle to the center or repeate a pixel block by pixel.
You can use bitmap, or a data stream of lines, x pixels black,X+1 pixels white, x+3 pixels black, on the Y axis... in a graphic window.
Just place several filling points...
Were is the UDG filling solution, by create a "rectangle" subroutine how put solid 8x8 pixels blocs. And tag triangulars UDG blocs on the vectorial lines...
It's faster, but can't fill all over include surfaces.
An ASM routine is slow too, but more convenient to use.
You also can use the scale or moving vectors solution, by reducing the circle to the center or repeate a pixel block by pixel.
You can use bitmap, or a data stream of lines, x pixels black,X+1 pixels white, x+3 pixels black, on the Y axis... in a graphic window.
Xavier ...on the Facebook groupe : "Zx81 France"(fr)