{"id":16252984,"url":"https://github.com/neki-dev/gen-city","last_synced_at":"2025-03-19T20:31:40.473Z","repository":{"id":190617640,"uuid":"683015036","full_name":"neki-dev/gen-city","owner":"neki-dev","description":"🧩 Procedural city generation","archived":false,"fork":false,"pushed_at":"2024-07-15T08:09:22.000Z","size":943,"stargazers_count":13,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-17T10:52:07.581Z","etag":null,"topics":["2d","city","generation","map","procedural","random","street","tilemap","town"],"latest_commit_sha":null,"homepage":"https://gen-city.neki.guru","language":"TypeScript","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/neki-dev.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-08-25T11:51:50.000Z","updated_at":"2024-08-25T22:34:38.000Z","dependencies_parsed_at":null,"dependency_job_id":"98fd0e0d-cbc0-4cd9-94dc-b6153df4aa92","html_url":"https://github.com/neki-dev/gen-city","commit_stats":null,"previous_names":["neki-dev/gen-city"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neki-dev%2Fgen-city","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neki-dev%2Fgen-city/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neki-dev%2Fgen-city/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neki-dev%2Fgen-city/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/neki-dev","download_url":"https://codeload.github.com/neki-dev/gen-city/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244501411,"owners_count":20462856,"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":["2d","city","generation","map","procedural","random","street","tilemap","town"],"created_at":"2024-10-10T15:15:36.174Z","updated_at":"2025-03-19T20:31:37.842Z","avatar_url":"https://github.com/neki-dev.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## ⚡ Gen City\n[![Version](https://badgen.net/npm/v/gen-city)](https://npmjs.com/package/gen-city)\n[![Small size](https://img.badgesize.io/neki-dev/gen-city/master/dist/index.js)](https://github.com/neki-dev/gen-city/blob/master/dist/index.js)\n[![Build](https://github.com/neki-dev/gen-city/actions/workflows/deploy.yml/badge.svg)](https://github.com/neki-dev/gen-city/actions/workflows/deploy.yml)\n\nProcedural city generation\n\n.\n\n[Demo](https://gen-city.neki.guru/)\n\nDocumentation\n\n* [Install](https://github.com/neki-dev/gen-city?tab=readme-ov-file#install)\n* [Generation](https://github.com/neki-dev/gen-city?tab=readme-ov-file#generation)\n* [General](https://github.com/neki-dev/gen-city?tab=readme-ov-file#general)\n* [Nodes](https://github.com/neki-dev/gen-city?tab=readme-ov-file#nodes)\n* [Paths](https://github.com/neki-dev/gen-city?tab=readme-ov-file#paths)\n* [Buildings](https://github.com/neki-dev/gen-city?tab=readme-ov-file#buildings)\n* [Example](https://github.com/neki-dev/gen-city?tab=readme-ov-file#example)\n\n.\n\n## Install\n```sh\nnpm i gen-city\n```\n\n.\n\n## Generation\n#### Create city\n```ts\nconst city = new City(params)\n```\n| Param | Description | Default |\n| ------|-------------|---------|\n| `width` | Map width | - | \n| `height` | Map height | - | \n\n#### Generate\n```ts\nawait city.generate(params?)\n```\n| Param | Description | Default |\n| ------|-------------|---------|\n| `mode` | Generation mode.\u003cbr\u003e* `Runtime` - Random generation in runtime\u003cbr\u003e* `Seed` - Generation follows the specified seed | Runtime |\n| `seed` | Generation seed array for seed mode | - |\n| `startPosition` | Position of the first node. | Center of map |\n| `startDirections` | Start generation directions | Left, Right, Top, Bottom |\n| `streetMinLength` | Street length before generating an intersection or turn | 10 |\n| `probabilityIntersection` | Probability of generating intersection | 0.1 |\n| `probabilityTurn` | Probability of generating turn | 0.05 |\n| `probabilityStreetEnd` | Probability of generating street end | 0.001 |\n| `buildingMinSize` | Minimum building size | 3 |\n| `buildingMaxSize` | Maximum building size | 6 |\n| `buildingMinSpace` | Minimum distance between buildings | 1 |\n| `buildingMaxSpace` | Maximum distance between buildings | 3 |\n| `buildingOffset` | Distance between building and path | 0 |\n\n.\n\n## General\n#### Get size\n```ts\nconst width = city.width\nconst height = city.height\n```\n\n#### Get seed\nReturn seed if city was generated with runtime mode\n```ts\nconst seed = city.getSeed(): number[] | null\n```\n\n.\n\n## Nodes\n#### Get all nodes\n```ts\nconst nodes = city.getAllNodes(): Node[]\n```\n\n#### Get node paths\n```ts\nconst inputPaths = node.getInputPaths(): Path[]\nconst outputPaths = node.getOutputPaths(): Path[]\nconst allPaths = node.getAllPaths(): Path[]\n```\n\n#### Get node type\nGet type by count of input and output paths (Turn, Cross, End)\n```ts\nconst type = node.getType(): NodeType\n```\n\n.\n\n## Paths\n#### Get all paths\n```ts\nconst paths = city.getAllPaths(): Path[]\n```\n\n#### Get path positions\n```ts\nconst positions = path.getPositions(): { \n  beg: Position\n  end: Position\n}\n```\n\n#### Get path nodes\n```ts\nconst nodeBeg = path.getNodeBeg(): Node\nconst nodeEnd = path.getNodeEnd(): Node\n```\n\n#### Get path length\n```ts\nconst length = path.getLength(): number\n```\n\n#### Each path positions\n```ts\npath.each(callback: (position: Position) =\u003e void)\n```\n\n#### Remove path from nodes\n```ts\npath.remove()\n```\n\n#### Get path buildings\n```ts\nconst buildings = path.getBuildings(): Building[]\n```\n\n#### Get path direction\nGet direction in degrees\n```ts\nconst direction: number = path.direction\n```\n\n.\n\n## Buildings\n#### Get all buildings\n```ts\nconst buildings = city.getAllBuildings(): Building[]\n```\n\n#### Get building vertices\nArray of rectangle corners positions\n```ts\nconst vertices: Position[] = building.vertices\n```\n\n#### Get building position\nGet top left corner position\n```ts\nconst position: Position = building.position\n```\n\n#### Get building size\n```ts\nconst width: number = building.width\nconst height: number = building.height\n```\n\n#### Each building positions\n```ts\nbuilding.each(callback: (position: Position) =\u003e void)\n```\n\n#### Remove building from path\n```ts\nbuilding.remove()\n```\n\n.\n\n## Example\n```ts\nconst city = new City({\n  width: 200,\n  height: 200,\n});\n\ncity.generate({\n  streetMinLength: 15,\n}).then(() =\u003e {\n  // Draw roads\n  ctx.beginPath();\n  city.getAllPaths().forEach((path) =\u003e {\n    const positions = path.getPositions();\n    ctx.moveTo(positions.beg.x, positions.beg.y);\n    ctx.lineTo(positions.end.x, positions.end.y);\n  });\n  ctx.stroke();\n\n  // Draw buildings\n  city.getAllBuildings().forEach((building) =\u003e {\n    ctx.fillRect(\n      building.position.x,\n      building.position.y,\n      building.width,\n      building.height\n    );\n  });\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneki-dev%2Fgen-city","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fneki-dev%2Fgen-city","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneki-dev%2Fgen-city/lists"}