Skip to content

A simple Game of Life app with ability to draw current generation written in C11 with SDL2.

License

Notifications You must be signed in to change notification settings

menshiva/draw-of-life

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Draw of Life
Code quality

Key Features 🍪 | Requirements 🧬 | Build and Run 🚀 | Controls 📃 | Credits ✍

Preview

Key Features 🍪

Cell data packing

Cell data (such as color, number of alive neighbors, etc.) is packed in a single 32-bit unsigned integer. Used for saving memory and simplifying the algorithm for next epoch generation.

00000000 00000000 00000000 000 0000 0
R channel G channel B channel Unused bits Alive neighbors Is alive

You can see the exact implementation in cells.h file.

Generations history buffer

Current epoch is stored in buffer before the new one is generated, so you are able to return to previous generation(s) or undo changes.

You can see the exact implementation in gens_buffer.h file.

Buffer size is 128 by default (which means that it can hold current generation and 127 previous generations). You can change it in preference file.

Averaging neighbor colors

When cell becomes a live cell on next generation we need to assign color to it. My approach is to get average color of all alive neighbor cells.

You can see the exact implementation in generateCellHexColor function in cells.h file.

Requirements 🧬

Build and Run 🚀

Preferences (optional)

You can also customize preferences before compilation by modifying prefs.h file.

Install SDL2

Windows (Visual Studio)

No actions needed.

Linux

Download and install libsdl2-dev via your package manager, for example:

sudo apt install libsdl2-dev

Build and run the application

mkdir build
cd build
cmake .. && make all
./DrawOfLife

Controls 📃

Mouse

  • Left mouse button click (hold) on grid: Draw with selected color (mark cell(s) as alive).
  • Left mouse button click on color palette: Change draw color.
  • Right mouse button click (hold) on grid: Erase (mark cell(s) as dead).

Keyboard

  • Left arrow / Right arrow: Change draw color.
  • Up arrow / Down arrow: Next / previous generation.
  • G: Toggle grid.
  • C: Clear all (mark all cells as dead).
  • Space: Start / stop animation with generating next epochs.
  • Esc: Close app.

Credits ✍

Third-party libraries / frameworks

Used algorithms

Author

About

A simple Game of Life app with ability to draw current generation written in C11 with SDL2.

Topics

Resources

License

Stars

Watchers

Forks

Languages