If it comes across a pixel that is already on, it cannot spawn into that spot. And the memory need only contain the pixels spawned in the current and previous loops.
|
It doesn't test if a pixel is on and then grow that pixel, the "living" pixels are recorded in a list.
Running the program itself would be a horrible implementation, as you'd very quickly be consuming massive amounts of memory. A looped implementation would be far superior.
- Kllrnohj
- ☢ PH34R |\/|3 (Posts: 8196)
- 28 Nov 2009 11:57:29 pm
- Last edited by Kllrnohj on 28 Nov 2009 11:58:46 pm; edited 1 time in total
Doesn't matter, as he has no way to store this information in TI-BASIC. You can't perform operations on something you can't store, and that is your problem right now.
Trying to figure out how to do a fill before you even have the base system implemented is pointless. Figure out how the user can draw on a per-pixel basis and THEN come back and figure out advanced stuff.
Trying to figure out how to do a fill before you even have the base system implemented is pointless. Figure out how the user can draw on a per-pixel basis and THEN come back and figure out advanced stuff.
While we're on the topic of flood fill or bucket fill algorithms, btw, there's of course the Wikipedia page on the subject:
http://en.wikipedia.org/wiki/Flood_fill
Edit: The queue implementation is obviously the one that you want, since TI-BASIC is a language where the level of recursion required for the recursive implementation is prohibitive for any decent size.
http://en.wikipedia.org/wiki/Flood_fill
Edit: The queue implementation is obviously the one that you want, since TI-BASIC is a language where the level of recursion required for the recursive implementation is prohibitive for any decent size.
KermMartian wrote:
Edit: The queue implementation is obviously the one that you want, since TI-BASIC is a language where the level of recursion required for the recursive implementation is prohibitive for any decent size.
Except TI-BASIC doesn't really have an efficient queue either. Using a list is going to be horribly slow...
I said it before I'll say it again, this really needs to be in assembly to get anything resembling speed out of it.
Kllrnohj wrote:
KermMartian wrote:
Edit: The queue implementation is obviously the one that you want, since TI-BASIC is a language where the level of recursion required for the recursive implementation is prohibitive for any decent size.
Except TI-BASIC doesn't really have an efficient queue either. Using a list is going to be horribly slow...
I said it before I'll say it again, this really needs to be in assembly to get anything resembling speed out of it.
I've already built a splash fill program in TI-BASIC, and it it's slow, but not mindbendingly slow. I just seem to have misplaced it.
source code for splash fill program
Code:
etc. etc. etc for up, down, and right
Code:
Code:
{S->lPX
{T->lPY
{S->lCX
(T->lCY
1->B
0->C
1->E
repeat B=C
B->C
for(A,E,dim(lPX
If not(pxl-test(lPY(A),lPX(A)-1
then
lPX(A)-1->lCX(dim(lCX)+1
lPY(A)->lCY(dim(lCY)+1
end
etc. etc. etc for up, down, and right
Code:
for(D,B,dim(lCX))
Pxl-On(lCY(D),lCX(D)
end
dim(lCX->B
end
dim(lPX->E
lCX->lPX
lCY->lPY
end
- Will_W
- Expert (Posts: 529)
- 29 Nov 2009 11:49:30 am
- Last edited by Will_W on 29 Nov 2009 02:46:49 pm; edited 1 time in total
Code:
PROGRAM:FILL
:Ans->L3
:L3(3->U
:{L3(1)+L3(3)i->L3
:imag(L3->L6
:real(L3->L3
:L3->LC
:L6->LD
:1->J
:While J
:Delvar Q{0->L4
:{0->L2
:dim(L3->F
:For(A,1,F)
:L3(A->B
:L6(A->C
:C-1->V
:C+1->W
:B-1->G
:B+1->H
:not({pxl-Test(G,V),pxl-Test(G,C),pxl-Test(G,W),pxl-Test(B,V),pxl-Test(B,W),pxl-Test(H,V),pxl-Test(H,C),pxl-Test(H,W->L5
:Ans and {(L5(4) or L5(2)),1,(L5(2) or L5(5)),1,1,(L5(4) or L5(7)),1,(L5(7) or L5(5->L5
:L5{V,C,W,V,C+1,V,C,W->LB
:L5{G,G,G,B,B,H,H,H->LA
:Delvar NDelvar Dsum(L5->M
:While D<M
:N+1->N
:If LA(N
:Then
:LA(N->K
:LB(N->L
:Pxl-On(K,L
:Q+1->Q
:K->L4(Q
:L->L2(Q
:D+1->D
:End
:End
:End
:If not(sum(L4
:Then
:Delvar JEnd
:L4->L3
:L2->L6
:If U
:Then
:{U:prgmFILLTYPE
:End:End
:
PROGRAM:FILLTYPE
:If Ans(1)=1
:Then
:For(T,1,dim(LC))
:If 2=gcd(2,LC(T)+LD(T
:Then
:Pxl-Off(LC(T),LD(T
:End
:End
:L3->LC
:L6->LD
:End
PROGRAM:FILLTOOL
:a+bi
:25->O
:25->P
:Pxl-Change(O,P
:While 1
:Delvar Z
:While not(Z
:getKey->Z
:End
:Pxl-Change(O,P
:O+(Z=34)-(Z=25->O
:P+(Z=26)-(Z=24->P
:Pxl-Change(O,P
:If Z=21
:Then
:{O,P,0:prgmFILL /////replace the 0 with a 1 for checker fill
:Pxl-Change(O,P
:End
:End
Slightly optimized and bug fixed.
Here's an improvement to your FILLTOOL program:
Code:
Code:
PROGRAM:FILLTOOL
:a+bi
:0->Xmin:0->Ymin
:1->dX:1->dY
:While 1
:Input
:{X,63-Y,0:prgmFILL /////replace the 0 with a 1 for checker fill
:Pxl-Change(X,63-Y
:End
I had a fill program that filled in horizontal lines instead of pixel to pixel.
It was not perfect because it forget some parts but could be modified... In TI-BASIC this method could be faster...
It was not perfect because it forget some parts but could be modified... In TI-BASIC this method could be faster...
What should I use input for? Where to start filling? This is supposed to be for a paint program, and most people don't know the exact codes for positions.
For what it's worth, you can transfer Pic variables to and from BBC BASIC by saving and loading the graph buffer memory (&9340) directly. To load and display a picture, use
Code:
To save a picture, use
Code:
As always, be careful when accessing memory directly!
Code:
*LOAD PIC1.PIC 9340
*REFRESH
To save a picture, use
Code:
*SAVE PIC1.PIC 9340+2F4
As always, be careful when accessing memory directly!
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.
» Go to Registration page
» Go to Registration page
» Goto page Previous 1, 2, 3 Next
» View previous topic :: View next topic
» View previous topic :: View next topic
Page 2 of 3
» All times are UTC - 5 Hours
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Advertisement