Author Topic: 2D Cellular Automata  (Read 10459 times)

0 Members and 1 Guest are viewing this topic.

Offline Iambian

  • Coder Of Tomorrow
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 739
  • Rating: +216/-3
  • Cherry Flavoured Nommer of Fishies
    • View Profile
2D Cellular Automata
« on: February 07, 2012, 12:32:29 pm »
The image that I have posted is not the version that I am proposing. What is posted is my preexisting version, dating back to 2006-2007. It runs at a nice 8.73 FPS @ 6MHz according to Wabbitemu (fastcopy doesn't like it at 15MHz).

Now... what I am trying to say is that I don't think 8.73 FPS is fast enough. Me, Runer112, and (I think) ZippyDee was chatting late last night. Runer112 was trying to help ZippyDee with something about a flood fill algorithm and the manner in which he was doing it reminded me about my old 2D cellular automata program, so at one point, I innocently showed the main code to this program to Runer112 on IRC and asked him to optimize it. He basically went "wtf?" at my code and wrote it off as unoptimizable, so then we sort of went around talking about how it works, and trying to explain to him the insane method I was using to do the job. And then, at some point he suggested something that I realized I was already doing in E:SoR. Why not do 2D-CA on a vertically-aligned buffer? Yup. So now that's what I'm working on. Vertically-aligned goodness.

Now, this new version is not going to sport that flashy menu system, more or less because version 1.3 had a menu bug that would cause the calc to crash almost randomly. I never really figured out what was causing the problem. But try it out at your own risk. I'm also attaching that package. Because I'm not going with something fancy, I figured I'd go with something more intuitive instead. Like image thumbnails of what you're trying to save or load against what was already done in the 2D play field. Like the original, you'll be able to change the rulesets right from underneath an already in-progress field. That is, it'll pause when you try to quit and continue from where you left off (if you don't exit the program, that is).

So, yeah. I'm taking a small break from E:SoR (or rather, hop back and forth between the two) to work on this small, but satisfying project.

Also, I plan on having default images built in so you can select them if you don't have the pic files of what you want.

EDIT: FWIW, by "2D Cellular Automata", I'm referring to 2 two-state system in a Moore neighborhood, which is what Conway's Game of Life is run on.
« Last Edit: February 07, 2012, 10:30:22 pm by Iambian »
A Cherry-Flavored Iambian draws near... what do you do? ...

Offline Blue Raven

  • LV3 Member (Next: 100)
  • ***
  • Posts: 73
  • Rating: +3/-0
  • Trust me. I'm the Doctor.
    • View Profile
Re: 2D Cellular Automata
« Reply #1 on: February 07, 2012, 12:47:16 pm »
Woah ! Looks awesome ! What rules do you use to make the labyrinth ? :o
Apprenez l'Axe ! | DropBox


Offline Iambian

  • Coder Of Tomorrow
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 739
  • Rating: +216/-3
  • Cherry Flavoured Nommer of Fishies
    • View Profile
Re: 2D Cellular Automata
« Reply #2 on: February 07, 2012, 12:54:43 pm »
Woah ! Looks awesome ! What rules do you use to make the labyrinth ? :o
I used the "Maze" rule, which starts on line 36 of the mess that is below. What's below was copied straight out of the source of my 2D CA program. I grabbed these rules from http://en.wikipedia.org/wiki/Life-like_cellular_automaton and followed a few links to get more rules. This was fun. If you have any suggestions for what I missed, I'd be glad to include them.

Also, I intend on allowing you to define your own ruleset within the program. This is something I've always intended on doing but never got around to.

Code: [Select]
;Ruleset tables:
;Format:
;.db #ofentries,#ofneighborsToRetunToLife
;.db #ofentries,#ofneighborsToKeepThisAlive
c.Conway:
c.Life:
.db 1    ;return to life, one entry
.db 3    ;return to life, these # of neighbors
.db 2    ;keep alive, two entries
.db 2,3  ;keep alive, these # of neighbors

c.Seeds:
.db 1    ;return to life
.db 2    ;2 neighbors
.db 1    ;keep alive list
.db 9    ;illegal value to simulate the survival list as "empty"

c.Serviettes:
.db 3     ;return to life
.db 2,3,4
.db 1     ;survival
.db 9     ;impossible to simulate empty list.

c.Flakes:
.db 1     ;birth rule
.db 3
.db 9     ;return to life
.db 0,1,2,3,4,5,6,7,8  ;life without death

c.Gnarl:
.db 1     ;birth rule
.db 1
.db 1     ;survival rule
.db 1

c.Maze
.db 1     ;birth rule
.db 3
.db 5     ;survival rule
.db 1,2,3,4,5

c.2x2
.db 2     ;birth rule
.db 3,6
.db 3     ;survival rule
.db 1,2,5

c.Replicator
.db 4     ;birth rule
.db 1,3,5,7
.db 4     ;survival rule
.db 1,3,5,7

c.Amoeba:
.db 3     ;birth rule
.db 3,5,7
.db 4     ;survival rule
.db 1,3,5,8

c.HighLife:
.db 2     ;birth rule
.db 3,6
.db 2     ;survival rule
.db 2,3

c.WalledCities:
.db 5     ;birth rule
.db 4,5,6,7,8
.db 4     ;survival rule
.db 2,3,4,5

c.Stains:
.db 4     ;birth
.db 3,6,7,8
.db 6     ;survival
.db 2,3,5,6,7,8

c.Coagulations:
.db 3     ;birth
.db 3,6,7,8
.db 6     ;survival
.db 2,3,5,6,7,8

c.PseudoLife:
.db 3     ;birth
.db 3,5,7
.db 3     ;survival
.db 2,3,8

c.Move:
.db 3     ;birth
.db 3,6,8
.db 3     ;survival
.db 2,4,5

c.34Life:
.db 2     ;birth
.db 3,4
.db 2     ;survival
.db 3,4

c.DayAndNight:
.db 4     ;birth
.db 3,6,7,8
.db 5     ;survival
.db 3,4,6,7,8

c.Assimilation:
.db 3     ;birth
.db 3,4,5
.db 4     ;survival
.db 4,5,6,7

c.Coral:
.db 1     ;birth
.db 3
.db 5     ;survival
.db 4,5,6,7,8

c.LongLife:
.db 3     ;birth
.db 3,4,5
.db 1     ;survival
.db 5

c.Diamoeba:
.db 5     ;birth
.db 3,5,6,7,8
.db 4     ;survival
.db 5,6,7,8
A Cherry-Flavored Iambian draws near... what do you do? ...

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: 2D Cellular Automata
« Reply #3 on: February 07, 2012, 09:26:16 pm »
Wow, beautious!

Offline Iambian

  • Coder Of Tomorrow
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 739
  • Rating: +216/-3
  • Cherry Flavoured Nommer of Fishies
    • View Profile
Re: 2D Cellular Automata
« Reply #4 on: February 09, 2012, 02:00:20 am »
I know the menu system took a backseat to this whole thing, and I know it looks more like a BASIC program with an ASM backend to it, but really. This will help keep the program file size down and ensure that useful features are included. I haven't written said useful features, but they'll be in soon.

Planned are: thumbnail views of work screen and image files for saving and loading, and custom rule editing.

Also, the thing works faster. Can't tell how much faster it runs since wabbitemu won't give me a reliable framerate anymore. Probably has something to do with the way I'm updating the LCD. Any suggestions on how I can figure out framerate without having to have a stopwatch and a good eye (both of which I do not possess)?

EDIT: Let's see if I can link to attached images from within the same page. I do this so I can see the difference between the old and the new easier than having to scroll back and forth. Old image thinger:
« Last Edit: February 09, 2012, 02:03:07 am by Iambian »
A Cherry-Flavored Iambian draws near... what do you do? ...

Offline Eiyeron

  • Urist McEiyolobster
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1430
  • Rating: +130/-10
  • (-_(//));
    • View Profile
    • Rétro-Actif : Rétro/Prog/Blog
Re: 2D Cellular Automata
« Reply #5 on: February 09, 2012, 02:06:00 am »
If you have a functions who uses the rtc, you could make a counter who'll give you the numbers of frames displayed per second

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: 2D Cellular Automata
« Reply #6 on: February 09, 2012, 03:17:57 am »
My favorite method is to have the simulation quit after a large number of seconds, and time how long it takes to quit.

Offline Iambian

  • Coder Of Tomorrow
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 739
  • Rating: +216/-3
  • Cherry Flavoured Nommer of Fishies
    • View Profile
Re: 2D Cellular Automata
« Reply #7 on: February 09, 2012, 04:49:21 am »
My favorite method is to have the simulation quit after a large number of seconds, and time how long it takes to quit.
That was a great idea, thanks! I just remembered that there were online stopwatches, so I used one of those to time my program. I set my CA program to stop at 512 generations. The end result was about 38 seconds, which resolves to roughly 13.5 FPS @ 6MHz. My original calculation had it at around 16FPS, so that isn't too bad.

I did not time the other program, but I'm pretty sure that the older one ran much slower than that. Over all, I think this is a great success. Maybe a few minor adjustments may make this thing run ever so slightly faster, but I'm certain this is about as fast as it's going to get using this method of cell checking.

I suppose "tomorrow", I'll pull together the rest of the menu interface, add a few features additional features, and then upload this to ticalc.
A Cherry-Flavored Iambian draws near... what do you do? ...

Offline Iambian

  • Coder Of Tomorrow
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 739
  • Rating: +216/-3
  • Cherry Flavoured Nommer of Fishies
    • View Profile
Re: 2D Cellular Automata
« Reply #8 on: February 11, 2012, 05:38:29 am »
I got this thing mostly built. All that needs to be done is add a few more default images and update the rule set. This is what my program has so far:

* Ability to toggle 15MHz mode if you have it
* Change rule sets and create your own
* Save to or load from pic files 0-9, now with crappy thumbnails!
* Contains built in patterns (thus far, only Gosper Glider Gun is in. Try to suggest more!)
* Allows you to change between a wrapping buffer and a buffer with a dead zone around it
* Stopping the program at any time to make any changes.
* Takes initial input from graph buffer (best used if run from homescreen instead of a shell)
* Allows step-by-step mode in the CA field

I try to touch on all the features listed in the screenshot below
EDIT: I forgot to demonstrate the step-by-step feature >.<
Oh well. When I get the patterns and rules put in, I'll submit something to the Omnimaga archive write up that blasted ReadME file, then submit that to the archive.
« Last Edit: February 11, 2012, 05:43:42 am by Iambian »
A Cherry-Flavored Iambian draws near... what do you do? ...

Offline Blue Raven

  • LV3 Member (Next: 100)
  • ***
  • Posts: 73
  • Rating: +3/-0
  • Trust me. I'm the Doctor.
    • View Profile
Re: 2D Cellular Automata
« Reply #9 on: February 11, 2012, 09:19:36 am »
I'll try that ! I'm a big fan of the Game of Life !
For the built-in patterns, you could add puffers, spaceships...
Here are nice ones : http://home.interserv.com/~mniemiec/sship.htm
Apprenez l'Axe ! | DropBox


Offline Iambian

  • Coder Of Tomorrow
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 739
  • Rating: +216/-3
  • Cherry Flavoured Nommer of Fishies
    • View Profile
Re: 2D Cellular Automata
« Reply #10 on: February 15, 2012, 12:04:18 pm »
Attached to this post is the full program, complete with unreadable cherry-flavoured source.

Warning: Source may contain too much cherry flavouring for some people to handle. Use responsibly.

EDIT: Low frame rate screenshot attached, also probably seen in Cemetech's archives, but forgot to upload to ticalc. Also, I hope running this program is understood well enough, since I also forgot to include that information in the ReadME.txt file. You can run this from either the homescreen or a shell (as an ION program). I'm unsure if the program description is up to date.

EDIT2: Whoops. Forgot to add that screenshot. Put it in now.
« Last Edit: February 15, 2012, 04:19:17 pm by Iambian »
A Cherry-Flavored Iambian draws near... what do you do? ...

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: 2D Cellular Automata
« Reply #11 on: February 15, 2012, 12:13:08 pm »
I have downloaded it and it is still very much lovely and more so than before o.o
* Xeda112358 noms

Offline hellninjas

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 625
  • Rating: +17/-0
    • View Profile
Re: 2D Cellular Automata
« Reply #12 on: February 15, 2012, 03:11:17 pm »
Very cool I think this deserves a +1!

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: 2D Cellular Automata
« Reply #13 on: February 15, 2012, 03:15:38 pm »
That is awesome. I remember the original screenshot and how the maze reminded me a burning sheet of paper animation or something. It was a cool effect. Glad you managed to make the program faster.

Offline tr1p1ea

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 647
  • Rating: +110/-0
    • View Profile
Re: 2D Cellular Automata
« Reply #14 on: February 23, 2012, 07:40:43 pm »
Heya Iambian, i remember when you first started working on your old version. I was very impressed then and im even more impressed now!

Great work :).
"My world is Black & White. But if I blink fast enough, I see it in Grayscale."