A tool for recreating images with geometric primitives

To install, run:

haxelib install geometrize-haxe 1.0.2 

See using Haxelib in Haxelib documentation for more information.

Project logo

Haxelib Version Travis Unit Test Build Status Code Climate License

Geometrize Haxe is a Haxe library for recreating images with geometric primitives. Run the demo in your browser.

Geometrize Haxe is part of Geometrize, and is based on the primitive Go library.

Geometrized Cat 500 Triangles


  • Recreate images as geometric primitives - rectangles, rotated rectangles, triangles, circles, ellipses, rotated ellipses and lines are supported.
  • Export generated shape data to JSON.
  • Export geometrized images as SVGs.
  • All Haxe targets are supported.

Shape Comparison

The matrix shows typical results for circles, triangles, rotated rectangles, rotated ellipses and all supported shapes at 50, 200 and 500 total shapes:

-50 Shapes200 Shapes500 Shapes
Circles50 Circles200 Circles500 Circles
Triangles50 Triangles200 Triangles500 Triangles
Rotated Rectangles50 Rotated Rectangles200 Rotated Rectangles500 Rotated Rectangles
Rotated Ellipses50 Rotated Ellipses200 Rotated Ellipses500 Rotated Ellipses
All Shapes50 All Shapes200 All Shapes500 All Shapes

How It Works

A user provides a target image, and the algorithm finds shapes to approximate that image. To identify 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. The shapes are added one by one.


Get the Haxe library from GitHub or through haxelib.


  • Instantiate an `ImageRunner, passing it a Bitmap target image and a starting background Rgba` color.
  • Generate shapes by repeatedly calling `runner.step(options), passing in your ImageRunnerOptions`.
  • Export the results using the `export methods on SvgExporter and ShapeJsonExporter`.

Refer to the library documentation. Also see the Geometrize Haxe web demo and code, or this HaxeFlixel example and code.


Examples And Screenshots

Geometrized public domain artwork and photos:

Geometrized Flower 330 Rotated Ellipses Geometrized Train 230 Rotated Ellipses Geometrized Woodland Cemetery 600 Rotated Rectangles Geometrized Pomegranate 300 Rotated Ellipses Geometrized Monarch Butterfly 800 Various Shapes Geometrized Leafy Railroad 800 Rotated Rectangles Geometrized Pyramid 150 Triangles Geometrized Trees 210 Ellipses Geometrized Chomsky 300 Triangles Geometrized Trees 250 Rotated Ellipses Geometrized Fairies 500 Triangles

For more examples, see the Geometrize gallery.


  • This implementation is single-threaded, and performance varies by target platform. Small target images work best.
  • Got an idea or suggestion? Open an issue on GitHub, or send Sam a message on Twitter.
  • Find more related projects and open source code here.
2 weeks ago

All libraries are free

Every month, more than thousand developers use haxelib to find, share, and reuse code — and assemble it in powerful new ways. Enjoy Haxe; It is great!

Explore Haxe

Haxe Manual

Haxe Code Cookbook

Haxe API documentation

You can try Haxe in the browser!

Join us on Github!

Haxe is being developed on GitHub. Feel free to contribute or report issues to our projects.

Haxe on Github