This project demonstrates a simple procedural animation technique to create a snake-like movement using raylib and C. The project is inspired by a video on procedural animation by argonaut, which can be found here.
- Procedural animation: A simple and effective technique to animate a snake.
- Mouse and touch control: Move the snake by moving the mouse cursor or by touching the screen.
- Web port: The project is also ported to WebAssembly using zozlib.js.
- raylib
- A C compiler (e.g., GCC, Clang)
- Clone the repository:
git clone https://github.com/quecot/procedural-animals.git
cd procedural-animals
- Get raylib from the releases page (adapt to your OS)
wget https://github.com/raysan5/raylib/releases/download/5.0/raylib-5.0_macos.tar.gz
tar -xf raylib-5.0_macos.tar.gz
- Compile the project:
mkdir build && cd build
cmake .. -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE
cmake --build .
- Run the executable:
./main
- Mouse and touch: Move the snake by moving the mouse cursor or touching and dragging the screen on mobile.
- Spacebar: Pause or resume the snake's movement.
The project is also available as a WebAssembly (WASM) application. A live version can be found here snake.fvila.dev.
To build and run the web version:
- Compile the project for WebAssembly using nob.h:
cd web
clang -o nob nob.c
- Serve the generated WASM and access it in http://localhost:8000
python3 -m http.server
The main animation logic is implemented in the main.c file. The key components include:
- Initialization: Setting up the window, colors, and initial positions of the snake's head and body.
- Update Loop: Handling user input, updating the snake's position and body segments, and applying constraints to ensure smooth movement.
- Drawing Loop: Rendering the snake, its eyes, and the mouse cursor.
Contributions are welcome! Feel free to open issues or submit pull requests with improvements, new features, or bug fixes.
This project is licensed under the MIT License. See the LICENSE file for details.