All Projects → redblobgames → Mapgen2

redblobgames / Mapgen2

Licence: apache-2.0
JavaScript version of mapgen2 polygon map generator algorithms

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Mapgen2

creature-creator
Procedurally generate creatures in Unity - inspired by Spore.
Stars: ✭ 185 (-37.5%)
Mutual labels:  procedural-generation
macroverse
An entire universe on the Ethereum blockchain
Stars: ✭ 31 (-89.53%)
Mutual labels:  procedural-generation
DungeonTemplateLibraryUnity
🌏: Dungeon free resources (terrain & roguelike generation)
Stars: ✭ 51 (-82.77%)
Mutual labels:  procedural-generation
tripbot9000
Procedural generation of geometric patterns and fractals.
Stars: ✭ 22 (-92.57%)
Mutual labels:  procedural-generation
SdfFontDesigner
Offline font tuning/bitmap generation via shaders
Stars: ✭ 56 (-81.08%)
Mutual labels:  procedural-generation
Procedural-Generation
An Overview of Procedural Generation Techniques and Applications
Stars: ✭ 23 (-92.23%)
Mutual labels:  procedural-generation
alien-script-generator
Procedurally generated front for alien languages
Stars: ✭ 17 (-94.26%)
Mutual labels:  procedural-generation
Wavefunctioncollapse
Bitmap & tilemap generation from a single example with the help of ideas from quantum mechanics
Stars: ✭ 17,156 (+5695.95%)
Mutual labels:  procedural-generation
differential-growth
adrianton3.github.io/differential-growth/
Stars: ✭ 27 (-90.88%)
Mutual labels:  procedural-generation
fishdraw
procedurally generated fish drawings
Stars: ✭ 1,963 (+563.18%)
Mutual labels:  procedural-generation
plants
Procedural generation of plants.
Stars: ✭ 16 (-94.59%)
Mutual labels:  procedural-generation
DoomlikeDungeons
A procedural multi-room dungeon generator for Minecraft
Stars: ✭ 23 (-92.23%)
Mutual labels:  procedural-generation
FallingSandSurvival
2D survival game inspired by Noita and slightly Terraria
Stars: ✭ 66 (-77.7%)
Mutual labels:  procedural-generation
IsoRTS
Isometric RTS game with procedural generated maps.
Stars: ✭ 14 (-95.27%)
Mutual labels:  procedural-generation
VulkanRenderer
Personal repo for learning the vulkan graphics api
Stars: ✭ 42 (-85.81%)
Mutual labels:  procedural-generation
cloud gen
Procedural Generation of Clouds with Vector Graphics
Stars: ✭ 46 (-84.46%)
Mutual labels:  procedural-generation
Worlds
World History Simulator
Stars: ✭ 47 (-84.12%)
Mutual labels:  procedural-generation
Project Skylines
procedural retro 3d game, winner of the GitHub Gameoff 2017
Stars: ✭ 293 (-1.01%)
Mutual labels:  procedural-generation
Bwo
An infinity procedural online game using Flutter with NodeJS and flames
Stars: ✭ 262 (-11.49%)
Mutual labels:  procedural-generation
city-tour
A procedurally generated city built with WebGL and three.js
Stars: ✭ 57 (-80.74%)
Mutual labels:  procedural-generation

[[http://unmaintained.tech/][http://unmaintained.tech/badge.svg]]

JavaScript version of my [[https://github.com/amitp/mapgen2/][Polygon Map Generator]].

  • Most of the algorithms are reimplemented rather than ported, so there are some minor differences, but it mostly follows what's described on [[http://www-cs-students.stanford.edu/~amitp/game-programming/polygon-map-generation/][this page]].
  • The data structures are rather different. The mesh connectivity is separate from the generated map (elevation, rivers, biomes, etc.). The original project uses an “array of struct” approach whereas this one uses a “struct of arrays” approach (see [[https://en.wikipedia.org/wiki/AOS_and_SOA][explanation]]).
  • The naming convention for the data is =x_property_y= where =x= and =y= are =r=, =s=, or =t= indicating the type of the input (=x=) and output (=y=). For example, =t_downslope_s= would be an array indexed by a =t= (triangle) id, and returning an =s= (side) id.
  • The maps are created with 0 ≤ x ≤ 1000, 0 ≤ y ≤ 1000.

This repository contains the map generation algorithms but not the code for UI or rendering. I only used it for [[https://www.redblobgames.com/maps/mapgen2/][this one project]] so it's not a general purpose library.

** Examples

The way I used this library was with Poisson Disc to create points for the mesh, and a seeded random number library.

#+begin_src js const SimplexNoise = require('simplex-noise'); const DualMesh = require('@redblobgames/dual-mesh'); const MeshBuilder = require('@redblobgames/dual-mesh/create'); const Map = require('@redblobgames/mapgen2'); const Poisson = require('poisson-disk-sampling'); const {makeRandInt} = require('@redblobgames/prng');

let mesh = new DualMesh( new MeshBuilder() .addPoisson(Poisson, 100) .create() );

let map = new Map(mesh, { amplitude: 0.2, length: 4, seed: 12345 }, makeRandInt, );

map.calculate({ noise: new SimplexNoise(), shape: {round: 0.5, inflate: 0.4, amplitudes: [1/2, 1/4, 1/8, 1/16]}, numRivers: 30, drainageSeed: 0, riverSeed: 0, noisyEdge: {length: 10, amplitude: 0.2, seed: 0}, biomeBias: {north_temperature: 0, south_temperature: 0, moisture: 0}, }); #+end_src

If you want to use your own points for the mesh, keep in mind that they are expected to be in the range 0 ≤ x ≤ 1000, 0 ≤ y ≤ 1000:

#+begin_src js const points = [[250, 250], [750, 250], [750, 750], [250, 750]]; let mesh = new DualMesh( new MeshBuilder() .addPoints(points) .create() ); #+end_src

The code is written assuming we need to use seeds for repeatable results, but if you don't care about seeded random numbers, you can use the built-in random number function instead of =makeRandInt= from my library:

#+begin_src js function makeRandInt (_ignoreSeed) { return N => Math.round(Math.random() * N); } #+end_src

You can pass in your own noise function instead of using the =SimplexNoise= library:

#+begin_src js noise: {noise2D(nx, ny) { return … }} #+end_src

However, the code as written doesn't have a way to pass in your own height map or a water/land assignment function. You can modify the =assign_r_water= function if you want to use your own water/land shape.

** Output

If your project needs polygon data:

#+begin_src js let polygons = []; for (let r = 0; r < map.mesh.numSolidRegions; r++) { polygons.push({ biome: map.r_biome[r], vertices: map.mesh.r_circulate_t([], r) .map((t) => map.t_pos([], t)) }); } #+end_src

If you want the noisy edges instead, see =map.s_lines[s]= for the line segments that should be used instead of side =s=.

If your game needs the polygons split into triangles:

#+begin_src js let triangles = []; for (let s = 0; s < map.mesh.numSolidSides; s++) { let r = map.mesh.s_begin_r(s), t1 = map.mesh.s_inner_t(s), t2 = map.mesh.s_outer_t(s); triangles.push({ biome: map.r_biome[r], indices: [ map.r_pos([], r), map.t_pos([], t1), map.t_pos([], t2), ] }); } #+end_src

If your game needs the polygons split into tiles:

The map coordinates are 0 to 1000. Scale these to the desired size of the map. Use a polygon rasterization library like [[https://github.com/rastapasta/points-in-polygon][points-in-polygon]] to get a list of tiles for each polygon. I have not tried this yet.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].