kanjivg-tools/README.md

2.2 KiB

kanjivg-tools

WIP

Kanimaji & KanimajiTool

This is a library & program pair that implements CSS animations for SVG files in the KanjiVG dataset, roughly based on the original kanimaji.py script (mirror).

The program is just a dead simple executable driver for the library. This project is currently still work in progress, but it is feature complete, and no major changes are expected in the public API (apart for error handling).

Library usage

In the simplest usecase, the library consists of just two public functions:

void AnimateFile(const Path& source, const Path& destination,
                 const AnimationSettings& settings = AnimationSettings::Default());

std::string Animate(const std::string& source,
                    const AnimationSettings& settings = AnimationSettings::Default());

The former function takes in two paths, where the first one specifies the file to be read, and the second one specified a path where the resulting animated SVG image shoule be stored.

The latter takes in a string that already contains the SVG kanji data, and returns a string containing the animated SVG file. This function performs all operations in memory.

The default settings (currently) approximate the default settings in the kanimaji.py script. In case these are not desired, it is possible to configure the animation to an extent, e.g. like this:

AnimateFile("084b8.svg", "084b8-out.svg", AnimationSettings {
    .StrokeProgression = Progression::EaseInOut,
    .UnfilledStroke = StrokeStyle {
        .Width = 2.0,
        .Colour = RGB::FromHex("#EEEEEE"),
    },
    .FilledStroke = StrokeStyle {
        .Width = 3.0,
        .Colour = RGB::FromHex("#000000"),
    },
    .StrokeFillingColour = RGB::FromHex("#FF0000"),
    .EnableBrush = Flag::Enable,
    .Brush = StrokeStyle {
        .Width = 5.5,
        .Colour = RGB::FromHex("#FF0000"),
    },
    .BrushBorder = StrokeStyle {
        .Width = 7.0,
        .Colour = RGB::FromHex("#666666"),
    },
    .LengthToTimeScaling = [] (double length) -> double {
        return std::pow(length, 1.0 / 3.0) / 6.0;
    },
    .WaitBeforeRepeating = 1s,
    .DelayBetweenStrokes = 50ms,
});