{"id":13759500,"url":"https://github.com/krychu/wfc","last_synced_at":"2026-05-16T09:38:29.133Z","repository":{"id":43005703,"uuid":"308167239","full_name":"krychu/wfc","owner":"krychu","description":"Wave Function Collapse library in C, plus a command-line tool","archived":false,"fork":false,"pushed_at":"2026-02-23T15:30:06.000Z","size":238,"stargazers_count":364,"open_issues_count":11,"forks_count":22,"subscribers_count":9,"default_branch":"master","last_synced_at":"2026-02-23T23:38:25.598Z","etag":null,"topics":["c","command-line-tool","library","procedural-generation","procgen","wave-function-collapse","wfc"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/krychu.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2020-10-28T23:38:45.000Z","updated_at":"2026-02-23T15:33:08.000Z","dependencies_parsed_at":"2024-01-15T03:42:32.253Z","dependency_job_id":null,"html_url":"https://github.com/krychu/wfc","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/krychu/wfc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krychu%2Fwfc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krychu%2Fwfc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krychu%2Fwfc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krychu%2Fwfc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/krychu","download_url":"https://codeload.github.com/krychu/wfc/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krychu%2Fwfc/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33097298,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-16T04:41:52.686Z","status":"ssl_error","status_checked_at":"2026-05-16T04:41:52.009Z","response_time":115,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["c","command-line-tool","library","procedural-generation","procgen","wave-function-collapse","wfc"],"created_at":"2024-08-03T13:00:54.191Z","updated_at":"2026-05-16T09:38:29.127Z","avatar_url":"https://github.com/krychu.png","language":"C","funding_links":[],"categories":["C"],"sub_categories":[],"readme":"# wfc\n\nSingle-file Wave Function Collapse library in C, plus a command-line tool\n\n- License: MIT\n- Version: 1.0\n\nSupports the overlapping WFC method.\nThe method takes a small input image and generates a larger output image which is\nlocally similar to the input image. A few examples of\ninput/output pairs:\n\n\u003cimg width=\"950px\" src=\"https://user-images.githubusercontent.com/947457/150605257-ba54c0fe-734d-4458-89d6-7fd54ea99495.png\"\u003e\n\nThe WFC is often used for procedural map generation, but is not limited to this use-case.\n\nThe library is very performant and includes a number of optimizations not found in other implementations. As an example, generating a 128x128 image from cave.png (308 unique tiles) takes 371ms. Solve times (3x3 patterns, flipped and rotated) on an Intel Core Ultra 9 285K with clang -O3:\n\n| Sample | Tiles | Size | Solve (ms) |\n|---|---|---|---|\n| cave.png | 308 | 128x128 | 371 |\n| cave.png | 308 | 256x256 | 1729 |\n| twolines2.png | 76 | 128x128 | 58 |\n| twolines2.png | 76 | 256x256 | 514 |\n| wrinkles.png | 51 | 128x128 | 37 |\n| wrinkles.png | 51 | 256x256 | 356 |\n\n## LANGUAGE BINDINGS\n\n- [Rust](https://crates.io/crates/wfc-rs) -- by [Noah Ryan](https://github.com/nsmryan)\n\n## HOW TO USE THE LIBRARY\n\nOne file in your project should include `wfc.h` like this:\n\n```c\n        #define WFC_IMPLEMENTATION\n        #include \"wfc.h\"\n```\n\nOther files can also include and use `wfc.h` but they shouldn't define\n`WFC_IMPLEMENTATION` macro.\n\nAlternatively, you can build a traditional .o file with `make wfc.o` and use\n`wfc.h` as a regular header file.\n\nUsage:\n\n```c\n        struct wfc *wfc = wfc_overlapping(\n            128,             // Output image width in pixels\n            128,             // Output image height in pixels\n            input_image,     // Input image that will be cut into tiles\n            3,               // Tile width in pixels\n            3,               // Tile height in pixels\n            1,               // Expand input image on the right and bottom\n            1,               // Add horizontal flips of all tiles\n            1,               // Add vertical flips of all tiles\n            1                // Add n*90deg rotations of all tiles\n        );\n\n        wfc_run(wfc, seed);  // Run Wave Function Collapse\n                             // seed controls the random generation\n        struct wfc_image *output_image = wfc_output_image(wfc);\n        wfc_destroy(wfc);\n        // use output_image-\u003edata\n        // wfc_img_destroy(output_image);\n```\n\nBy default you work with `struct wfc_image` for inputs and outputs.\n\n```c\n        struct wfc_image {\n            unsigned char *data;\n            int component_cnt;\n            int width;\n            int height;\n         }\n```\n\n`data` is tightly packed without padding. Each pixel consists of\n`component_cnt` components (e.g., four components for rgba format).\nThe output image will have the same number of components as the input\nimage.\n\n`wfc_run` returns 0 if it cannot find a solution. You can try again like so:\n\n```c\n        wfc_run(wfc, different_seed);\n```\n\n### Working with image files\n\nwfc can optionally use [stb_image.h](https://github.com/nothings/stb) and [stb_image_write.h](https://github.com/nothings/stb) to provide\nconvenience functions for working directly with image files.\n\nYou will normally place `stb_image.h` and `stb_image_write.h` in the same\ndirectory as `wfc.h` and include their implementations in one of the\nproject files:\n\n```c\n        #define STB_IMAGE_IMPLEMENTATION\n        #define STB_IMAGE_WRITE_IMPLEMENTATION\n        #include \"stb_image.h\"\n        #include \"stb_image_write.h\"\n```\n\nFurther, you will instruct `wfc.h` to use stb:\n\n```c\n        #define WFC_IMPLEMENTATION\n        #define WFC_USE_STB\n        #include \"wfc.h\"\n```\n\nUsage:\n\n```c\n        struct wfc_image *input_image = wfc_img_load(\"input.png\");\n        struct wfc *wfc = wfc_overlapping(\n            ...\n            input_image,\n            ...\n        );\n\n        wfc_run(wfc, seed);  // Run Wave Function Collapse\n                             // seed controls the random generation\n        wfc_export(wfc, \"output.png\");\n        wfc_img_destroy(input_image);\n        wfc_destroy(wfc);\n```\n\nExtra functions enabled by the inclusion of stb:\n\n```c\n        struct wfc_image *image = wfc_img_load(\"image.png\")\n        wfc_img_save(image, \"image.png\")\n        wfc_export(wfc, \"output.png\")\n        wfc_export_tiles(wfc, \"directory\")\n        // don't forget to wfc_img_destroy(image) loaded images\n```\n\n## COMMAND-LINE TOOL\n\nThe command-line tool uses the library and allows to generate WFC images.\nThe tool depends on [stb_image.h](https://github.com/nothings/stb)\nand [stb_image_write.h](https://github.com/nothings/stb). Place both files in the same\ndirectory as `wfctool.c`.\n\n```\n        make\n        ./wfc\n```\n\nRun `./wfc` to see available options\n\n\nBasic usage:\n\n```\n        ./wfc -m overlapping samples/wrinkles.png output.png\n```\n\n## THANKS\n\nThanks for using wfc. If you find any bugs, have questions, or feedback please\nlet me know. Also, if you'd like to share your works it's very appreciated.\n\nsamp.krystian at gmail.com\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrychu%2Fwfc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkrychu%2Fwfc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrychu%2Fwfc/lists"}