Skip to content
This repository has been archived by the owner on Jun 2, 2021. It is now read-only.

Two implementations of "Generalization of Conway's Game of Life to a continuous domain — SmoothLife" written in Swift for the iPhone. One uses Metal and the other uses vDSP.

License

Notifications You must be signed in to change notification settings

tscheepers/SmoothLife-Swift

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SmoothLife in Swift

Two implementations of "Generalization of Conway's "Game of Life" to a continuous domain - SmoothLife" written in Swift for the iPhone. Firstly, this repository contains a CPU implementation using vDSP for optimized matrix arithmetic and FFT. Secondly, the repository contains a GPU implementation written fully in Metal shading language, including the FFT.

SmoothLife in Swift running in the iPhone Simulator

I started this project to learn a bit about numeric computation on the GPU and other specialized hardware in a fun way. And also, I think looking at SmoothLife is just mesmerizing.

My implementation took inspiration from the original C++ implementation by the paper's author Stephan Rafler, a Python implementation by Sean Murphy, and a Dart/WebGL implementation by Robert Muth (live version, blog article). This blogpost by Mikola Lysenko was a great help as well.

The codebase also includes a simple implementation of the orignal Game of Life written in Metal shading language.

Written in Swift 5.3.2 using Xcode 12.3 for iOS 14.3.

SmoothLife Configuration

The original SmoothLife C++ implementation has a configuration file in which you can specify certain paramters. This implementation defaults to the same parameters used by Robert Muth in his implementation. Resulting in nice gliders and wires.

2 2   12.0  4.0  12.0  0.100   0.254  0.312  0.340  0.518   2 0 0   0.0  0.0

Fast Fourier transform

An important part of the implementation is the quick application of convolutions by multiplying in the frequency domain. This requires transforming a representation to the frequency domain and back again using the fast Fourier transform. Using this trick we can apply convolutions in O(n log(n)) instead of O(n^2). Generally, FFT algorithms have the constraint that n needs to be a power of 2, e.g. 2^8 = 256. This is why our field's dimenstions are a power of two.

For the GPU implementation I needed to write an FFT in Metal shading language. This allows running the full SmoothLife algorithm on the GPU without going back for the CPU to call vDSP. You can find the standalone Metal FFT implementation here.

About

Two implementations of "Generalization of Conway's Game of Life to a continuous domain — SmoothLife" written in Swift for the iPhone. One uses Metal and the other uses vDSP.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published