Follow
Einstein2
 2

Cart #langtons_ant_tweetcart-0 | 2024-02-05 | Code ▽ | License: CC4-BY-NC-SA
2

Langton's Ant is a tremendously simple system played on a grid of pixels that can either be on (white) or off (black). Each during timestep, the ant moves forward in the direction it is currently facing (I have it facing right at the start). Then, if the ant was on a black square before it moved, it makes the square white and turns right; if the ant was on a white square, it sets the square to black and turns left. And... that's it. But despite these incredibly simple rules, Langton's ant emerges from the apparent randomness after about 11000 steps and starts forming a recurring "highway". In fact, Langton's ant not only tends toward this self-organizing behavior, but also is capable of computation with the right setup (i.e. it is a universal Turing machine) -- see this paper for a proof of that.

Anyway, this cart runs 8 steps of Langton's ant per frame until step 11250. There's a ton of layers of optimizing the code to be as short as possible, so it probably is completely unreadable at this point, haha! If someone wants an explanation of how the code works I can type one up later upon request.

P#141126 2024-02-05 02:52

 1
 ```?"\*0abc" -- expected: bc -- actual: abc```

Perhaps this isn't a bug, but it could make a padding function a lot simpler.

 ```function pad(str, char, len) return str.."\*"..(len-#str)..char end ?pad("hello","h",6) -- helloh ?pad("hello","h",5) -- helloh -- second one should just be hello```
P#118291 2022-10-01 17:52

 1

Basically the title.

 `info([cart])--returns tokens,chars,compressed_size of [cart] or the current cart if given none`

This could be useful for people who are creating carts using printh() and such, to detect if the cart is able to be run before load()ing it:

 ```tokens,chars,compressed=info("cart.p8") if(tokens<8192 and chars<65536)load("cart.p8")```

What do you all think?

P#95387 2021-07-28 18:51

 12

Cart #picoforth-4 | 2021-06-04 | Code ▽ | License: CC4-BY-NC-SA
12

Welp, this took way to long to finish. But now it's here!

picoforth is a programming language based on Forth, a family of stack-based programming languages. If you're unfamiliar with stack-based programming languages or Forth, I recommend you check out this site.

### wordlist

Here is a list of every word in picoforth. (A "word" in a stack-based language is roughly equivalent to a "function" or a "subroutine" in a normal programming language.)

 ```--typical forth stack-manipulating words pop 2pop dup 2dup over swap rotl rotr --mathematical operators + - * / // --integer division ^ --comparing operators = ~= > < --bitwise operators & --bitwise and, or, shr, shl, xor, and not, respectively | >> << ^^ ~ --storing and recalling ! --peek and poke, respectively @ --printing . --prints the popped item (works with strings and numbers) .stack --prints the entire stack (doesn't affect anything) --key operations chr ord key --halts the program until a key is pressed; pushes the pressed key input --repeats key until enter is pressed; pushes the finished string --branching branch --relative branch: I(nstruction)P(ointer) becomes the sum of itself and popped item goto --absolute branch: sets the IP to popped item --screen drawing cls flip spr pset --strings " -- opens a string, then closes it the next time it's used (i.e. " asdf " . will print asdf) "" --pushes an empty string join --concatenates the two top popped items sub # --length of string --miscellaneous exec --runs the popped item as if it were forth code time --pushes t()\1 rnd --pushes rnd(poppeditem\1) sin --pushes sin(poppeditem) cos --pushes cos(poppeditem) def --pushes the definition of popped item interpret --repeats input + exec forever --creating new words : -- : name-of-new-word [definition] ; ;```

Here's an example program, the one that generated the label image:

 `0 1 + dup dup 0x6000 + dup rotl ! 0x7fff < 2 * goto`

Post any spinoffs of this cart/programs in picoforth that you made in the comments. I'd love to see them!
For the previous picoforth, which was a work-in-progress, see this cart.

P#93031 2021-06-05 00:16

 5

Cart #picoforth-0 | 2021-05-14 | Code ▽ | License: CC4-BY-NC-SA
5

# picoforth - a stack-based programming language

picoforth is a project I started working on a while ago, and then gave up on, then returned to yesterday. It is unfinished (there are a few minor bugs, there is essentially no support for strings yet, and the method of inputting text is pretty bad), but still can do quite a lot.

If you are unfamiliar with stack-based languages, I recommend you check out easyforth, a stack-based language resembling a typical Forth. It can teach you the basics of stack-based languages, and to a lesser extent, Forth.

Here's the list of the words (for those unfamiliar, a "word" in forth is roughly comparable to a function in most other languages) currently in picoforth:

 ```(if a word doesn't have a comment, that means it works exactly like it would in a normal Forth) pop swap dup over rotl -- rotates the top three stack items left (n1 n2 n3 -> n3 n1 n2) rotr -- same, but to the right (n1 n2 n3 -> n2 n3 n1) + - * / // -- integer division = ~= -- not equals > < & -- bitwise and | -- or ^^ -- xor ~ -- not >> -- shr << -- shl not -- 1 -> 0, 0 -> 1 ! -- @ and ! are peek and poke, respectively @ . .stack -- prints the current stack, mostly useful for debugging key -- halts the program until a key is pressed; puts the ord() of that key on the stack emit branch -- relative branch: adds the instruction pointer with the value at the top of the stack (can be negative) absbranch -- absolute branch: sets the instruction pointer to the value of the item at the top of the stack : ; ```

