An iterative algorithm to generate high quality triangulated and polygonal art from images.
Triangula uses a modified genetic algorithm to triangulate or polygonate images. It works best with images smaller than 3000px and with fewer than 3000 points, typically producing an optimal result within a couple of minutes. For a full explanation of the algorithm, see [this page in the wiki](https://github.com/RH12503/Triangula/wiki/Explanation-of-the-algorithm). You can try the algorithm out in your browser [here](https://rh12503.github.io/triangula/), but the desktop app will typically be 20-50x faster. ## Install ### GUI Install the [GUI](https://github.com/RH12503/Triangula-GUI) from the [releases page](https://github.com/RH12503/Triangula/releases). The GUI uses [Wails](https://wails.app/) for its frontend.
### Polygonal
### Community Examples
* [triangul4rt Instagram](https://www.instagram.com/triangul4rt/):
|
|
|
|
|
#### Difference from [fogleman/primitive](https://github.com/fogleman/primitive) and [gheshu/image_decompiler](https://github.com/gheshu/image_decompiler)
A lot of people have commented about Triangula's similarities to these other algorithms. While all these algorithms are iterative algorithms, the main difference is that in the other algorithms triangles can overlap while Triangula generates a triangulation.
## API
Simple example:
```Go
import imageData "github.com/RH12503/Triangula/image"
func main() {
// Open and decode a PNG/JPEG
file, err := os.Open("image.png")
if err != nil {
log.Fatal(err)
}
image, _, err := image.Decode(file)
file.Close()
if err != nil {
log.Fatal(err)
}
img := imageData.ToData(image)
pointFactory := func() normgeom.NormPointGroup {
return (generator.RandomGenerator{}).Generate(200) // 200 points
}
evaluatorFactory := func(n int) evaluator.Evaluator {
// 22 for the cache size and 5 for the block size
// use PolygonsImageFunctions for polygons
return evaluator.NewParallel(fitness.TrianglesImageFunctions(imgData, 5, n), 22)
}
var mutator mutation.Method
// 1% mutation rate and 30% variation
mutator = mutation.NewGaussianMethod(0.01, 0.3)
// 400 population size and 5 cutoff
algo := algorithm.NewModifiedGenetic(pointFactory, 400, 5, evaluatorFactory, mutator)
// Run the algorithm
for {
algo.Step()
fmt.Println(algo.Stats().BestFitness)
}
}
```
## Contribute
Any contributions are welcome. Currently help is needed with:
* Support for exporting effects to SVGs.
* Supporting more image types for the CLI and GUI. (eg. .tiff, .webp, .heic)
* Allowing drag and drop of images from the web for the GUI.
* More effects.
* Any optimizations.
Thank you to these contributors for helping to improve Triangula:
- [@bstncartwright](https://github.com/bstncartwright)
- [@2BoysAndHats](https://github.com/2BoysAndHats)