C++ stdlib-only renderer that generates a sequence of images to create an animation of a rotating heart-shaped surface. B-day gift for @ainnnia :)))
heart.mp4
Julia's parametric heart surface is defined by the following equations:
Given a function
The heart surface is defined in src/codegen/generate.py
.
Functions that return sampled surface points & normal vectors are expressed in Python using SymPy.
SymPy provides C code generation capabilites, they are used to create src/codegen/surface.{c,h}
files:
Lines 13 to 14 in c9f0987
src/main.cc
contains the renderer code. It uses src/codegen/surface.h
and src/linalg.hh
(linear algebra module).
The renderer:
- samples the heart surface in the parameter domain
- applies a simplified Phong lighting model
- projects the points onto a 2D plane, using z-buffer to determine visibility
- outputs the rendered frames in PPM format
For more details, see the comments in the source code. They should be quite verbose.
The simplest way to run the renderer is to use Nix:
nix run github:havaker/heart#video heart.mp4
That command will fetch the source code, build the renderer, and render the
animation video to heart.mp4
.
If you don't have Nix, you can still build the renderer manually using the
provided CmakeLists.txt
file. To render the animation, install ffmpeg
and
follow the steps described in the flake.nix
file.
To develop the renderer, you can use the provided flake.nix
file to create a
development environment with all the necessary dependencies (Nix required). To
enter the development environment, run nix develop
in the cloned repository.
In that environment, you can use the ./run.sh
script to build and run the
preview animation.
x86-64 Linux only. It should be possible to run the renderer on other platforms
by simply modyfing the system = "..."
line in flake.nix
, but I haven't
tested it.