{"id":27761088,"url":"https://github.com/tsoding/wang-tiles","last_synced_at":"2025-04-29T12:26:02.427Z","repository":{"id":47547400,"uuid":"388824188","full_name":"tsoding/wang-tiles","owner":"tsoding","description":"Wang Tiles Grid generator","archived":false,"fork":false,"pushed_at":"2021-08-28T11:44:44.000Z","size":2246,"stargazers_count":52,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-29T12:26:00.430Z","etag":null,"topics":["computer-graphics","gradients","procedural-generation","shaders","wang-tiles"],"latest_commit_sha":null,"homepage":"","language":"C","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/tsoding.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-07-23T14:13:59.000Z","updated_at":"2025-04-20T10:28:39.000Z","dependencies_parsed_at":"2022-09-10T14:10:48.445Z","dependency_job_id":null,"html_url":"https://github.com/tsoding/wang-tiles","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/tsoding%2Fwang-tiles","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsoding%2Fwang-tiles/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsoding%2Fwang-tiles/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsoding%2Fwang-tiles/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tsoding","download_url":"https://codeload.github.com/tsoding/wang-tiles/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251501033,"owners_count":21599328,"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":["computer-graphics","gradients","procedural-generation","shaders","wang-tiles"],"created_at":"2025-04-29T12:26:01.604Z","updated_at":"2025-04-29T12:26:02.419Z","avatar_url":"https://github.com/tsoding.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Wang Tiles Grid generator\n\n![thumbnail](./imgs/grid-01.png)\n\n## Quick Start\n\nThe project is using [nobuild](https://github.com/tsoding/nobuild#nobuild) build system.\n\n```console\n$ cc -o nobuild nobuild.c\n$ ./nobuild\n$ ./wang -live\n```\n\n## Goal\n\nTrying to generate a random grid of 2-colored [Wang Tiles](http://www.cr31.co.uk/stagecast/wang/intro.html) based on a single function definition:\n\n```c\ntypedef struct { float c[2]; } Vec2f;\ntypedef struct { float c[3]; } Vec3f;\ntypedef Vec2f UV;\ntypedef Vec3f RGB;\ntypedef uint32_t BLTR;\n\nRGB wang(BLTR bltr, UV uv);\n```\n\nwhere\n\n- `bltr` is a 4 bit mask encoding the specific Wang Tile. Each bit represents a side of the tile in the following order: Bottom, Left, Top, Right. `0` is the first color, `1` is the second one.\n- `uv` is a 2D vector that represents a point on the tile. Top-Left corner is `[0.0, 0.0]`, Bottom-Right corner is `[1.0, 1.0]`. Coordinates are normalized and resolution-independant.\n- The result of the function is a 3D vector that represents an RGB color of a pixel on the tile `bltr` at `uv`.\n\nThink of it as a [Fragment Shader](https://www.khronos.org/opengl/wiki/Fragment_Shader) that generates a Texture for a Wang Tile based on its bitmask description.\n\n## Phases\n\nThe whole rendering is split into roughly 3 phases and done entirely on CPU.\n\n### Phase 1. Atlas Rendering\n\nGiven the \"Shader\" function described in the [Goal](#goal) section we generate an atlas (spritesheet) of all 16 Wang Tiles. (4 sides, 2 colors, 2⁴ = 16)\n\n![atlas-00](./imgs/atlas-00.png) ![atlas-01](./imgs/atlas-01.png)\n\n### Phase 2. Grid Generation\n\nGiven the size of the grid in tiles we generate 2D array of `BLTR`-s (defined in the [Goal](#goal) section) satisfying the Wang Tile constraints between the tiles (the adjacent side of the tiles must have the same color).\n\n### Phase 3. Grid Rendering\n\nAfter the [Atlas](#phase-1-atlas-rendering) and the [Grid](#phase-2-grid-generation) are generated we iterate over each `BLTR` in the Grid and copy the corresponding tiles from the Atlas into the final Grid image.\n\n![grid-00](./imgs/grid-00.png)\n![grid-01](./imgs/grid-01.png)\n\n## Screencasts\n\nThe development was streamed on [Twitch](https://twitch.tv/tsoding). Here is an archive of screencasts: https://www.youtube.com/playlist?list=PLpM-Dvs8t0VYgJXZyQzWjfYUm3MxcvqR0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftsoding%2Fwang-tiles","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftsoding%2Fwang-tiles","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftsoding%2Fwang-tiles/lists"}