Log In  

Cart #24326 | 2016-07-02 | Code ▽ | Embed ▽ | No License
1

I was thinking about the current #tweetjam #tweetcart and wanted to do something fun an interactive, and though about a logo interpreter, i've made one then i've started to work on making it the shorter as possible, this is the current size it's about 200 chars, but I'm sure it can be done smaller.

How to use:

Left/Right select the logo command:

FW : Forward
TL : Turn Left
TR : Turn Right

Up/Down select the value for the current command, in degres for the rotation (TL/TR) and in pixel for moving (FW)

The top row is used to display the current command:

"A>CC VV"

where A is the current angle rotation (0 is going to the top, 90 to the right, etc..) CC is the currently selected command, and VV the command value.

To "run" the command BTN 4 (Z) is to be used!

This version is a really small subset of the Logo language, and is not interpreted as logo is of course, without a real keyboard it would be really difficult to do something better..

I will post a longer version that support most of the logo turtle commands but not as a language, only as a direct command mode.

Have fun!

It's not the code in the cart, but I've trimed it a bit, it was 346 chars it's now 314! \o/
But this one ditch the left button so you can only select in order FW → TL → TR → FW → ...

z={"fw","tl","tr"} s=1 v=0 a=0 x=64 y=64 cls() function _draw()
if(btnp(1))s+=1 s=s%3+1
if(btn(2)and v<360)v+=0.5
if(btn(3)and v>0)v-=0.5
if btnp(4)then f=sin(-a/360)*v g=-cos(a/360)*v
if(s==1)line(x,y,x+f,y+g)x+=f y+=g
if(s==2)a-=v
if(s==3)a+=v
end a%=360 rectfill(0,0,128,8,0)print(a..">"..z[s].." "..v,0,0,7)end

Older code version:

336 chars versions:

z={"fw","tl","tr"} s=1 v=0 a=0 x=64 y=64 cls() function _draw()
if(btnp(0)and s>1)s-=1
if(btnp(1)and s<3)s+=1
if(btn(2)and v<360)v+=0.5
if(btn(3)and v>0)v-=0.5
if btnp(4)then f=sin(-a/360)*v g=-cos(a/360)*v
if(s==1)line(x,y,x+f,y+g)x+=f y+=g
if(s==2)a-=v
if(s==3)a+=v
end a%=360 rectfill(0,0,128,8,0)print(a..">"..z[s].." "..v,0,0,7)end

346 chars version:

z={"fw","tl","tr"} s=1 v=0 a=0 x=64 y=64 cls() function _draw()
if(btnp(0)and s>1)s-=1
if(btnp(1)and s<3)s+=1
if(btn(2)and v<360)v+=0.5
if(btn(3)and v>0)v-=0.5
if btnp(4)then f=sin(-a/360)*v g=-cos(a/360)*v
if s==1 then line(x,y,x+f,y+g) x+=f y+=g end
if(s==2)a-=v
if(s==3)a+=v
end a%=360 rectfill(0,0,128,8,0)print(a..">"..z[s].." "..v,0,0,7)end


For the people interested in that code:
S is the currently selected command
A is the current angle [0..360[
X is the current turtle X position
Y is the current turtle Y position
V is the current selected value for the command
F and G are temporary values used for moving the turtle (basically F is next X position G the next Y position)

P#24402 2016-07-03 07:33 ( Edited 2016-07-03 13:18)


[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-28 22:30:58 | 0.009s | Q:13