Log In  

Cart #recursive-0 | 2019-12-21 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
1

A little program simulating recursion graphically.

Controls

  • Y Button to call the function
  • X Button to finish ( go back ) a function call.

It is only a simulation. So it should not be possible to go back and forth but I had to stop the calls and thought it would be funny to have some control during the process.

P#71275 2019-12-21 02:57 ( Edited 2019-12-21 13:43)

whoa. nice work. very straightforward and to the point.

P#71283 2019-12-21 17:27
1

Fun(ction) fact!
You can bake recursion directly in to functions themselves!

depth = 0
recursion = function(x)
 print(depth)
 flip()--slow things down
 if(x~=nil)then
  depth = x
 end
 if(depth<=200)then
  recursion(depth+1)
 end
end

recursion()
P#71360 2019-12-24 07:00

@Cabledragon
Nice! I didn`t know about the flip() function yet, that's why I had to use the workaround. Thanks a lot for this hint!

I guess (x~=nil) is the same as (x!=nil) ? :D

Why does the 0 gets printed out in the beginning twice though?

P#71446 2019-12-28 01:03

It prints zero twice simply because I set up the order of operations incorrectly.

Also yes, ~= == !=, except that != doesn't exist in standard lua.

All flip() does it draw the contents of the back buffer to the screen. It's used to manually update the screen, but here I use it to slow things down.

P#71455 2019-12-28 10:50

oh okay, so the double 0 comes from calling recursion the first time without arguments?

P#71478 2019-12-28 20:42

[Please log in to post a comment]

Follow Lexaloffle:        
Generated 2020-07-08 01:46 | 0.023s | 2097k | Q:38