Log In  

Cart #34207 | 2016-12-26 | Code ▽ | Embed ▽ | No License
7

WARNING : This is not (yet) a game. It's a strange thing (only) for programers.

This cartridge includes i_core and the turtle extension.
It shows how to:

  • bind a personal extension (turtle object, turtle binding) to the language core engine,
  • initialize the external extension and call its methods (from PICO-I and i_core)
  • pass parameters from PICO-8 to i_core (N).

The turtle extension includes the following commands:

  • FD forward, 20 FD
  • BD backward, 20 BD
  • TR turn right, 90 TR
  • TL turn left, 90 TL
  • CL change color, 1 CL
  • PU pen up, PU
  • PD pen down, PD
  • TO go to, 10 10 TO
  • HD head to (0 right, 90 top, 180 left, 270 down), 0 HD

Sample :

':loop 20 fd <a tr 1 - # ?loop ; :side >n 360 <n / >a <n loop ; cls 4 side'

Have fun ;-)

Cart #34198 | 2016-12-26 | Code ▽ | Embed ▽ | No License
7

This is the core engine of a language ('I') and its virtual machine (all of this in PICO-8).
You can extend this engine (see how _SHW or _CLS are implemented).
You can create synonyms for a simplier use (see ADD and +).

The programs must be writen in a line. Terms are separated by space.

The engine is stack based (like forth): '5 4 + .' => shows 9

The operators + - * / and flr function are available.
The '#' duplicates the last value (of the stack).

You can evaluate (5 + 4) (3 + 2) with '5 4 + 3 2 + .' => 45

Create a sub function

:NAME <sequence of instructions> ;

':A 5 4 + ; :B 3 2 + ; A B * .' => 45

You can call the sub function NAME with its NAME (see A and B in the sample).

Create SQUARE and evaluate 3^2:

':SQUARE # * ; 3 SQUARE .' => 9

Conditional call

?NAME

If the last value in the stack isn't zero it calls NAME else it goes to the next instruction.

This is usefull to create tests and loops:

':SA # . 1 - ; :LP SA # ?LP ; 5 LP 0 .'

Count down from 5 to 0 (then stop).

You can use variables:
>NAME (load value from stack)
<NAME (push value in the stack)

'1 >A <A <A + .' =>2

You can use many :EVAL call to enter your program (one line per call).
You can use as many i_core engines as you want at the same time (object).
You can execute the whole program (:EXEC) or run it :STEP by step.

:STATE returns 3 when done. You can restart with :STATE(0).

If you have read the description so far, you may have a question.
This sounds crazy... So, why?

I'm working on two games. In the first you have to build a program by stacking graphic items to draw on screen to replicate a drawing with the minimal amonth of items. In the second, some robots fight together using genetic algorithms to evolve (by sharing part of their own code to create new ones).

I think I can share this library and my interest in doing this.

jihem
picoscope101.fr where mad things come to life...

P#34035 2016-12-23 14:04 ( Edited 2016-12-29 09:03)

Nice work! Here's my attempt at printing the first n numbers of the Fibonacci sequence. (n is 10 in this snippet)

vm:eval(':f >j >a >b <a <a <b + # . <j 1 - # ?f ; :fib >j >a >b <b . <a . <b <a <j 2 - f ; cls 0 1 10 fib')

edit: except for n < 3, I guess.

P#34063 2016-12-23 20:33 ( Edited 2016-12-24 02:16)

Thanks
You have well understood. Very nice attempt. I have added it in the i_core+turtle.
I hope you will continue to explore and share :-)

I have added a new sample similar to 'turtle logo'.
This addon allows to draw on screen with orders like fd (forward), tr (turn right)...

':loop 20 fd <a tr 1 - # ?loop ; :side >n 360 <n / >a <n loop ; cls 4 side'

P#34077 2016-12-24 02:56 ( Edited 2016-12-24 17:31)

i_core (and i_core + turtle) updated (now v1.0)

The numbers are now floating point numbers. This make it more accurate.
In turtle sample, using floating point number in the angle calculation permits to close the forms (with N>6) in the drawing process.

P#34201 2016-12-26 04:30 ( Edited 2016-12-26 09:34)

Oh cool, a PICO-8 Forth-like! Awesome- I will give it a spin when I have a chance.

P#34388 2016-12-28 17:45 ( Edited 2016-12-28 22:45)

You're welcome :-)
Now I'm working on the editor.

I saw you have already found it ;-)

P#34419 2016-12-29 04:03 ( Edited 2016-12-29 09:04)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-19 01:38:56 | 0.012s | Q:19