Geometrize Haxe is a Haxe library for recreating images with geometric primitives. Run the web demo in your browser.
The Geometrize Haxe haxelib is based on the primitive Go library.
- Recreate images as shapes - combinations of rectangles, rotated rectangles, triangles, circles, ellipses, rotated ellipses and lines are supported.
- Easily export geometrized images to SVG, or generated shape data to JSON.
- All Haxe targets are supported.
Get the Haxe library from GitHub or through haxelib.
Include it in your project .hxml
-lib geometrize-haxe
Or add it to your Project.xml
:
<haxelib name="geometrize-haxe" />
Refer to the Geometrize Haxe web demo and code, and this HaxeFlixel example and code. Also read the library documentation.
Basic usage: instantiate an ImageRunner
, pass it a Bitmap
and starting background Rgba
color. Add shapes by repeatedly calling runner.step(options)
, passing your ImageRunnerOptions
. Export the results using the export
methods of SvgExporter
and ShapeJsonExporter
.
A user provides a target image, and the algorithm finds good shapes to approximate that image. To find a good shape, the algorithm generates a large number of random candidate shapes, repeatedly improving the fit of each using a hillclimbing optimization approach, eventually choosing the best fitting shape. Shapes are added one by one.
A detailed explanation of how the algorithm works is given in the primitive readme.
- See the Geometrize resources and template repositories.
- See the Geometrize haxelib code and library documentation.
- See the Geometrize web demo and web demo code.
- See the HaxeFlixel Geometrize demo and the demo code.
- See the Primitive Go repository.
There is no jagginess when saving images as vector-based SVG e.g. pyramid or pomegranate.
Examples from geometrizing public domain artwork and photos:
- This implementation is single-threaded, and performance varies by target platform. Small target images are recommended - you probably do not need the detail anyway.
- Got an idea or suggestion? Open an issue on GitHub, or send Sam a message on Twitter.
- Geometrize Haxe is based on primitive, a Go library created by Michael Fogleman.
- Geometrize Haxe is available as a haxelib.
- Geometrize Haxe has unit tests.
- All Haxe targets are supported.