{"id":22562250,"url":"https://github.com/preciz/wfc","last_synced_at":"2025-03-28T12:42:37.660Z","repository":{"id":147673443,"uuid":"184249237","full_name":"preciz/WFC","owner":"preciz","description":"Wave Function Collapse implemented in Elixir","archived":false,"fork":false,"pushed_at":"2019-11-11T15:17:12.000Z","size":13,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-02T13:16:27.990Z","etag":null,"topics":["algorithm","elixir","wave-function-collapse"],"latest_commit_sha":null,"homepage":null,"language":"Elixir","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/preciz.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}},"created_at":"2019-04-30T11:22:33.000Z","updated_at":"2023-04-08T16:43:23.000Z","dependencies_parsed_at":"2023-06-27T14:24:47.148Z","dependency_job_id":null,"html_url":"https://github.com/preciz/WFC","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/preciz%2FWFC","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/preciz%2FWFC/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/preciz%2FWFC/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/preciz%2FWFC/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/preciz","download_url":"https://codeload.github.com/preciz/WFC/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246034266,"owners_count":20712851,"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":["algorithm","elixir","wave-function-collapse"],"created_at":"2024-12-07T22:12:11.844Z","updated_at":"2025-03-28T12:42:37.644Z","avatar_url":"https://github.com/preciz.png","language":"Elixir","readme":"# WFC\nOverlapping Wave Function Collapse algorithm implemented in Elixir.\nOne of the main goal is readability so codebase can be used for learning the algorithm.\n\n[Paper to help understand the algorithm](https://adamsmith.as/papers/wfc_is_constraint_solving_in_the_wild.pdf)\n\n[Wave Function Collapse repo](https://github.com/mxgmn/WaveFunctionCollapse)\n\n## Try it out!\n\nThis will generate an example png for you in main dir.\n```elixir\nWfc.example()\n```\n\n## How it works?\n\nLet's say you have an input like the below one:\n```elixir\n  [\n    [{255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}],\n    [{255, 255, 255}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}],\n    [{255, 255, 255}, {0, 0, 0}, {255, 0, 0}, {0, 0, 0}],\n    [{255, 255, 255}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}]\n  ]\n```\n\nFirst you create NxN tiles from it. (optionally to make more tiles you rotate them around)\nThis happens in `Wfc.Input.tiles/2`.\n```elixir\n[\n  [[{255, 255, 255}, {255, 255, 255}], [{255, 255, 255}, {0, 0, 0}]],\n  [[{255, 255, 255}, {255, 255, 255}], [{0, 0, 0}, {0, 0, 0}]],\n  [[{255, 255, 255}, {0, 0, 0}], [{255, 255, 255}, {0, 0, 0}]],\n  [[{0, 0, 0}, {0, 0, 0}], [{0, 0, 0}, {255, 0, 0}]],\n  ...\n]\n```\n\nNow you need to determine which tiles can go next to each other in which directions.\nThis happens in `Wfc.Input.constraints/2`.\nFor example if you want to determine that `b_tile` can go above `a_tile`:\n```elixir\n  [a_tile_top_row | _] = a_tile = [[{255, 255, 255}, {255, 255, 255}], [{255, 255, 255}, {0, 0, 0}]],\n\n  [_top_row | b_tile_bottom_row] = b_tile = [[{255, 255, 255}, {255, 255, 255}], [{255, 255, 255}, {0, 0, 0}]],\n\n  can_b_tile_go_on_top_of_a_tile? = (a_tile_top_row == b_tile_bottom_row)\n```\n\nNow that you have your tiles with your constraints:\n\n1. You create your output matrix and you set all elements to include all possible tiles. `Wfc.Output.new/2`\n2. You set a random element to just 1 possible tile, and you propagate the changes to the neighbours. `Wfc.Output.collapse/1`\n3. When the above propagation is ready, you select the element with lowest possibilities and you repeat step 2 until you have only elements with 1 possible tile. `Wfc.Output.lowest_possibilities_position/1`\n4. You are done.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpreciz%2Fwfc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpreciz%2Fwfc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpreciz%2Fwfc/lists"}