Skip to content

Latest commit

 

History

History
213 lines (186 loc) · 8.62 KB

comitl.md

File metadata and controls

213 lines (186 loc) · 8.62 KB

Comitl

comitl noun — Classical Nahuatl: [1] cooking pot, pan — a rounded or cylindrical container used to heat up meals over a fire.

Synopsis

Concentrically arranges randomly sized arcs into a pretty disc shape. Output is generated as a set of vector shapes in Scalable Vector Graphics (SVG) format and printed on the standard output stream.

Requirements

An installation of Python 3 (any version above v3.5 will do fine). For the optional PNG output support an installation of the cairosvg 3rd-party Python module is recommended. The module can be installed with Python's package manager:

pip --install cairosvg --user

Output Examples

Figure 1 Figure 2 Figure 3 Figure 4 Figure 5 Figure 6 Figure 7 Figure 8 Figure 9 Figure 10 Figure 11 Figure 12

Usage

usage: comitl.py [-V] [-h] [--circles INT] [--stroke-width FLOAT]
                 [--gap FLOAT] [--inner-radius FLOAT] [--hoffset FLOAT]
                 [--voffset FLOAT] [--color COLOR] [--random-seed INT]
                 [--randomize] [--separate-paths]
                 [--outline-mode {both,outside,inside,none}]
                 [--background-color COLOR] [--disc-color COLOR]
                 [--animation-mode {random,bidirectional,cascade-in,cascade-out}]
                 [--animation-duration FLOAT] [--animation-offset FLOAT]
                 [-o FILENAME] [--output-size INT]

Startup:
  -V, --version         show version number and exit
  -h, --help            show this help message and exit

Algorithm:
  --circles INT         number of concentric arc elements to generate inside
                        the disc  [:21]
  --stroke-width FLOAT  width of the generated strokes  [:6]
  --gap FLOAT           distance between the generated strokes
  --inner-radius FLOAT  setup inner disc radius to create an annular shape
  --hoffset FLOAT       shift the whole disc horizontally  [:0.0]
  --voffset FLOAT       shift the whole disc vertically  [:0.0]
  --color COLOR         SVG compliant color specification or identifier
                         [:black]
  --random-seed INT     fixed initialization of the random number generator
                        for predictable results
  --randomize           generate truly random disc layouts; other algorithm
                        values provided via command line parameters are
                        utilized as limits

Miscellaneous:
  --separate-paths      generate separate <path> elements for each arc;
                        automatically implied when animation support is
                        enabled
  --outline-mode {both,outside,inside,none}
                        generate bounding outline circles  [:both]
  --background-color COLOR
                        SVG compliant color specification or identifier; adds
                        a background <rect> to the SVG output
  --disc-color COLOR    SVG compliant color specification or identifier; fills
                        the background of the generated disc by adding an
                        extra <circle> element
  --animation-mode {random,bidirectional,cascade-in,cascade-out}
                        enables SVG <animateTransform> support
  --animation-duration FLOAT
                        defines base duration of one full 360° arc rotation
                        (in seconds); negative inputs switch to counter-
                        clockwise base direction  [:6.0]
  --animation-offset FLOAT
                        offset the animation (in seconds) to support rendering
                        to frame sequences for frame based animation formats.
                         [:0]

Output:
  -o FILENAME, --output FILENAME
                        optionally rasterize the generated vector paths and
                        write the result into a PNG file (requires the
                        `svgcairo' Python module)
  --output-size INT     force pixel width and height of the raster image; if
                        omitted the generated SVG viewbox dimensions are used

Usage Examples

# Generate a SVG file
./comitl.py --circles=10 --color=green > output.svg

# Rasterize directly into a PNG file (requires "cairosvg")
./comitl.py --circles=10 --disc-color=black --color="#fff" -o output.png
# Preview output with ImageMagick's "convert" and Preview.app (Mac OS X)
./comitl.py --randomise | convert svg:- png:- | open -f -a Preview.app

# Preview output with ImageMagick's "convert" and "display" (Linux/BSD/etc.)
./comitl.py --randomise | convert svg:- png:- | display

Creating frame-based animations (for use in VFX applications like BlackMagic Fusion, After Effects, etc.) is possible by utilizing the --animation-offset parameter to manually advance the SVG animation, f.ex. a quick bash script like this would create a 10s clip in Apple ProRes 4444 format with the help of ffmpeg:

#!/bin/bash

if mkdir -p './output_frames'; then
	framerate=`bc -l <<< "30000/1001"`  # NTSC
	
	for frame in {0..299}; do
		offset=`bc -l <<< "${frame}/${framerate}"`
		filename=`printf 'frame%04d.png' ${frame}`
	
		./comitl.py \
			--random-seed=12345              \
			--animation-mode=random          \
			--animation-offset="${offset}"   \
			--color=#334455                  \
			--background-color=#ddeeff       \
			--output-size=480                \
			-o "./output_frames/${filename}"
	done
	
	ffmpeg \
		-f image2                          \
		-framerate "${framerate}"          \
		-i "./output_frames/frame%04d.png" \
		-c:v prores_ks -profile:v 4        \
		"./output_frames/output.mov"
fi

History

1.7 30-May-2020
  • Fixed: random seeds passed via `--random-seed` parameter were ignored for the two random animation modes
  • The `SVGArcPathSegment` class now can handle arcs larger than 360° (not used by Comitl though)
1.6 22-May-2020
  • Added support for SVG animations with 4 different modes (`--animation-mode`, `--animation-duration`, and `--animation-offset` options)
1.5 22-May-2020
  • Added support for rasterized PNG output (using `cairosvg`)
  • Added `--separate-paths` option
  • Utilize Python's own xml module to generate the SVG data (not that this really improves the code in any way)
  • Improved render aspects to avoid various stroke overlapping issues
  • Added `--background-color` and `--disc-color` options
  • Added `--outline-mode` option
  • Constant ratio for the image border area
1.4 20-May-2020
  • Allow arc specification in degree
  • Arcs are now initialized with angular offsets and ranges
  • Improved code reusability and scope separation
1.3 19-May-2020
  • Refactored in preparation for new features
  • Optimizations
1.2 18-May-2020
  • Utilize SVG groups in the generated output
  • Added automatic identifiers to the SVG elements
  • Updated help text
1.1 18-May-2020 Initial public source code release