Author Topic: filling subroutine  (Read 6862 times)

0 Members and 1 Guest are viewing this topic.

Offline kindermoumoute

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 836
  • Rating: +54/-3
    • View Profile
filling subroutine
« on: November 11, 2010, 05:30:01 pm »
I'm looking to make a function filling like paint. I already tried some stuff, but I think I share in the wrong direction :
Code: [Select]
:2→Z
:sub(FIL,X,Y)
:...
:Lbl FIL
:r1→{L1+Z}
:r2→{L1+Z+1}
:While Z
: !If pxl-Test({L1+Z},{L1+Z+1})
: Pxl-On({L1+Z},{L1+Z+1})
: Z+2→Z
: sub(FIL,r1,r2+1)
: Z-2→Z
: sub(FIL,r1,r2-1)
: Z-2→Z
: sub(FIL,r1+1,r2)
: Z-2→Z
: sub(FIL,r1-1,r2)
: End
: Z-2→Z
:End
:Return
Projects :

Worms armageddon z80 :
- smoothscrolling Pixelmapping : 100%
- Map editor : 80%
- Game System : 0%

Tutoriel français sur l'Axe Parser
- 1ère partie : en ligne.
- 2ème partie : en ligne.
- 3ème partie : en ligne.
- 4ème partie : 10%
- Annexe : 100%

SirCmpwn

  • Guest
Re: filling subroutine
« Reply #1 on: November 11, 2010, 05:32:37 pm »
I don't have code, but this should help:
http://en.wikipedia.org/wiki/Flood_fill

Offline kindermoumoute

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 836
  • Rating: +54/-3
    • View Profile
Re: filling subroutine
« Reply #2 on: November 11, 2010, 05:33:46 pm »
I already read this, but I can't find how to use in Axe Parser (r1 is always same variable).
« Last Edit: November 11, 2010, 05:34:12 pm by kindermoumoute »
Projects :

Worms armageddon z80 :
- smoothscrolling Pixelmapping : 100%
- Map editor : 80%
- Game System : 0%

Tutoriel français sur l'Axe Parser
- 1ère partie : en ligne.
- 2ème partie : en ligne.
- 3ème partie : en ligne.
- 4ème partie : 10%
- Annexe : 100%

SirCmpwn

  • Guest
Re: filling subroutine
« Reply #3 on: November 11, 2010, 05:36:47 pm »
Make sure you have the latest version of Axe and try this:
Code: [Select]
.r1 = X, r2 = Y
Lbl FF
ReturnIf Pxl-Test(r1,r2)
Pxl-On(r1,r2)
sub(FFʳ,r1+1,r2
sub(FFʳ,r1-1,r2
sub(FFʳ,r1,r2-1
sub(FFʳ,r1,r2+1
Return

EDIT: Fixed code
EDIT2: I tested this, and it works, but make sure that you only do it with a small area or you will end up overflowing the stack, which would be bad.
« Last Edit: November 11, 2010, 05:53:42 pm by SirCmpwn »

Offline kindermoumoute

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 836
  • Rating: +54/-3
    • View Profile
Re: filling subroutine
« Reply #4 on: November 11, 2010, 05:59:54 pm »
Wow... usefull ʳ :o
Correction with screen limit :
Code: [Select]
:Lbl FIL
:If Pxl-Test(r1,r2) or (r1≥96) or (r2≥64)
:Return
:End
:Pxl-On(r1,r2)
:sub(FILr,r1+1,r2)
:sub(FILr,r1-1,r2)
:sub(FILr,r1,r2-1)
:sub(FILr,r1,r2+1)
:Return
pretty routine, thank ;)
Projects :

Worms armageddon z80 :
- smoothscrolling Pixelmapping : 100%
- Map editor : 80%
- Game System : 0%

Tutoriel français sur l'Axe Parser
- 1ère partie : en ligne.
- 2ème partie : en ligne.
- 3ème partie : en ligne.
- 4ème partie : 10%
- Annexe : 100%

SirCmpwn

  • Guest
Re: filling subroutine
« Reply #5 on: November 11, 2010, 06:00:39 pm »
Woah, careful there.  Filling the whole screen, or even most of it, will cause a stack overflow, which will crash the calc.

Offline kindermoumoute

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 836
  • Rating: +54/-3
    • View Profile
Re: filling subroutine
« Reply #6 on: November 11, 2010, 06:01:56 pm »
It work perfectly, don't crash (with screen limit).
Projects :

Worms armageddon z80 :
- smoothscrolling Pixelmapping : 100%
- Map editor : 80%
- Game System : 0%

Tutoriel français sur l'Axe Parser
- 1ère partie : en ligne.
- 2ème partie : en ligne.
- 3ème partie : en ligne.
- 4ème partie : 10%
- Annexe : 100%

SirCmpwn

  • Guest
Re: filling subroutine
« Reply #7 on: November 11, 2010, 06:02:25 pm »
Oh really?  Okay then, glad to hear it.

Offline kindermoumoute

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 836
  • Rating: +54/-3
    • View Profile
Re: filling subroutine
« Reply #8 on: November 11, 2010, 06:31:05 pm »
OK, there is 1 random bugs and always final crash ;D
« Last Edit: November 11, 2010, 06:32:05 pm by kindermoumoute »
Projects :

Worms armageddon z80 :
- smoothscrolling Pixelmapping : 100%
- Map editor : 80%
- Game System : 0%

Tutoriel français sur l'Axe Parser
- 1ère partie : en ligne.
- 2ème partie : en ligne.
- 3ème partie : en ligne.
- 4ème partie : 10%
- Annexe : 100%

SirCmpwn

  • Guest
Re: filling subroutine
« Reply #9 on: November 11, 2010, 06:36:11 pm »
That first one is weird, and it's probably a stack overflow.  The second one is probably a problem with your code.

Offline kindermoumoute

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 836
  • Rating: +54/-3
    • View Profile
Re: filling subroutine
« Reply #10 on: November 11, 2010, 06:40:41 pm »
What is a stack overflow ? How prevent that ?
Projects :

Worms armageddon z80 :
- smoothscrolling Pixelmapping : 100%
- Map editor : 80%
- Game System : 0%

Tutoriel français sur l'Axe Parser
- 1ère partie : en ligne.
- 2ème partie : en ligne.
- 3ème partie : en ligne.
- 4ème partie : 10%
- Annexe : 100%

SirCmpwn

  • Guest
Re: filling subroutine
« Reply #11 on: November 11, 2010, 06:44:58 pm »
The stack is like a stack of papers.  You can put stuff on top, and take stuff off.  The last thing on is the first thing off.  The calculator has its own internal stack.  When you use use sub(FFr, it adds r1, r2, r3, r4, r5, and r6 to the top of the stack.  The stack is a fixed size, though.  You can only put so much paper on before the calculator crashes.  There is an alternative flood-fill method that is designed to prevent this, but it's more complex, so I'll have to work on that for you later.

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: filling subroutine
« Reply #12 on: November 11, 2010, 06:46:29 pm »
Yeah, and let it be noted that its not the size necessarily that makes the stack overflow, but the complexity of the filling field.

SirCmpwn

  • Guest
Re: filling subroutine
« Reply #13 on: November 11, 2010, 06:47:50 pm »
Exactly what BuilderBoy said.
Also, is L1 available for storage when working on a better routine?

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: filling subroutine
« Reply #14 on: November 11, 2010, 06:52:13 pm »
Actually, i retract what i just said XD its difficult to predict what will crash and what will not.  Smaller is generally safer though :)