{"id":13437670,"url":"https://github.com/kchapelier/wavefunctioncollapse","last_synced_at":"2025-04-04T19:15:16.072Z","repository":{"id":41812046,"uuid":"69691156","full_name":"kchapelier/wavefunctioncollapse","owner":"kchapelier","description":"Javascript port of https://github.com/mxgmn/WaveFunctionCollapse","archived":false,"fork":false,"pushed_at":"2023-08-24T19:11:41.000Z","size":285,"stargazers_count":490,"open_issues_count":3,"forks_count":52,"subscribers_count":13,"default_branch":"master","last_synced_at":"2024-10-18T21:20:34.456Z","etag":null,"topics":["javascript","procedural-generation","tilemap"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/kchapelier.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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-09-30T18:23:19.000Z","updated_at":"2024-09-24T17:26:58.000Z","dependencies_parsed_at":"2024-01-14T16:30:21.995Z","dependency_job_id":null,"html_url":"https://github.com/kchapelier/wavefunctioncollapse","commit_stats":{"total_commits":42,"total_committers":1,"mean_commits":42.0,"dds":0.0,"last_synced_commit":"f1374ee2c04d197afe6d01652f87663a68cbf6a5"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kchapelier%2Fwavefunctioncollapse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kchapelier%2Fwavefunctioncollapse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kchapelier%2Fwavefunctioncollapse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kchapelier%2Fwavefunctioncollapse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kchapelier","download_url":"https://codeload.github.com/kchapelier/wavefunctioncollapse/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247234927,"owners_count":20905854,"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":["javascript","procedural-generation","tilemap"],"created_at":"2024-07-31T03:00:59.172Z","updated_at":"2025-04-04T19:15:16.047Z","avatar_url":"https://github.com/kchapelier.png","language":"JavaScript","readme":"# wavefunctioncollapse\n\nJavascript port of https://github.com/mxgmn/WaveFunctionCollapse\n\n- [Interactive OverlappingModel demo](http://www.kchapelier.com/wfc-example/overlapping-model.html)\n- [Interactive SimpleTiledModel demo](http://www.kchapelier.com/wfc-example/simple-tiled-model.html)\n- [Animated SimpleTiledModel demo](http://www.kchapelier.com/wfc-example/simple-tiled-model-animated.html)\n\n## Installing\n\nWith [npm](http://npmjs.org) do:\n\n```\nnpm install wavefunctioncollapse --production\n```\n\n## Public API\n\n### OverlappingModel Constructor\n\n**new OverlappingModel(data, dataWidth, dataHeight, N, width, height, periodicInput, periodicOutput, symmetry[, ground])**\n\n - *data :* The RGBA data of the source image.\n - *dataWidth :* The width of the source image.\n - *dataHeight :* The height of the source image.\n - *N :* Size of the patterns.\n - *width :* The width of the generation (in pixels).\n - *height :* The height of the generation (in pixels).\n - *periodicInput :* Whether the source image is to be considered as periodic / as a repeatable texture.\n - *periodicOutput :* Whether the generation should be periodic / a repeatable texture.\n - *symmetry :* Allowed symmetries from 1 (no symmetry) to 8 (all mirrored / rotated variations)\n - *ground :* Id of the specific pattern to use as the bottom of the generation ([learn more](https://github.com/mxgmn/WaveFunctionCollapse/issues/3#issuecomment-250995366))\n\n```js\nvar wfc = require('wavefunctioncollapse');\n\nvar imgData = ... // let's pretend this is an ImageData retrieved from a canvas context in the browser\n\nvar model = new wfc.OverlappingModel(imgData.data, imgData.width, imgData.height, 3, 48, 48, true, true, 4);\n```\n\n### OverlappingModel Methods\n\n**model.graphics([array])**\n\nRetrieve the RGBA data of the generation.\n\n - *array :* Array to write the RGBA data into (must already be set to the correct size), if not set a new Uint8Array will be created and returned. It is recommended to use Uint8Array or Uint8ClampedArray.\n\n```js\n// create a blank ImageData\nvar imgData = canvasContext.createImageData(48, 48);\n\n// write the RGBA data directly in the ImageData\nmodel.graphics(imgData.data);\n\n// print the ImageData in the canvas\ncanvasContext.putImageData(imgData, 0, 0);\n```\n\n### SimpleTiledModel Constructor\n\n**new SimpleTiledModel(data, subsetName, width, height, periodicOutput)**\n\n - *data :* Tiles, subset and constraints definitions. The proper doc on this matter is yet to be written, check the example in the meantime.\n - *subsbetName :* Name of the subset to use from the data. If falsy, use all tiles.\n - *width :* The width of the generation (in tiles).\n - *height :* The height of the generation (in tiles).\n - *periodicOutput :* Whether the generation should be periodic / a repeatable texture.\n\n```js\nvar wfc = require('wavefunctioncollapse');\n\nvar data = ... // object with tiles, subsets and constraints definitions\n\nvar model = new wfc.SimpleTiledModel(data, null, 48, 48, false);\n```\n\n### SimpleTiledModel Methods\n\n**model.graphics([array[, defaultColor]])**\n\nRetrieve the RGBA data of the generation.\n\n - *array :* Array to write the RGBA data into (must already be set to the correct size), if not set a new Uint8Array will be created and returned. It is recommended to use Uint8Array or Uint8ClampedArray.\n - *defaultColor :* RGBA data of the default color to use on untouched tiles.\n\n```js\n// create a blank ImageData\nvar imgData = canvasContext.createImageData(48, 48);\n\n// write the RGBA data directly in the ImageData, use an opaque blue as the default color\nmodel.graphics(imgData.data, [0, 0, 255, 255]);\n\n// print the ImageData in the canvas\ncanvasContext.putImageData(imgData, 0, 0);\n```\n\n### Common Methods\n\n**model.generate([rng])**\n\nExecute a complete new generation. Returns whether the generation was successful.\n\n```js\nmodel.generate(Math.random); // return true or false\n```\n\n - *rng :* A function to use as random number generator, defaults to Math.random.\n\n**model.iterate(iterations[, rng])**\n\nExecute a fixed number of iterations. Stop when the generation is successful or reaches a contradiction. Returns whether the iterations ran without reaching a contradiction.\n\n - *iterations :* Maximum number of iterations to execute (0 = infinite).\n - *rng :* A function to use as random number generator, defaults to Math.random.\n\n```js\nmodel.iterate(30, Math.random); // return true or false\n```\n\n**model.isGenerationComplete()**\n\nReturns whether the previous generation completed successfully.\n\n**model.clear()**\n\nClear the internal state to start a new generation.\n\n## Changelog\n\n### [2.1.0](https://github.com/kchapelier/wavefunctioncollapse/tree/2.1.0) (2021-03-27)\n\n * Port of the latest changes (trivial symmetry support in SimpleTiledModel).\n * Update dev dependencies.\n\n### [2.0.0](https://github.com/kchapelier/wavefunctioncollapse/tree/2.0.0) (2019-07-06)\n\n * Port of the newer, faster, implementation.\n * This port is now written in ES6 instead of ES5 [breaking change].\n\n### [1.0.0](https://github.com/kchapelier/wavefunctioncollapse/tree/1.0.0) (2016-10-14)\n\n * Change and freeze the public API (with iteration support).\n * First publication on NPM.\n\n### License\n\nMIT\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkchapelier%2Fwavefunctioncollapse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkchapelier%2Fwavefunctioncollapse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkchapelier%2Fwavefunctioncollapse/lists"}