Giter VIP home page Giter VIP logo

wireworld-nim's Introduction

Wireworld

./wireworld-nim.gif

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.

I decided to implement another type of cellular automata, Wireworld, first conceived by Brian Silverman in 1987. The code for this could easily be modified to produce Conway’s Game of Life by adjusting the State type and the process(world: ref World) procedure.

Build the project from source by typing nim c display.nim into your terminal. You must have Nim installed already, as well as the SDL 2 module. You can install the SDL 2 module by running nimble install sdl2.

Run the project by calling ./display in the appropriate directory.

Description

This automata simulates a simple abstraction of electricity.

It has four states:

  • Ground
  • Wire
  • Electron head
  • Electron tail

The propagation rules are:

  • Ground -> Ground
  • Electron head -> Electron tail
  • Electron tail -> Wire
  • If Wire has exactly 1 or 2 neighbors == Electron Head:
    • Wire -> Electron Head
  • Otherwise:
    • Wire -> Wire

Implementation

This implementation is built in Nim using the SDL 2 library.

Thanks to GitHub user tylorr for taking it upon himself to make a web frontend for this project as well.

Features and Instructions

Clicking on the map changes the tile under the cursor to the current drawmode’s type.

The info bar at the bottom of the window indicates the currently selected draw mode on the left half, and the paused/play state of the simulation on the right half.

There are four drawing modes, one for each state:

  • A: Ground mode
  • S: Wire mode
  • D: Electron head mode
  • F: Electron tail mode

In addition there are a few other keybindings:

  • Up: Increases the speed of the simulation by 1 tick per second (Min: 1, Max: 60)
  • Down: Decreases the speed of the simulation by 1 tick per second
  • Q: Quit Wireworld
  • R: Clear the current world
  • P: Pause or Play the simulation (can draw while paused or playing)

Future Additions

  • [ ] Undo
  • [ ] Save and load worlds from file

wireworld-nim's People

Contributors

jhonaker avatar tylorr avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.