Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sea-kg/roads2dgenerator
algorithm for procedural generation map of roads in 2d or caves or something else
https://github.com/sea-kg/roads2dgenerator
2d caves collapse-wave-function cpp generator map procedural-generation roadmap roads
Last synced: 6 days ago
JSON representation
algorithm for procedural generation map of roads in 2d or caves or something else
- Host: GitHub
- URL: https://github.com/sea-kg/roads2dgenerator
- Owner: sea-kg
- License: mit
- Created: 2023-06-02T05:08:22.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-05-02T06:46:10.000Z (7 months ago)
- Last Synced: 2024-11-14T10:16:59.128Z (6 days ago)
- Topics: 2d, caves, collapse-wave-function, cpp, generator, map, procedural-generation, roadmap, roads
- Language: C++
- Homepage:
- Size: 119 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Roads2DGenerator
Algorithm for map generation of roads in 2D
(collapse wave function???)
Forked and improved from https://github.com/sea-kg/roadmapgen2d
Example of generated structs (30x30 points):
![example1.png](https://github.com/sea-kg/Roads2DGenerator/blob/main/images/example1.png?raw=true)
![example2.png](https://github.com/sea-kg/Roads2DGenerator/blob/main/images/example2.png?raw=true)
![example3.png](https://github.com/sea-kg/Roads2DGenerator/blob/main/images/example3.png?raw=true)
![example4.png](https://github.com/sea-kg/Roads2DGenerator/blob/main/images/example4.png?raw=true)## Usage
1. Copy `src/Roads2DGenerator.*` to your project
```cpp
#include "Roads2DGenerator.h"...
int width = 30;
int height = 30;
Roads2DGenerator road2gen(width, height);
road2gen.generate(0.7);// use a table with true/false
std::vector> vPixelMap = road2gen.exportToPixelMap();
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
if (vPixelMap[x][y]) {
// has road
} else {
// no road
}
}
}// or use a table with directional elements
std::vector> vTable = exportToTable();
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
std::string sRoad = vTable[x][y];
if (sRoad == "cross") {
// ╬
} else if (sRoad == "horizontal") {
// ═
} else if (sRoad == "vertical") {
// ║
} else if (sRoad == "right-down") {
// ╔
} else if (sRoad == "left-down") {
// ╗
} else if (sRoad == "right-up") {
// ╚
} else if (sRoad == "left-up") {
// ╝
} else if (sRoad == "left-up-down") {
// ╣
} else if (sRoad == "right-up-down") {
// ╠
} else if (sRoad == "left-right-down") {
// ╦
} else if (sRoad == "left-right-up") {
// ╩
} else {
// nope
}
}
}```