{"id":16533825,"url":"https://github.com/kchapelier/convchain","last_synced_at":"2025-09-22T01:31:32.781Z","repository":{"id":57206678,"uuid":"66151330","full_name":"kchapelier/convchain","owner":"kchapelier","description":"Javascript port of https://github.com/mxgmn/ConvChain","archived":false,"fork":false,"pushed_at":"2016-11-04T13:24:21.000Z","size":11,"stargazers_count":50,"open_issues_count":0,"forks_count":7,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-12-29T23:16:05.186Z","etag":null,"topics":["javascript","procedural-generation"],"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}},"created_at":"2016-08-20T14:37:19.000Z","updated_at":"2024-04-13T04:55:16.000Z","dependencies_parsed_at":"2022-09-08T17:01:07.877Z","dependency_job_id":null,"html_url":"https://github.com/kchapelier/convchain","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kchapelier%2Fconvchain","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kchapelier%2Fconvchain/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kchapelier%2Fconvchain/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kchapelier%2Fconvchain/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kchapelier","download_url":"https://codeload.github.com/kchapelier/convchain/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233704837,"owners_count":18717027,"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"],"created_at":"2024-10-11T18:15:56.207Z","updated_at":"2025-09-22T01:31:27.496Z","avatar_url":"https://github.com/kchapelier.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# convchain\n\nVanilla javascript port of [ConvChain](https://github.com/mxgmn/ConvChain).\n\n[Interactive demo](http://www.kchapelier.com/convchain-demo/)\n\n## Installing and testing\n\nWith [npm](http://npmjs.org) do:\n\n```\nnpm install convchain\n```\n\n## Basic example\n\n```js\nvar ConvChain = require('convchain');\n\nvar samplePattern = Uint8Array.from([\n    1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n    1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n    1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n    1, 1, 1, 0, 0, 0, 0, 1, 1, 1,\n    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n    1, 1, 1, 0, 0, 0, 0, 1, 1, 1,\n    1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n    1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n    1, 1, 1, 1, 1, 1, 1, 1, 1, 1\n]);\n\nvar width = 45,\n    height = 20;\n\nvar convChain = new ConvChain(samplePattern);\n\nvar generatedPattern = convChain.generate([width, height], 3, 0.5, 4); // a flat Uint8Array\n\n// some code to display the result\nfor (var y = 0; y \u003c height; y++) {\n    var s = '';\n    for (var x = 0; x \u003c width; x++) {\n        s += ' ' + generatedPattern[x + y * width];\n    }\n    console.log(s);\n}\n```\n\n## Public API\n\n### Constructor\n\n**new ConvChain(sample[, sampleSize])**\n\n - *sample :* Sample pattern as a flat array or a 2D array.\n - *sampleSize :* Indicate the width and height of the sample when used with a flat array, if omitted the sample pattern is assumed to be a square.\n\n```js\nvar testSample = Uint8Array.from([\n    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n    1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1,\n    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n    1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1,\n    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1\n]); //flat array\n\nvar convChain = new ConvChain(testSample, [14, 10]);\n```\n\n```js\nvar testSample = [\n    [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],\n    [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],\n    [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],\n    [1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1],\n    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\n    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\n    [1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1],\n    [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],\n    [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],\n    [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n]; //2D array\n\nvar convChain = new ConvChain(testSample);\n```\n\n### Methods\n\n**convChain.setSample(sample[, sampleSize])**\n\nSame arguments as the constructor.\n\n**convChain.generate(resultSize, n, temperature, iterations[, rng])**\n\nGenerate a new pattern based on the sample pattern. The generated pattern is returned as a flat Uin8Array.\n\n - *resultSize :* Width and height of the generated pattern.\n - *n :* Receptor size, an integer greater than 0.\n - *temperature :* Temperature, a float.\n - *iterations :* Number of iterations.\n - *rng :* A function to use as random number generator, defaults to Math.random.\n\n```js\nvar result = convChain.generate([100, 50], 3, 0.5, 4);\n```\n\n**convChain.iterate(field, resultSize, n, temperature[, tries[, rng]])**\n\nExecute a specific number of operations on a given pattern.\n\n - *field :* An existing pattern given as a flat Uint8Array. If *null* is given, a noisy pattern will be used instead.\n - *resultSize :* Width and height of the generated pattern.\n - *n :* Receptor size, an integer greater than 0.\n - *temperature :* Temperature, a float.\n - *tries :* Number of operations to execute, default to the result's width multiplied by the result's height\n - *rng :* A function to use as random number generator, defaults to Math.random.\n\n```js\nvar field = null;\n\nfor (var i = 0; i \u003c 32; i++) {\n    field = convChain.iterate(field, [64, 64], 3, 0.2, 128);\n\n    // ... do something with the return pattern here\n}\n```\n\n## Changelog\n\n### [1.1.0](https://github.com/kchapelier/convchain/tree/1.1.0) (2016-08-25)\n\n * Implement the iterate method.\n\n### [1.0.0](https://github.com/kchapelier/convchain/tree/1.0.0) (2016-08-21)\n\n * First implementation.\n\n### License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkchapelier%2Fconvchain","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkchapelier%2Fconvchain","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkchapelier%2Fconvchain/lists"}