Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Show HN: Create your own cellular automata (aperocky.com)
111 points by Aperocky on March 15, 2021 | hide | past | favorite | 53 comments


I've been fine-tuning my forest for way too long and here's what I came up with:

    {
      "0": [
        "CountAdjacentChance eq 1 1 1 0.01",
        "CountAdjacentChance ge 1 2 1 0.03"
      ],
      "1": [
        "SpontaneousChange 2 0.00001",
        "ChangeByBlockAge gt 200 3 0.1",
        "CountAdjacentChance eq 2 1 2 0.4",
        "CountAdjacentChance eq 2 2 2 0.8",
        "CountAdjacentChance ge 2 3 2 1.0"
      ],
      "2": [
        "SpontaneousChange 3 1"
      ],
      "3": [
        "SpontaneousChange 0 0.25"
      ],
      "InitialCondition": "1 0.0005",
      "colorMap": {
        "0": "black",
        "1": "green",
        "2": "red",
        "3": "brown"
      },
      "timeStep": 30
    }


This is amazing, I think this is why cellular automata are so interesting - there are so many possibility (and conway's game of life is just a beginning!). Feel free to pull request into ./sample/, alternatively I can add this in a commit later.

The one I found the most fun is actually semi-dynamic in maze runner, there's a small trick in that you can reuse color for colormap:

  {
    "0": [
      "SpontaneousChange 1 0.15"
    ],
    "1": [
      "CountAdjacent gt 1 5 2",
      "SpontaneousChange 3 0.00001",
      "CountDirectlyAdjacent gt 3 0 3"
    ],
    "2": [],
    "3": [
      "ChangeByBlockAge gt 1 4 1"
    ],
    "4": [
      "ChangeByBlockAge gt 2 1 1"
    ], 
    "colorMap": {
      "0": "tintblack",
      "1": "cyan",
      "2": "gray",
      "3": "yellow",
      "4": "cyan"
    },
    "timeStep": 100
  }


absolutely sick. one of the coolest things I've seen all year.


Express your own cellular automata without writing 100s of lines of boiler plate.

The famous conway game of life can be expressed as:

``` { "InitialCondition": "1 0.2", "0": [ "CountAdjacent eq 1 3 1" ], "1": [ "CountAdjacent lt 1 2 0", "CountAdjacent gt 1 3 0" ] } ```

Entirely browser based.


Can you explain this language?




I find it interesting that so many people have made their own CA simulator — I’ve made one as well! [0] Mine uses a very different design to yours: it’s distributed as a library allowing people to define their own CAs, which they can then compile and run in a GUI. Compared to yours and OP’s, this is admittedly a bit hard to use, and you do need to know Haskell to use it. Additionally, I’ve only just rewritten it to use this approach, so some of the documentation and samples are out of date. (Also, it crashes a lot, I don’t know why.) Still, I have successfully used it ‘in anger’ at least once, to simulate the Beleusov-Zhabotinsky reaction for a chemistry assignment [1], so it at least seems to work.

(The categorically inclined may also be interested to know that this uses a variant of comonads [2] to define CAs, an approach I’ve found to be surprisingly flexible.)

[0] https://github.com/bradrn/cabasa

[1] http://www.jstor.org/stable/2874179 and http://www.sciencedirect.com/science/article/pii/01672789909...

[2] https://www.reddit.com/r/haskell/comments/a2vnni/a_better_co...


I have always been fascinated with alife, the first one I created was something like 20+ years ago after I read an article about Tierra in a magazine.

For anyone not familiar with tierra, peek into the rabbit hole :-)

https://web.stanford.edu/class/sts129/Alife/html/Tierra.htm

http://life.ou.edu/pubs/doc/index.html

https://ai2020.org/tom-rays-tierra

So... Genesys I linked is more than just basic CA, it consists of independent agents with each "creature" using a lisp-like instruction set.


Oh man, I spent a lot of time in high school playing around with Tierra. It is a lot of fun. A while back I started to reimplement it in rust, just to learn it, but never got very far. About a year ago, give or take, I did do a reimplementation of another alife/GA style problem, https://gitlab.com/eythian/tracker - this evolves DFSAs to follow lines. I have some more ideas that I want to test out with it actually, it's time I got back into it.


My main idea behind creating the Genesys project was to create a network of worlds - I have full intentions to make the worlds connected in the future via internet and have functionalities to share worlds, creatures etc..

I just have too much more work to do and other more pleasant blockers like children :-)


In my case I'm doing it because I really enjoy thinking about representations of solutions that make evolutionary operators more effective - it was the topic of my masters thesis. This is more "pure" GA than alife though, mostly because alife was a bit too open-ended to structure a hypothesis around for a thesis, at least as far as I could figure out, so I had to compromise.

Multi-world with migration between them was my PgDipSci thesis :)

But I also really like the results that come out of alife in the broader sense, synthetic evolution, world/environment-building, and so on. It's quite a rich interesting field that's pretty easy to dabble in with some good ideas and some programming ability.

