{"id":13410409,"url":"https://github.com/rh12503/triangula","last_synced_at":"2025-05-14T23:07:46.131Z","repository":{"id":47413009,"uuid":"354015172","full_name":"rh12503/triangula","owner":"rh12503","description":"Generate high-quality triangulated and polygonal art from images.","archived":false,"fork":false,"pushed_at":"2021-09-02T02:11:07.000Z","size":29539,"stargazers_count":3861,"open_issues_count":8,"forks_count":123,"subscribers_count":41,"default_branch":"main","last_synced_at":"2025-05-03T01:45:58.482Z","etag":null,"topics":["art","evolutionary-algorithms","evolutionary-art","generative-art","genetic-algorithm","go","golang","gui","polygons","triangles","triangula"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rh12503.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-04-02T12:38:24.000Z","updated_at":"2025-04-29T19:57:35.000Z","dependencies_parsed_at":"2022-09-18T06:53:41.546Z","dependency_job_id":null,"html_url":"https://github.com/rh12503/triangula","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rh12503%2Ftriangula","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rh12503%2Ftriangula/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rh12503%2Ftriangula/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rh12503%2Ftriangula/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rh12503","download_url":"https://codeload.github.com/rh12503/triangula/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254243362,"owners_count":22038046,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["art","evolutionary-algorithms","evolutionary-art","generative-art","genetic-algorithm","go","golang","gui","polygons","triangles","triangula"],"created_at":"2024-07-30T20:01:06.704Z","updated_at":"2025-05-14T23:07:41.122Z","avatar_url":"https://github.com/rh12503.png","language":"Go","readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"/assets/logo.svg\" width=\"250px\"\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003eAn iterative algorithm to generate high quality triangulated and polygonal art from images.\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n\u003ca\u003e\u003cimg src=\"https://github.com/RH12503/Triangula/actions/workflows/test.yml/badge.svg\" alt=\"Test status\"\u003e\u003c/a\u003e\n\u003ca href=\"https://pkg.go.dev/github.com/RH12503/Triangula\"\u003e\u003cimg src=\"https://pkg.go.dev/badge/github.com/RH12503/Triangula.svg\" alt=\"Go Reference\"\u003e\u003c/a\u003e\n\u003ca href=\"https://goreportcard.com/report/github.com/RH12503/Triangula\"\u003e\u003cimg src=\"https://goreportcard.com/badge/github.com/RH12503/Triangula\" alt=\"Go Report Card\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opensource.org/licenses/MIT\"\u003e\u003cimg src=\"https://img.shields.io/badge/License-MIT-yellow.svg\" alt=\"License: MIT\"\u003e\u003c/a\u003e\n\u003ca href=\"https://twitter.com/intent/tweet?text=An%20iterative%20algorithm%20to%20triangulate%20images.\u0026url=https://github.com/RH12503/triangula\u0026hashtags=golang,geneticalgorithm,generativeart\"\u003e\u003cimg src=\"https://img.shields.io/twitter/url/http/shields.io.svg?style=social\" alt=\"Tweet\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\nTriangula 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). \n\nYou can try the algorithm out in your browser [here](https://rh12503.github.io/triangula/), but the desktop app will typically be 20-50x faster. \n\n## Install\n\n### GUI\nInstall the [GUI](https://github.com/RH12503/Triangula-GUI) from the [releases page](https://github.com/RH12503/Triangula/releases). \nThe GUI uses [Wails](https://wails.app/) for its frontend. \n\u003cp float=\"left\" align=\"middle\"\u003e\n\u003cimg src=\"/assets/gui1.png\" width=\"49%\"\u003e\n\u003cimg src=\"/assets/gui2.png\" width=\"49%\"\u003e\n\u003c/p\u003e\nIf the app isn't running on Linux, go to the Permissions tab in the executable's properties and tick `Allow executing file as program`. \n\n### CLI\nInstall the [CLI](https://github.com/RH12503/Triangula-CLI) by running: \n```\ngo get -u github.com/RH12503/Triangula-CLI/triangula\n```\n\nYour `PATH` variable also needs to include your `go/bin` directory, which is `~/go/bin` on macOS, `$GOPATH/bin` on Linux, and `c:\\Go\\bin` on Windows. \n\nThen run it using the command: \n```\ntriangula run -img \u003cpath to image\u003e -out \u003cpath to output JSON\u003e\n```\n\nand when you're happy with its fitness, render a SVG:\n```\ntriangula render -in \u003cpath to outputted JSON\u003e -img \u003cpath to image\u003e -out \u003cpath to output SVG\u003e \n```\nFor more detailed instructions, including rendering PNGs with effects see [this page](https://github.com/RH12503/Triangula-CLI/blob/main/README.md). \n\n## Options\nFor almost all cases, only changing the number of points and leaving all other options with their default values will generate an optimal result. \n\n| Name  | Flag | Default |  Usage |\n| ------------- | ---- | ------------- | -- |\n|  Points |  `--points, -p`  | 300 | The number of points to use in the triangulation   |\n| Mutations  |  `--mutations, --mut, -m`  |  2 | The number of mutations to make |\n| Variation | `--variation, -v` | 0.3 | The variation each mutation causes |\n| Population | `--population, --pop, --size` | 400 | The population size in the algorithm |\n| Cutoff | `--cutoff, --cut` | 5 | The cutoff value of the algorithm |\n| Cache | `--cache, -c` | 22 | The cache size as a power of 2 |\n| Block | `--block, -b` | 5 | The size of the blocks used when rendering |\n| Threads | `--threads, -t` | 0 | The number of threads to use or 0 to use all cores | \n| Repetitions | `--reps, -r`| 500 | The number of generations before saving to the output file (CLI only) | \n\n## Examples of output\n### Triangulated\n\u003cimg src=\"/assets/output/grad.png\" height=\"400\"/\u003e\n\u003cimg src=\"/assets/output/plane.png\" height=\"400\"/\u003e \n\u003cimg src=\"/assets/output/sf.png\" height=\"400\"/\u003e\n\u003cimg src=\"/assets/output/elon.png\" height=\"400\"/\u003e\n\u003cimg src=\"/assets/output/astro.png\" height=\"400\"/\u003e\n\n### Polygonal\n\u003cimg src=\"/assets/output/dog.png\" height=\"400\"/\u003e\n\u003cimg src=\"/assets/output/obama.png\" height=\"400\"/\u003e \n\u003cimg src=\"/assets/output/science.png\" height=\"400\"/\u003e\n\u003cimg src=\"/assets/output/queen.png\" height=\"400\"/\u003e\n\n### Community Examples\n* [triangul4rt Instagram](https://www.instagram.com/triangul4rt/):\n\u003cp float=\"left\" align=\"middle\"\u003e\n\u003cimg src=\"/assets/output/bunny.png\" width=\"200px\"/\u003e\n\u003cimg src=\"/assets/output/owl.png\" height=\"150px\"/\u003e\n\u003cimg src=\"/assets/output/panda.png\" height=\"150px\"/\u003e\n\u003c/p\u003e\n\n\n### Comparison to [esimov/triangle](https://github.com/esimov/triangle)\nesimov/triangle seems to be a similar project to Triangula that is also written in Go. However, the two appear to generate very different styles. One big advantage of triangle is that it generates an image almost instantaneously, while Triangula needs to run many iterations. \n\nesimov/triangle results were taken from their [Github repo](https://github.com/esimov/triangle), and Triangula's results were generated over 1-2 minutes. \n| esimov/triangle | Triangula |\n| :---: | :---: |\n| \u003cimg src=\"https://github.com/esimov/triangle/blob/master/output/sample_11.png\" height=\"250\"/\u003e | \u003cimg src=\"/assets/output/result.png\" height=\"250\"/\u003e |\n| \u003cimg src=\"https://github.com/esimov/triangle/blob/master/output/sample_3.png\" height=\"250\"/\u003e | \u003cimg src=\"/assets/output/result2.png\" height=\"250\"/\u003e  |\n\n#### Difference from [fogleman/primitive](https://github.com/fogleman/primitive) and [gheshu/image_decompiler](https://github.com/gheshu/image_decompiler)\nA 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. \n\n## API \nSimple example: \n```Go\nimport imageData \"github.com/RH12503/Triangula/image\"\n\nfunc main() {\n    // Open and decode a PNG/JPEG\n    file, err := os.Open(\"image.png\")\n\n    if err != nil {\n          log.Fatal(err)\n    }\n\n    image, _, err := image.Decode(file)\n\n    file.Close()\n\n    if err != nil {\n          log.Fatal(err)\n    }\n\n    img := imageData.ToData(image)\n\n\n    pointFactory := func() normgeom.NormPointGroup {\n          return (generator.RandomGenerator{}).Generate(200) // 200 points\n    }\n\n    evaluatorFactory := func(n int) evaluator.Evaluator {\n          // 22 for the cache size and 5 for the block size\n          // use PolygonsImageFunctions for polygons \n\t\t  return evaluator.NewParallel(fitness.TrianglesImageFunctions(imgData, 5, n), 22)\n    }\n\n    var mutator mutation.Method\n\n    // 1% mutation rate and 30% variation\n    mutator = mutation.NewGaussianMethod(0.01, 0.3)\n\n    // 400 population size and 5 cutoff\n    algo := algorithm.NewModifiedGenetic(pointFactory, 400, 5, evaluatorFactory, mutator)\n\n    // Run the algorithm\n    for {\n          algo.Step()\n          fmt.Println(algo.Stats().BestFitness)\n    }\n}\n\n```\n## Contribute\nAny contributions are welcome. Currently help is needed with:\n* Support for exporting effects to SVGs. \n* Supporting more image types for the CLI and GUI. (eg. .tiff, .webp, .heic)\n* Allowing drag and drop of images from the web for the GUI. \n* More effects. \n* Any optimizations. \n\nThank you to these contributors for helping to improve Triangula: \n- [@bstncartwright](https://github.com/bstncartwright)\n- [@2BoysAndHats](https://github.com/2BoysAndHats)\n","funding_links":[],"categories":["Go","By Industry","By Language"],"sub_categories":["Other","Go"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frh12503%2Ftriangula","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frh12503%2Ftriangula","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frh12503%2Ftriangula/lists"}