5 ms·
Author here, I spent this weekend making an implementation of a lesser known (to me at least) cellular automaton, Wireworld. It was my first non-trivial projec
by JHonaker 9y ago
Author here, I spent this weekend making an implementation of a lesser known (to me at least) cellular automaton, Wireworld.
It was my first non-trivial project in Nim. I had a lot of fun. It uses SDL 2 as the graphics engine. Let me know if you have any little suggestions for it, or any questions about the development.
- blaze33 9y ago> Everyone knows the classic example of cellular automata, Conway’s Game of Life. Instead of rehashing an implementation of that, I wanted to build something just a little bit different while learning the Nim language. Haha, nice catch because I just did that on the other thread ;) https://news.ycombinator.com/item?id=14387684 https://news.ycombinator.com/item?id=14387684 boring implementation of the classic game of life. I don't know if it's a pure coïncidence or not but I'll have a look at your repo, nice work !
- JHonaker 9y agoIt was complete coincidence. I was trying to think of something fun, and slightly more complicated than hello world or the simple dice roller I whipped up. Your GoL implementation is so pretty though. I really need to work on my design skills.
- sevensor 9y ago284 lines! I'm impressed by the brevity. Were the SDL bindings as straightforward to use as they appear?
- Jach 9y agoI've worked with Nim's sdl2 interface too, it is indeed pretty straightforward, and it was easy for me to tell vim to know how to jump to the nim wrapper's source. The main pain points for me were 1) sdl2 is harder than sdl1 and 2) I thought some type conversion behavior (or lack thereof) was odd, especially when working with 'cints' (which is what the wrapper api expects everywhere). For a more flushed out example there's: https://hookrace.net/blog/writing-a-2d-platform-game-in-nim-with-sdl2/ https://hookrace.net/blog/writing-a-2d-platform-game-in-nim-...
- JHonaker 9y agoI actually used a few snippets of this tutorial to figure out how to use the SDL bindings. I'd never used SDL before.
- JHonaker 9y agoIt was pretty straightforward. I had never had any experience with SDL before, and I figured it out pretty quickly just from comments and the function names. I did use a tiny bit of code from the tutorial on 2D platformers linked by someone else. I'm surprised it was that brief actually. I didn't even try for brevity. And I'm sure if I had a better handle on some of the other features like macros and templates it could have been much more elegant in the display/SDL code. The actual implementation of the automaton is only about 70 lines of code if I remember correctly.
- dested 9y agoGreat implementation. I love the wireworld cellular automaton so much. A while back I implemented it in typescript and ran the computer startup file through it for the web. It is such a fun piece of logic to squeeze every nanosecond of performance out of. https://github.com/dested/WireWorld/blob/master/WireWorldTypescript/scripts/WireWorld.ts https://github.com/dested/WireWorld/blob/master/WireWorldTyp... https://dested.com/projects/wire/index.html https://dested.com/projects/wire/index.html
- JHonaker 9y agoThank you! I want to write the loading logic to get the insanely complex systems like the one you linked. I'm curious to see what the performance will be like.
- dested 9y agohttps://github.com/dested/WireWorld/blob/master/WireWorldWindows/shoes%2037.txt https://github.com/dested/WireWorld/blob/master/WireWorldWin... This is the file for the computer, shoot me an email if you ever get around to implementing it. I'd love to see the result and talk about optimizing! dested at gmail