Many of you might know me for my "TangentLock" program, one of the first public lock programs for ComputerCraft.
Today I have a very special program for you, a one-dimensional cellular automaton. What is a cellular automaton? It is basically a simple turing machine that manipulates bits according to a set of rules. To read more, visit the Wikipedia page here.
One-dimensional CA are used in the modern world for things like advanced programming algorithms, data encryption, artificial creativity, probability, sudo-random number generation, and abstract artwork.
This project was more of a fun relaxing thing for me to do in-between college classes. While working on it, I also put alot of effort into making it an educational script to help people better understand Lua. Nearly every line has a comment explaining what it does.
This program was completely coded within SciTE. The only actual computercraft testing that went on, was by Cruor on the IRC.
To use my program, install it like any other computercraft program. When you start it, it will ask you for a width. The width will define how large the environment for the CA will be. I recommend entering a number within the 2^n string, but anything will work. Make sure that your width isn't too small, or you won't see anything. Too large, and you'll run out of space on the computer screen. The bigger the width, the longer it will also take for the automaton to complete.
The next prompt will ask you for a rule. The rule is an 8-bit (numbers 0-255) decimal number, and corrosponds to Wolfram's code. To learn how these rules work, I highly recommend visiting the wikipedia link above. If you're lazy, you can look at a large list of interesting rules here.
After that's set up, you'll be asked if you want to enter a custom seed. In programming, a seed is a set of predetermined data that a program acts upon. If you choose to enter a seed by typing "y", enter the starting pattern in 1's and 0's (I'm unsure of what happens if you use anything else).
If you choose not to use a custom seed, you'll be asked if you want to use a random seed. If you choose yes to this, a random beginning seed will be generated and used.
If you don't choose to use a custom or random seed, the default seed will be chosen. The default seed is a single "on" cell in the middle of the starting seed. This seed usually generates triangular structures with very little chaos (with the exception of rule 110).
Once you've done all of that, the automaton will begin generating patterns based on your input. If the width is too wide, it might wrap around and distort, which is why smaller numbers are recommended for the width. If you're having a hard time with choosing a width, go with a width of 64.
My script can be found here: http://pastebin.com/Ru3nfViz
Change-log:
Spoiler
–1.4–Added:
- Added some sexy line numbering
- Code is now 100% all mine
- Removed my custom matrix, reducing memory usage by a factor of math.huge()
- Removed all un-needed variables and functions
- Tweaked the seed providing functions just a bit
- Shortened a ton of long functions
- The rule table is now either "1" or "0" instead of "true" or "false", which allows for instant translation without converting it.
- Revised a few comments
- Re-arranged the order that data is asked for at the beginning, now custom and random seeds should work.
- Fixed the fickle way that some rules got cut off
Screenshots:
Spoiler
Note: Because of a weird "bug" in computercraft, "t" (tab) doesn't work, and displays as a "?". I had to take out my line numbering code in the "compute" function to get it to display correctly.Rule 90, run with a width of 64 and starting with the default seed.
Rule 110, run with a width of 64 and starting with a random seed.
Rule 90, run with a width of 64 and starting with a random seed.