A small CLI game using cubic spline interpolation (pronounced klie-spline). Make a path out of pebbles for some ants to follow!
To install and build, clone the repository and use build.sh (or build-brew.sh if using MacOS with Homebrew to install GSL):
$ git clone https://github.com/Athan13/cli-spline.git
$ cd cli-spline
$ bash build.sh
$ ./cli-spline.out
Dependencies are ncurses and GSL. build.sh is written for gcc.
First, drop the pebbles to make a path for the ants to follow:
Note that once you hit space, a pebble is dropped and a new one automatically appears under your cursor that you can move using the HJKL keys.
Once you've hit enter, watch the ants go! Tip: hit space a few times in quick succsession to get a full column of ants.
Once we've laid down the pebbles for the ants to follow, how do we give the ants a path that hits all the pebbles? The calculations described below are in spline-calc.c.
Fundamentally, we want to be able to describe the path of the ants as a function of time. If we think of the ants as a pair of
In order for the ants to hit every single one of the pebbles, it makes sense to make 
and likewise for
We need a couple of things to make this work. Firstly, the path must be continuous. This means that
Naively, we might have the ants follow a straight line from one pebble to the next; this does meet all of our conditions. However, this has the effect of making jagged edges at the locations of the pebbles.
The way to get around this issue is to make the derivatives of each of the
-
$x_i(i)$ is the$x$ -coordinate of the$i$ 'th pebble. -
$x_i(i+1)$ is the$x$ -coordinate of the$i+1$ 'st pebble. -
$x_i'(i) = x'_{i - 1}(i)$ . -
$x_i'(i+1) = x'_{i + 1}(i+1)$ .
Given that we have those four conditions, we can use a cubic polynomial of the form
The 
where
Finally, we set
We store all of these into one big coefficients matrix
We repeat the entire process for
In order to actually display a curve, we need to evaluate these polynomials at a series of points. Because
We do this by constructing a matrix
which allows us to calculate a path matrix