As an aside, be aware that "genesys" is already taken in the field: http://web.cs.ucla.edu/~dyer/Papers/AlifeTracker/Alife91Jeff... (this is the HTML of the paper the thing I linked above is based on.) This may cause google-collisions.


> As an aside, be aware that "genesys" is already taken in the field

Thanks for notification, I was already aware that it was used as a brand for anoher kind of service and was pondering if I should change it but this resolved that question :-) So many thanks for that.

I would be interested in reading your thesis, is it available somewhere?


http://www.kallisti.net.nz/wikifiles/RobinsStuff/ga_thesis.p... (multipopulation) and http://www.kallisti.net.nz/~robin/thesis.pdf (representation)

Warning, I wouldn't say they're great, but if you're having trouble sleeping... :)


> So... Genesys I linked is more than just basic CA, it consists of independent agents with each "creature" using a lisp-like instruction set.

Sure, I do understand that Genesys is an agent-based simulation rather than being ‘just’ a CA. Still, at heart it seems to be a CA with adjustable rules, and as such there is a similarly to my own program.

(I’ve never heard of Tierra before, but it looks interesting; I shall have to look into it!)


This is amazing, though I have to say it is also pretty confusing.

What does the color represent? Does the creature stack?


The creatures are using lisp-likeninstruction set. For more information please check the links I provided, there is more information there.


Now that I think of it, I've created something that has a minimum level of correlation...

http://prehistoric.tech/

Though this one is more about society simulation then evolution, it does come with a command line for control.


Add some instructions to the site, now it's just a bunch of buttons and nothing happens. Or it doesn't work in Firefox.


I totally agree on instructions, it's an alpha quality hobby stuff so I haven't had time. I'll add tutorial at some point.

About firefox not working - strange! It should work on any device even with mobile browsers, thanks for notifying me.

edit: It looks there was some version conflict with my CI and it had uploaded old broken version - thanks for notification. Now it should work.


Unfortunately it still doesn't work on Firefox (v86.0.1), it's just black inside the grey border. I tried it in a different browser and there it works fine. The lack of a tutorial is not as frustrating now that I can see what's happening.


That's very strange as it works on my older firefox (78.8.0 / Linux). Sorry I don't have access to v86.0.1 so I can't check why it doesn't work on that.


i haven't made stuff like this but 800x1000 running in 60fps on cpu sounds really fast, looking amazing! is it open sourced?


Nice. It's fun the be able to play with the initial "forest fire" model and try to model different conditions -- a wet forest which takes more adjacent sparks to create a fire, a fire that stays burning longer, etc.

A couple small suggestions from someone who makes a lot of these kinds of models: A "Step" button would be really nice, to be able to advance the model a single step at a time; it would be helpful for "Start" to change to "Reset" or "Restart" after the initial press, so you're not surprised when it blows away your model; "Continue" could be disabled until you Stop, as it doesn't do anything.


Thanks for the feedback! The continue was actually a bug as it allowed multiple settimeout loops to speed up the process.

Hammered out a fix and added the step button over lunch break, pretty easy change & fix (just 10 lines!). thanks for suggestion.


Reminds me of this one https://ncase.me/sim/


Can anyone share some insight into why cellular automata are a big deal? I've built the original Game of Life and some variations (in 3D, 4D and on a hexagonal grid) during last year's Advent of Code but I still don't get the usefulness or where they fit in the larger picture of computer science.


Cellular automata models are widely used in different science and engineering disciplines. For example, I use them for the simulation of heat treatments of steel.

I guess that the fascination of the CS community comes from: 1) Conway; 2) They raise different interesting programming questions and exercises (writing GOL is a nice exercise to learn a new language, a parallel CA is a nice way to learn about parallelization, huge models pose interesting memory management questions,...); and 3) They are cool (isn't the video about GOL in APL by John Scholes one of the coolest programming videos you've ever seen?)


What kind of CA model do you use to simulate heat treatments in steel?


What do you mean by what kind? I work at a university and we use all kind of models. From very simple models to teach students or make some quick estimation to very large codebases in projects in collaboration with steel companies.

Using CA models is quite common in the field of metallurgy. A periodic grid is well suited to describe the polycrystalline microstructures we work with, and grain nucleation and growth laws fit well with the CA concept of rules.


I guess there could be a lot of attributes the compose "kind" here. In the Game of Life cells are either on or off (binary) and the rules are pretty simple. I'd guess that for a CA to do the kind of simulation you're talking about each cell would have a floating point value? (continuous values) Any idea what the next-state rules look like? Then there's the neighborhood of a CA. GoL uses a Moore neighborhood (9 surrounding cells) - what kind of neighborhood does your simulation CA use? Is it strictly the surrounding cells or does the neighborhood extend further out? And if it does extend further out do the cells further away have less impact than the ones immediately adjacent?


In the simplest models, a cell can be identified by only an integer, indicating either the phase in phase transformation problems or grain id for grain growth or recrystallization. But, in the more complex models, a cell can include all kind of properties (chemical composition, crystallographic orientation, dislocation density...).

