Skip to content

egeoz/mapgen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 

Repository files navigation

mapgen

Basic map generation with Simplex and Perlin Noise in Nim.

Requirements

  • nim
  • perlin

For the example program:

  • cligen
  • nimPNG

How to Build

git clone https://github.com/egeoz/mapgen.git
nimble install cligen nimPNG perlin
cd mapgen && nim c -d:release mapgenerator.nim

Usage

import mapgen

# MapGenerator* = object
#    width*, height*, iterationCount*: int
#    noiseSeed*: float
#    biome*: Biome
#    noise: NoiseType
#    bottomElevation*, lowElevation*, midElevation*, highElevation*, topElevation*: uint8

# proc newMapGenerator*(width: int = 1920, height: int = 1080,
#                       biome: Biome = Temperate, noise: NoiseType = NoiseType.Simplex,
#                       noiseSeed: float = -0.2, iterationCount: int = 16, bottomElevation: uint8 = 185,
#                       lowElevation: uint8 = 170, midElevation: uint8 = 160, highElevation: uint8 = 145,
#                       topElevation: uint8 = 0): MapGenerator =
let mapgen = newMapGenerator(width = 1920,
                            height = 1080,
                            biome = Temperate,
                            noise = NoiseType.Simplex,
                            noiseSeed = -0.1)

# proc generateMap*(mapgen: MapGenerator) =
mapgen.generateMap()

# proc getMap*(mapgen: MapGenerator): seq[Pixel] =
var imgData = mapgen.getMap()

# proc getMapRGB*(mapgen: MapGenerator): seq[uint8] =
imgData = mapgen.getMapRGB() # Each pixel is [R, G, B]

# Saving the map as PNG
import nimPNG
discard savePNG24("output.png", imgData, mapgen.width, mapgen.height)

Example Program

Usage:
  mapgenerator [optional-params] [output: string...]
Options:
  -h, --help                  Display this help page.
  -v, --version  false        Show version info.
  -w=, --width=  1920         Width of the map to be generated.
  --height=      1080         Height of the map to be generated.
  -b=, --biome=  "temperate"  Biome type (arctic, temperate, desert).
  -p, --perlin   false        Use Perlin instead of Simplex noise.

Examples

Simplex

  • Temperate

- Arctic

- Desert

Perlin

  • Temperate

- Arctic

- Desert

TODO

  • More biomes (ie. color schemes).
  • Gradient color change for altitude.
  • Threads

About

Basic map generation with Simplex and Perlin Noise in Nim

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages