Author Topic: LogoMagic  (Read 4095 times)

0 Members and 1 Guest are viewing this topic.

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
LogoMagic
« on: November 13, 2011, 11:25:46 pm »
LogoMagic



http://www.omnimaga.org/index.php?action=downloads;sa=view;down=739

LogoMagic is a Logo interpreter for the Ti-Nspire series. It is written in Lua, so only works on OS 3 and above.
It supports the UCB Logo dialect, and understands quite some primitives.

There is a built-in editor to create your scripts on-calc.
So, in short: another language for the Ti-Nspire :p


Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55941
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: LogoMagic
« Reply #1 on: November 13, 2011, 11:32:02 pm »
Hmm I never heard of Logo before. This seems interesting, though, for those who know it. :D

I also like how it lets you edit programs on-calc. :)
« Last Edit: November 13, 2011, 11:32:16 pm by DJ_O »

Offline Darl181

  • «Yo buddy, you still alive?»
  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3408
  • Rating: +305/-13
  • VGhlIEdhbWU=
    • View Profile
    • darl181.webuda.com
Re: LogoMagic
« Reply #2 on: November 13, 2011, 11:48:27 pm »
Logo can be fun, it gave me the idea for my old..um..logo :P (If I'm thinking about the right Logo that is)
Spoiler For img:
« Last Edit: November 13, 2011, 11:49:12 pm by Darl181 »
Vy'o'us pleorsdti thl'e gjaemue

Offline Michael_Lee

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1019
  • Rating: +124/-9
    • View Profile
Re: LogoMagic
« Reply #3 on: November 14, 2011, 12:25:02 am »
I'm really fond of Logo myself.

I once had a large math paper and used the Turtle module in Python (which is pretty much a copy of Logo) to construct a bunch of pictures/geometric shapes for it.  I was the envy of my math class :D

Spoiler For Spoiler:


Spoiler For Spoiler:

« Last Edit: November 14, 2011, 12:27:31 am by Michael_Lee »
My website: Currently boring.

Projects:
Axe Interpreter
   > Core: Done
   > Memory: Need write code to add constants.
   > Graphics: Rewritten.  Needs to integrate sprites with constants.
   > IO: GetKey done.  Need to add mostly homescreen IO stuff.
Croquette:
   > Stomping bugs
   > Internet version: On hold until I can make my website less boring/broken.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55941
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: LogoMagic
« Reply #4 on: November 14, 2011, 12:54:37 am »
Can it let us make entire games by the way?

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: LogoMagic
« Reply #5 on: November 14, 2011, 12:56:26 am »
@Darl, Michael
Why not give me the logo code, I'll try it on my calculator :D

Offline Michael_Lee

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1019
  • Rating: +124/-9
    • View Profile
Re: LogoMagic
« Reply #6 on: November 14, 2011, 01:19:00 am »
Can it let us make entire games by the way?
I know that some versions of Logo can, but I think Logo's mostly meant for pretty graphics.


@Darl, Michael
Why not give me the logo code, I'll try it on my calculator :D

It might need some editing, but here you go:
I don't trust myself atm to make any changes to the code, so I just added comments.
Also, I think the trig functions take in radians in Python, but I liked degrees, so I have sort of a conversion thing going on in there. 

Code: [Select]

from turtle import *
from math import *

def main():
    # Setting up a screen 1000 by 1000 pixels
    setup(1000, 1000)
    hideturtle()
    penup()

    # This code is designed so that you simply call the functions
    # you want to use down below to draw the appropriate figure.

    setheading(270)
    drawStellarFigure(5, 5, write_total=False)
   
    return

def drawTriNum(side_length, tilt=60, distance=10, dot_size=5, write_total=True):
    """Draws a triangular number (1, 3, 6, 10, etc...)
   
    side_length = the length of a single side. 
        1 -> Triangle with area of 1
        2 -> Triangle with area of 3
        3 -> Triangle with area of 6
    tilt = The way the triangle is angled.
    distance = The distance (in pixels) between each dot
    dot_size = The size of each dot (in pixels)
    write_total = Disregard this, don't bother translating.
    """

    start_position = position()
    start_heading = heading()
    penup()
    tracer(False)
   
    total_dots = 0
    for i in range(side_length):   
        setheading(tilt)
        for j in range(i):
            forward(distance)
        setheading(0)
        for k in range(side_length - i):
            dot(dot_size, "black")
            total_dots += 1
            forward(distance)
        goto(start_position)

    # Don't bother translating anything from here to the Return.
    if write_total:
        goto(start_position)
        setheading(0)
        forward((side_length - 1) * distance / 2 + 1)
        setheading(270)
        forward(30)
        write(str(total_dots), move=False, align="center",
              font=("Times New Roman", 12, "normal"))
    goto(start_position)
    setheading(start_heading)
    tracer(True)
    return total_dots


def drawStellarFigure(vertex_num, shell_num, warp=1, distance=10, dot_size=5, write_total=True):
    """Draws a stellar figure (like a star).

    vertex_num = the number of vertexes
    shell_num = how many layers there are
    warp = The higher the warp, the more angular the figure.
    distance = Sort of like the distance between dots
    dot_size = The size of each dot (in pixels)
    """
    shell_num -= 1
    start_position = position()
    start_heading = heading()
    penup()
    tracer(False)
   
    dot(dot_size, "black")
    total_dots = 1
   
    shell = []
    for i in range(shell_num):
        for j in range(vertex_num):
            for k in range(2):
                if k:
                    forward(distance * (i + 1) * warp)
                else:
                    forward(distance * (i + 1))
                dot(dot_size, "black")
                temp1 = radians(180/vertex_num)
                temp2 = acos(sin(temp1/warp))
                right(90 - degrees(temp2) + 180/vertex_num)
                total_dots += 1
                shell.append(position())
            goto(start_position)
            setheading(start_heading - 360/vertex_num*(j+1))
        goto(shell[-1])
        pendown()
        for pos in shell:
            goto(pos)
        penup()
        goto(start_position)
        setheading(start_heading)
        shell = []

    # Don't translate this 'if' statement
    if write_total:
        forward(distance * (shell_num + 3))
        setheading(0)
        forward(1)
        write(str(total_dots), move=False, align="center", font=("Times New Roman", 12, "normal"))
    goto(start_position)
    setheading(start_heading)
    tracer(True)
    return total_dots



if __name__ == "__main__":
    main()
    mainloop()    # This runs the actual program
« Last Edit: November 14, 2011, 01:21:55 am by Michael_Lee »
My website: Currently boring.

Projects:
Axe Interpreter
   > Core: Done
   > Memory: Need write code to add constants.
   > Graphics: Rewritten.  Needs to integrate sprites with constants.
   > IO: GetKey done.  Need to add mostly homescreen IO stuff.
Croquette:
   > Stomping bugs
   > Internet version: On hold until I can make my website less boring/broken.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55941
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: LogoMagic
« Reply #7 on: November 14, 2011, 03:46:27 am »
Ah ok, thanks for the info. :)

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: LogoMagic
« Reply #8 on: November 14, 2011, 09:56:57 am »
@Michael_Lee, to be honest, that isn't Logo :p
Its just python with turtle graphics :)
I could convert it to Logo, but I'm too lazy right now :)

Can it let us make entire games by the way?

My current implementation runs the whole code in one time, and then displays the result.
But I can make a version that draws stuff during run time, making it possible to create games :)

Offline Darl181

  • «Yo buddy, you still alive?»
  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3408
  • Rating: +305/-13
  • VGhlIEdhbWU=
    • View Profile
    • darl181.webuda.com
Re: LogoMagic
« Reply #9 on: November 14, 2011, 10:46:28 am »
@Darl, Michael
Why not give me the logo code, I'll try it on my calculator :D
Sure, why not.
In programming class we had a unit in MSWLogo, see if I can find the drive that I have the stuff saved on.
A few q's:
- Does it have the "Commander" (text I/O thing)
- Can it run the subroutines, or does it run the whole file?

I think this is the majority of the stuff I made, I'll need to find the old flash drive tho :P
Spoiler For WFRNG, diamonds, house, more random stuffs:
to boxes
repeat 5[
make "this repcount
repeat 4[
fd :this*10+20 rt 90
]]
end

to bush :size
repeat 12[squ :size rt 30]
end

to cent_square
pu fd 50 rt 90 pd fd 50
repeat 3[
rt 90 fd 100
]
rt 90 fd 50 rt 90 pu fd 50 rt 180 pd
end

to circle
repeat 180[fd 1 rt 2]
end

to corners
cs
repeat 4[
repeat 4[fd 10 lt 90]
fd 100 rt 90
]
end

to cus_square :size
repeat 4[fd :size rt 90]
end

to diamondR
make "position pos
repeat 2[fd 60 rt 60 fd 60 rt 120]
pu fd 10 rt 60 fd 10 lt 60 pd
repeat 2[fd 40 rt 60 fd 40 rt 120]
pu fd 10 rt 60 fd 10 lt 60 pd
repeat 2[fd 20 rt 60 fd 20 rt 120]
pu setpos :position pd
end

to flag
fd 60 rt 90
squ 20
rt 90 fd 60 rt 180
end

to flags
cs st
lt 45
flag
fd 20
lt 90
fd 20
rt 180
flag
end

to flower
repeat 3[
lt 30
repeat 3[
cent_square
]
]
lt 90
repeat 12[
fd 49 rt 180 fd 49 rt 210
]
fd 100 rt 60 tri 20 rt 180 tri 20 rt 120 fd 50
ht wait 60 st
end

to hello
cs rt 90
make "string [Hello world!]
label :string
end

to house
cs pd
rect 100 200
fd 100 lt 90 fd 20 rt 180
tri 240
lt 60 fd 40 lt 30 fd 100
lt 90 fd 5 rt 180
repeat 2[fd 40 lt 90 fd 10 lt 90]
fd 35 rt 90 fd 50
pu home ;#### outline is finished, start windows
fd 30 rt 90 fd 25 lt 90 pd windoww pu rt 90 fd 110 lt 90 pd windoww pu home ;bottom windows
fd 100 rt 90 fd 40 lt 90 pu fd 20
repeat 2[pd windoww fd 40 lt 90 fd 5 rt 180 tri 50 fd 5 rt 90 fd 40 lt 90 pu fd 80 lt 90]
pu home pd rt 90
;#### start bushes and door
fd 70 lt 90 fd 10
bush 10
rt 180 fd 10 lt 90 fd 5
lt 90
rect 75 50
rt 90 fd 55
lt 90 fd 10 bush 10 pu home pd
;#### house is finished
rt 90 fd 9001 home rt 180 pu fd 200 lt 90 pd fd 9001 pu home
pd rt 90 fd 75 rt 102 fd 205 pu home pd
rt 90 fd 125 rt 78 fd 205 pu home pd
;#### start tree
lt 90 fd 175 rt 90 fd 50 rt 25 fd 30 lt 90 pu fd 5 pd
lt 90 fd 30 rt 90 fd 20 seth 0 fd 20
pu lt 90 fd 5 lt 90 pd fd 23 lt 65 fd 20 seth 180 fd 49
rt 180 pu fd 85 pd rt 60
repeat 6[bush 20 fd 40 lt 60]
lt 60
fd 40
bush 40
ht
end

to kitty
cs rt 30
repeat 6[
tri 100 rt 60
]
tri 50 lt 120 tri 50
rt 60 fd 100 rt 30
rt 30
repeat 2[
fd 50 rt 120 fd 50 lt 120
]
end

to polygon :size :number
make "angle 360/:number
repeat :number[fd :size rt :angle]
end

to prisms
lt 30
repeat 3[
repeat 3[
tri 100
fd 100
]
rt 120
]
end

to rect :side1 :side2
repeat 2[fd :side1 rt 90 fd :side2 rt 90]
end

to rps ;rock paper scissors
cs
make "ai random 3
;w00t for finally counting from zero :P
seth 0 ht pu lt 90 fd 200 seth 90
label [0 is rock, 1 is paper, 2 is scissors]
wait 120
make "pc rw ;pc==player's choice
seth 180 fd 30 seth 90
if :pc=:ai [label [Same!] stop]
ifelse (or (and :pc=0 :ai=1) (and :pc=1 :ai=2) (and :pc=2 :ai=0)) [label [You lost (eht emag)!]] [label [You won!!!!!!1111!!!!!!!!!! 0.o]]
end

to signals
cs
repeat 2[
fd 30
rt 90
square
rt 90
fd 30
]
end

to squ :size
repeat 4[fd :size rt 90]
end

to square
repeat 4[fd 100 rt 90]
end

to star
setpensize [5 5]
setPC [150 150 0]
setFC [255 255 0]
pd cs
SETH 18
repeat 5[fd 50 rt 144 fd 50 lt 72]
pu rt 90 fd 20 fill
ht
end

to steps
cs
repeat 2[
repeat 4[
squ 20
fd 10 lt 90 fd 20 rt 90
]
repeat 4[
squ 20
rt 90 fd 20 lt 90 fd 10
]
fd 20 rt 90 fd 20 rt 90
]
end

to strings
repeat 30[
tri 150 tri 100 tri 50 rt 12
]
end

to tri :size
repeat 3[fd :size lt 120]
end

to triangle
repeat 3[fd 100 rt 120]
end

to WFRNG ;wacky fun random numbar generator
show [Nick Disabato's]
show [/<-3R33+ Number]
show [Guessing Program]
show []
show [Yes I'm really doing this for practice]
show [The Game]
show []
show [Choose a number]
show [1-30]
show [A=?]
make "numbar (random 1)+1
make "guess rw
If :guess>30 [print[Out of range!]]
If :guess<1 [print[Out of range!]]
Ifelse :guess=:numbar [print[Yes! Nick's]] [print[That's not it!]]
If :guess=:numbar [print[ticalc.org]]
If :guess=:numbar [print[password is]]
If :guess=:numbar [print[**********]]
End

to whee
pd
repeat 360[repeat 4[fd 10 rt 90]pu fd 20 rt 1 pd wait 1]
end

to windmill
cs
repeat 10[
flag
rt 36
]
end

to windoww
squ 40
rt 90 fd 20 pu lt 90 fd 20 pd
repeat 4[squ 15 rt 90]
pu bk 20 lt 90 fd 20 rt 90 pd
end
Vy'o'us pleorsdti thl'e gjaemue

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: LogoMagic
« Reply #10 on: November 14, 2011, 11:48:28 am »
- Does it have the "Commander" (text I/O thing)
- Can it run the subroutines, or does it run the whole file?

Currently my logo version doesn't support input (user entering stuff), but it supports all the list/word modification stuff (well, probably not all, but enough).
For text output there is "print" and "label".
If I have some time, I'll make it accept input too :)

Yes, it supports subroutines. That way most logo code will run without a hitch :D

Edit: And thanks for all the code!
« Last Edit: November 14, 2011, 11:49:35 am by jimbauwens »