Here's an example program, the one that generated the label image:

 `0 1 + dup dup 0x6000 + dup rotl ! 0x7fff < 2 * absbranch`

My eventual goal with this is to make tiny games/demos that you can copy and paste into this cart, similar to a tweetcart. If you want to, make spinoffs of this cart! I'd love to see them.

P#91954 2021-05-14 23:28 ( Edited 2021-05-15 02:44)

 2

### context

Earlier today, I learned that pressing ctrl+p while running a cart brings up a performance monitor (and something else I learned on accident: pressing ctrl+p in the commandline/text editor lets you use the tiny characters; this isn't documented in the pico-8 fandom wiki but is on pico-8's changelog in the manual.)

I booted up one of my carts and opened the performance monitor. (It runs at a smooth 60fps, it's not very complicated at all). For fun, I changed the cls(1) to print("\^c1"). To my great surprise, the performance monitor indicated that it did this ever so slightly quicker than cls(1). So I made a new cartridge (function _update60()for _=1,1000do print("\^c1") end) and it ran smoothly, never going over the virtual processor limit. I switched the print() to the respective cls() and it was almost 2 times more resource intensive, constantly over the virtual limit, and running at an extremely choppy ~1fps.

### conclusion

I'm not sure how this would be useful unless you're calling cls() an awful lot of times, as it takes quite a few extra characters. Even with the minor improvement of using ? rather than print() is small, as you still need a newline on either side. If you really wanted to, you could just redefine cls() to simply be something like this:

 ```function cls(a)a=a or 0 ?"\^c"..split("0123456789abcdef","")[a+1] end```
P#89318 2021-03-21 21:02 ( Edited 2021-03-22 17:22)

 3

Cart #lotsocolors-2 | 2020-12-15 | Code ▽ | No License
3

This is a simple pico-8 program that I thought I would share. The concept is simple; it's drawing circles where the center is a point on an (hidden) circle, incrementing the color each time. You can adjust the radius of the hidden circle by using left/right and the amount of circles being drawn with up/down. Since it never clears the screen, it gives really nice visuals with the trails left behind by the circles.

edit: there is now a version 1.1, which allows you to press x/o to swap whether or not screen clearing is on or not. While this looks much more boring, it allows to see how it works much better.

Cart #lotsocolors-3 | 2020-12-17 | Code ▽ | No License
3

P#85434 2020-12-15 17:19 ( Edited 2020-12-17 20:11)

 2

Cart #juliasetrender-0 | 2020-11-04 | Code ▽ | No License
2

This is a Julia set renderer. Not much else to say. The code was based off of the Wikipedia Pseudocode for the Julia Set.
The controls are (X) to zoom out, (Z)/(C) to zoom in, and the arrow keys to adjust the fractal parameters.
Hopefully you can enjoy it!
PS There are probably ways to increase the speed of this program. (This is my third published cartridge and so I'm not too great at pico-8 yet.) Once you zoom to fit the screen it takes ~2 seconds to respond. Feel free to point out changes that can be made.

P#83705 2020-11-04 18:33

 2

Cart #wezemogowo-0 | 2020-10-11 | Code ▽ | No License
2

This is my second published Pico-8 cartridge. It shows a near-perfect (in collision detection, not in the way it works) tiny collision detection function for a square. It can be expanded to any arbitrarily-sized rectangle. A square was chosen for simplicity.

There is no doubt in my mind that this can be improved upon. You know what, there's probably a way better, super obvious way that I glanced over.

I don't recommend using this for any of your games, as it has a blazingly obvious issue: You can't go into anything that isn't a black pixel. Also, due to the way it detects the pixels, it cannot detect sprites/map tiles that are smaller then a square.

The only reason I made this was to see if I could make a collision detection system that didn't use:

• Rocket science
• Quantum physics
• Carts that use coding like this video
• just kidding about most of those
I included the code so you can see how short it is (yes this is the entire cartridge's code)
 ```px=64 py=64 function collision() collr1=pget(px+8,py) collr2=pget(px+8,py+7) colll1=pget(px-1,py) colll2=pget(px-1,py+7) collu1=pget(px,py-1) collu2=pget(px+7,py-1) colld1=pget(px,py+8) colld2=pget(px+7,py+8) end function _update() cls() map(0,0,0,0,16,16) collision() spr(1,px,py) if btn(0) and colll1==0 and colll2==0 then px-=1 end if btn(1) and collr1==0 and collr2==0 then px+=1 end if btn(2) and collu1==0 and collu2==0 then py-=1 end if btn(3) and colld1==0 and colld2==0 then py+=1 end end```
P#82804 2020-10-11 20:17 ( Edited 2020-10-12 22:36)

 2