Omnimaga

Calculator Community => Other Calc-Related Projects and Ideas => TI-Nspire => Topic started by: Jim Bauwens on November 02, 2011, 10:36:59 am

Title: [lua] Logo interpreter
Post by: Jim Bauwens on November 02, 2011, 10:36:59 am
I've been a bit busy making a logo (http://en.wikipedia.org/wiki/Logo_%28programming_language%29) interpreter in Lua.
I'm going to participate with it in the Ti-Planet / Inspired-Lua contest (math section).

While I still need to make an on calc ui and editor, here are some screenshots that show some turtle graphics (together with the code):

(http://bwns.be/jim/logo.png)
Code: [Select]
to square
  repeat 4 [left 90 forward 80]
end

repeat 36 [left 10 square]

(http://bwns.be/jim/logo2.png)
Code: [Select]
make "x 1
repeat 150 [forward :x left 89 make "x :x + 1]
Title: Re: [lua] Logo interpreter
Post by: Adriweb on November 02, 2011, 10:38:31 am
This is awesomeeeeeeee

Congratulations !

For the Lua contest, right ? :D
Title: Re: [lua] Logo interpreter
Post by: Jim Bauwens on November 02, 2011, 10:39:20 am
Thanks =)
Yes, its for the contest :)
Title: Re: [lua] Logo interpreter
Post by: Stefan Bauwens on November 02, 2011, 02:15:28 pm
Good luck with all the rest.
I'm not so advanced in languages as you are but.. Good job, I guess. :D
Title: Re: [lua] Logo interpreter
Post by: Chockosta on November 02, 2011, 02:31:28 pm
Wow. Good luck, it is awesome.
Not really useful, but I'd love to play with that.
Title: Re: [lua] Logo interpreter
Post by: Jim Bauwens on November 02, 2011, 02:33:01 pm
Thanks =)

Quote
Not really useful
You can visualize lot of mathematical stuff with it ;)
Title: Re: [lua] Logo interpreter
Post by: Spyro543 on November 02, 2011, 03:16:44 pm
How about the mode I suggested where you can see the turtle move and draw the pattern instead of the pattern just appearing?
Title: Re: [lua] Logo interpreter
Post by: Jim Bauwens on November 02, 2011, 04:01:07 pm
I'm not yet done, just finished the main core.
Title: Re: [lua] Logo interpreter
Post by: Jim Bauwens on November 08, 2011, 11:33:22 am
I submitted my first version for the TI-Planet contest.
While its not yet done, most you need is there.

Here is a little animated screenshot:
(http://bwns.be/jim/logo.gif)

Note that the colors (grey's) look a bit better on a real calculator :D
Title: Re: [lua] Logo interpreter
Post by: Xeda112358 on November 08, 2011, 11:42:41 am
ooh, yum, that looks nice O.O
Title: Re: [lua] Logo interpreter
Post by: Chockosta on November 08, 2011, 12:49:58 pm
Congrats !

Could you post a link to download ?
TI-Planet staff haven't done it yet, and I really want to play with this awesome program !
Title: Re: [lua] Logo interpreter
Post by: Adriweb on November 08, 2011, 01:02:35 pm
I'm going to put it on TIPlanet.org today :)
Title: Re: [lua] Logo interpreter
Post by: Jim Bauwens on November 08, 2011, 01:53:29 pm
Thanks guys :D
I'll upload the package after the contest has ended, as there are some bugs that I need to fix.

I just discovered a bug that the calculator reboots sometimes if you have a " in the code.
This is not my fault, but TI's. (Probably will get fixed if I report it)
The problem here is that " is a special token in Logo, and used allot.
One way to be sure it doesn't crash is to replace
Code: [Select]
"thiscode
with
Code: [Select]
first [thiscode]

It has the same effect in Logo.

Edit: as you can see in the screenshot, the bug is fixed in 3.10 (the emu runs 3.10), while I still had 3.02 on my calculator.
So, I'm happy again \o/
Title: Re: [lua] Logo interpreter
Post by: Jim Bauwens on November 09, 2011, 10:44:04 am
While there is already a sierpinski curve included, here is sierpinski's triangle (not included):
Code: [Select]
to sierp :n :l
    if :n=0 [stop]
    repeat 3 [sierp :n-1 :l/2 fd :l rt 120]
end

pu bk 100 lt 90 bk 100 pd
sierp 5 200

This is the result:
(http://bwns.be/jim/sierp.png)
Title: Re: [lua] Logo interpreter
Post by: Adriweb on November 09, 2011, 11:36:38 am
looks awesome for such a small code...

can you comment line by line the code tho ? :o
Title: Re: [lua] Logo interpreter
Post by: Jim Bauwens on November 09, 2011, 11:53:53 am
Sure, first i'll expand it (short function names to long function names):
Code: [Select]
;define subroutine sierp
to sierp :n :l
    ;if the level is zero, stop
    if :n=0 [stop]

    ;Draw 3 lines for the triangle, while calling itself recursively (to draw the triangles on the sides)
    repeat 3 [
        sierp :n-1 :l/2
        forward :l
        right 120
    ]
end

;put the turtle on the right spot
penup
back 100
left 90
back 100
pendown

;Draw a sierpinski triangle, 5 levels deep (200 is the size)
sierp 5 200

That should be clear enough :)