The number of neighbors we use also varies. Sometimes, even inside the same CA model, we use a different number of neighbors to calculate the evolution of different properties. Some problems are more related with the boundary between cells, and there we have to use first order, but other properties depend on the bulk and we use second order neighbors too (of course, weighted accordingly). Electron microscopy results are commonly obtained in hexagonal grids, so hexagonal grids are often used in 2D simulations.

If you are interested in the topic, you can see for example http://www.dierk-raabe.com/reprints/cellular-automata/


I've struggled with this question as well, although Wolfram's tribute to Solomon Golomb (recently reposted here) helped me start to see why they're interesting.

https://writings.stephenwolfram.com/2016/05/solomon-golomb-1...


They are a novelty that is often surprising in the how their simple set of rules can lead to quite amazing emergent complexity. That the one-time chaotic game of life was eventually shown to be able to stably infinitely expand and be turing complete is quite interesting.

I don't know that they'll ever be useful for efficient computation, but they will likely always remain fun.

https://www.youtube.com/watch?v=xP5-iIeKXE8

I have not read it myself, but I know that Stephen Wolfram ( of Mathematica/Wolfram Alpha) laid out some arguments for the usefulness of studying cellular automata in his early 2000s book "A New Kind of Science".


I'd say it's not a very useful model on it's own, but it's a great teaching tool that illustrates emergence [1] well. It's easy to get started and it gets you into a mindset that you can then bring along to other models that you might do something slightly more useful with.

[1] https://en.wikipedia.org/wiki/Emergence


I'm sure there's a better reason, but I honestly think a major factor for why people think this stuff is important is because Conway called it 'the game of life', and it was a pretty early discovery in computer science. It was basically a recipe for sci-fi imagination and headlines, leading some people to believe this is literally a program about generating cellular life.


They're useful for making pretty patterns; digital lava lamp equivalents. Others mentioned other good reasons; so I'll throw that one in for completeness.


When I was in college I had a job working for a physics professor who was studying cellular computation. The hope was that by studying examples in nature of cellular systems that solved particular problems (e.g. a leaf trying to maximize sunlight absorption while minimizing water loss) we would be able to solve similar problems in the artificial realm. Using his equations I created a cellular automata simulation in Excel with VBA, my first real programming outside of CS classes. Good times.


Now that's dedication, I can't imagine doing the same with Excel (though it's definitely possible).

I've never tried this but what does coding in excel feels like? Does it feel like an ancient version of scratch?


I’ve never tried scratch but I can see the similarity to writing cell functions. VBA is a different beast entirely, it’s more like using a dumbed-down version of JavaScript to manipulate a simpler version of the DOM.


Question: what proportion of cellular automata generate "interesting" patterns in the way Conway's Game of Life does? For instance, in the GOL, you can create gliders, which keep their pattern over time, and even build logic gates. Perhaps you could even have "life forms" in some sense?

Presumably many automata aren't like this and just generate uninteresting patterns, or always collapse into some determinate after enough time.

What do we know about this?


The wikipedia page actually has a lot of depth on this topic, with other rulesets as well (see "specific rules" at the bottom): https://en.m.wikipedia.org/wiki/Cellular_automaton


It doesn't even necessarily need to be dynamic, for instance, use this to generate a maze:

  {
    "0": [
      "SpontaneousChange 1 0.1"
    ],
    "1": [
      "CountAdjacent gt 1 5 2"
    ],
    "2": [],
    "colorMap": {
      "0": "tintblack",
      "1": "cyan",
      "2": "gray"
    }
  }


Is there a path through the maze it generates? If so, are there multiple paths?


maybe it's provable mathematically, but I don't think it follow any strict bounds.


I've got a CA that can run a maze. Can I generate a maze using your maze-generating code and then use that as the starting point for my maze-runner? It doesn't seem to be possible - when I enter my maze running code and start the whole thing resets.


yeah sadly once it goes it doesn't accept changes to the paradigm (for now). I think it's a good feature to add though (hot start!), thanks for the suggestion.

EDIT: I just changed it to support hot loading (might have to reload). Need to pause first though, can hot load through either continue or step buttons.



Cellular Automata are so cool. I did a project for a distributed computing course on them and it was real fun throwing different rules in and seeing what emerged.


A couple years ago I threw together some MATLAB functions to take a wolfram number and a seed row, along with some cosmetic parameters, to generate elementary cellular automata. Nothing very big or elaborate, but fun and handy for exploring the ECAs themselves.

https://github.com/ninly/ecafun


Wolfram has produced a number of interesting articles, as well as a book, that explore the meta-landscape of cellular automata.


More recently, he's been exploring the application of cellular-automata-like rules to more general graphs (ie. nodes and edges) rather than the classic grids of cells: https://www.wolframphysics.org/technical-introduction/


Dijkstra did something along those lines with his “diffusing computations.”[1]

[1] https://www.cs.utexas.edu/users/EWD/transcriptions/EWD06xx/E...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: