kiwotigo

package module
v0.0.0-...-2ab7305 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 9, 2023 License: GPL-3.0 Imports: 4 Imported by: 1

README

kiwotigo

creative-coding Go Report Card

kiwotigo is world map generation tool.

the world builder algorithm generates randomly generated 2D maps, on which regions are distributed, with the following characteristics:

  • each region has a base area that has a minimum size (can be configured)
  • each region has at least one or more connections to another nearby region
  • each region is accessible from any region via these connections

A group of regions that are close together form a continent, there may (but need not) be several continents, and a continent can also consist of only one region (like islands).

Although the generation of regions is essentially based on randomness, it can be configured quite extensively.

As output, the world builder provides a json structure, the intermediate continental format.

kiwotigo is written in javascript, whereas the core of the world map builder is developed in go and integrated via webassembly.

kiwotigo example

Just try it out for yourself!

Why?

kiwotigo creates worlds, but doesn't tell you what to do with them. that's up to you. you're a indie-gamedev and need a tool to create 2D or maybe 3D maps? or you just want to create a nice graphics demo and need random input? go ahead, let your inspiration run wild - and don't forget to drop me a message (or a PR) if you want to show something off 😉

Local Development

As a precondition a current nodejs v16+ and a go-lang (1.17+) sdk has to be installed.

Build the kiwotigo library with:

$ npm run build  # -> npx gulp buildAll

Start a http server for testing the kiwotigo.wasm module with:

$ npx serve

as an alternative you can use the gulp tasks:

$ npx gulp --tasks  # show all tasks

or just start developing with:

$ npm start

have fun!

LICENSE

the kiwotigo code is licensed under the GPLv3. see LICENSE for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateShapePath

func CreateShapePath(region *Region, shapeEdgeOrder *[]int) *[]*Vec2

func NewRegionShape

func NewRegionShape(region *Region, shapeEdgeOrder *[]int) (shape *regionShape)

Types

type CenterPoint

type CenterPoint struct {
	Vec2
	InnerRadius float64 `json:"iR"`
	OuterRadius float64 `json:"oR"`
}

CenterPoint represents a point together with an inner and outer radius.

type Continent

type Continent struct {
	Width        uint                  `json:"width"`
	Height       uint                  `json:"height"`
	Shapes       []map[string]*[]*Vec2 `json:"regions"`
	CenterPoints []CenterPoint         `json:"centerPoints"`
	RegionSizes  []float64             `json:"regionSizes"`
	Neighbors    []*[]int              `json:"neighbors"`
	// contains filtered or unexported fields
}

func NewContinent

func NewContinent(cols, rows, hexWidth, hexHeight, paddingX, paddingY uint) (continent *Continent)

func (*Continent) CreateShapes

func (continent *Continent) CreateShapes(shapeName string)

func (*Continent) CreateSomeRegions

func (continent *Continent) CreateSomeRegions()

func (*Continent) Json

func (continent *Continent) Json() string

func (*Continent) MakeNeighbors

func (continent *Continent) MakeNeighbors()

func (*Continent) MinRegionSize

func (continent *Continent) MinRegionSize() int

func (*Continent) NeighborLessRegions

func (continent *Continent) NeighborLessRegions() []*Region

func (*Continent) UpdateCenterPoints

func (continent *Continent) UpdateCenterPoints(fastGrowCount uint)

func (*Continent) UpdateRegionSizes

func (continent *Continent) UpdateRegionSizes()

type ContinentConfig

type ContinentConfig struct {
	GridWidth                 uint    `json:"gridWidth"`
	GridHeight                uint    `json:"gridHeight"`
	GridOuterPaddingX         uint    `json:"gridOuterPaddingX"`
	GridOuterPaddingY         uint    `json:"gridOuterPaddingY"`
	GridInnerPaddingX         uint    `json:"gridInnerPaddingX"`
	GridInnerPaddingY         uint    `json:"gridInnerPaddingY"`
	GridHexWidth              uint    `json:"gridHexWidth"`
	GridHexHeight             uint    `json:"gridHexHeight"`
	HexWidth                  uint    `json:"hexWidth"`
	HexHeight                 uint    `json:"hexHeight"`
	HexPaddingX               uint    `json:"hexPaddingX"`
	HexPaddingY               uint    `json:"hexPaddingY"`
	MinimalGrowIterations     uint    `json:"minimalGrowIterations"`
	FastGrowIterations        uint    `json:"fastGrowIterations"`
	MaxRegionSizeFactor       float64 `json:"maxRegionSizeFactor"`
	ProbabilityCreateRegionAt float64 `json:"probabilityCreateRegionAt"`
	DivisibilityBy            uint    `json:"divisibilityBy"`
}

type ContinentCreationStrategy

type ContinentCreationStrategy struct {
	RegionGrid
	RegionGridMask
	ContinentConfig

	Continent *Continent

	MaxRegionSize int
	// contains filtered or unexported fields
}

func NewContinentCreationStrategy

func NewContinentCreationStrategy(cfg ContinentConfig) (strategy *ContinentCreationStrategy)

NewContinentCreationStrategy creates a new instacnce of ContinentCreationStrategy

func (*ContinentCreationStrategy) BuildContinent

func (strategy *ContinentCreationStrategy) BuildContinent(onProgress func(float64)) *Continent

BuildContinent runs the full continent creation algorithm.

Should never be called twice. Should be called right after creating a new instance of ContinentCreationStrategy.

func (*ContinentCreationStrategy) ForEachGridRegion

func (strategy *ContinentCreationStrategy) ForEachGridRegion(fn gridRegionFn)

type ContinentDescription

type ContinentDescription struct {
	Continent *Continent       `json:"continent"`
	Config    *ContinentConfig `json:"config"`
}

func NewContinentDescription

func NewContinentDescription(continent *Continent, config *ContinentConfig) (cd *ContinentDescription)

func (*ContinentDescription) Json

func (cd *ContinentDescription) Json() string

func (*ContinentDescription) PrettyJson

func (cd *ContinentDescription) PrettyJson() string

type Hexagon

type Hexagon struct {
	Row, Col  uint
	Left, Top float64

	CenterPoint Vec2

	Region *Region

	NeighborNorth     *Hexagon
	NeighborNorthEast *Hexagon
	NeighborSouthEast *Hexagon
	NeighborSouth     *Hexagon
	NeighborSouthWest *Hexagon
	NeighborNorthWest *Hexagon

	NeighborRight *Hexagon
	NeighborLeft  *Hexagon
	// contains filtered or unexported fields
}

The Hexagon represents a hexagon.

func NewHexagon

func NewHexagon(col, row, width, height uint, left, top float64) (hex *Hexagon)

NewHexagon creates a new Hexagon.

Normally this is done by the HexagonGrid and you do not need to create hexagons by yourself.

func (*Hexagon) Neighbor

func (hex *Hexagon) Neighbor(index int) *Hexagon

Neighbor returns the neighbor hexagon by index.

  _1_
2/   \0
3\___/5
   4

func (*Hexagon) NeighborsWithRegionCount

func (hex *Hexagon) NeighborsWithRegionCount() uint

NeighborsWithRegionCount returns the number of neighbor hexagons which are assigned to a region.

func (*Hexagon) Vertex

func (hex *Hexagon) Vertex(i int) *Vec2

Vertex returns the Vec2 by index.

type HexagonGrid

type HexagonGrid struct {
	Width, Height uint
	// contains filtered or unexported fields
}

func NewHexagonGrid

func NewHexagonGrid(width, height, hexWidth, hexHeight, paddingX, paddingY uint) (grid *HexagonGrid)

func (*HexagonGrid) CanvasHeight

func (grid *HexagonGrid) CanvasHeight() uint

func (*HexagonGrid) CanvasWidth

func (grid *HexagonGrid) CanvasWidth() uint

func (*HexagonGrid) Hexagon

func (grid *HexagonGrid) Hexagon(x, y uint) *Hexagon

type Position

type Position struct {
	X, Y uint
}

func (*Position) Col

func (pos *Position) Col() uint

func (*Position) Row

func (pos *Position) Row() uint

func (*Position) SetCol

func (pos *Position) SetCol(col uint) uint

func (*Position) SetRow

func (pos *Position) SetRow(row uint) uint

type Region

type Region struct {
	// contains filtered or unexported fields
}

func NewRegion

func NewRegion() (region *Region)

func (*Region) AssignHexagon

func (region *Region) AssignHexagon(hex *Hexagon) *Region

func (*Region) AssignHexagons

func (region *Region) AssignHexagons(hexagons []*Hexagon) *Region

func (*Region) IsNeighbor

func (region *Region) IsNeighbor(other *Region) bool

func (*Region) RegionLessNeighborHexagons

func (region *Region) RegionLessNeighborHexagons() (regionLess []*Hexagon)

func (*Region) RegionSize

func (region *Region) RegionSize() int

func (*Region) ShapeHexagons

func (region *Region) ShapeHexagons() (shape []*Hexagon)

func (*Region) SingleRandomShapeHexagon

func (region *Region) SingleRandomShapeHexagon() *Hexagon

type RegionGrid

type RegionGrid struct {
	// contains filtered or unexported fields
}

func NewRegionGrid

func NewRegionGrid(width, height uint) *RegionGrid

func (*RegionGrid) Height

func (grid *RegionGrid) Height() uint

func (*RegionGrid) IsInsideGrid

func (grid *RegionGrid) IsInsideGrid(x, y uint) bool

func (*RegionGrid) Region

func (grid *RegionGrid) Region(x, y uint) *Region

func (*RegionGrid) SetRegion

func (grid *RegionGrid) SetRegion(x, y uint, region *Region) *RegionGrid

func (*RegionGrid) Width

func (grid *RegionGrid) Width() uint

type RegionGridMask

type RegionGridMask struct {
	// contains filtered or unexported fields
}

func NewRegionGridMask

func NewRegionGridMask(rand *rand.Rand, width, height, divisibilityBy uint, probabilityCreateRegionAt float64) *RegionGridMask

func (*RegionGridMask) ShouldCreateRegionAt

func (grid *RegionGridMask) ShouldCreateRegionAt(x, y uint) bool

type RegionGroup

type RegionGroup struct {
	Regions []*Region
}

func NewRegionGroup

func NewRegionGroup(maxRegionCount int) (group *RegionGroup)

func (*RegionGroup) Append

func (group *RegionGroup) Append(region *Region)

func (*RegionGroup) IsInside

func (group *RegionGroup) IsInside(region *Region) bool

func (*RegionGroup) IsOverlapping

func (group *RegionGroup) IsOverlapping(other *RegionGroup) bool

func (*RegionGroup) Merge

func (group *RegionGroup) Merge(other *RegionGroup)

type Vec2

type Vec2 struct {
	X float64 `json:"x"`
	Y float64 `json:"y"`
}

Vec2 represents a 2-dimensional point in a cartesian coordinate system.

Directories

Path Synopsis
Copyright (C) 2014-2020 Wolfger Schramm <wolfger@spearwolf.de>
Copyright (C) 2014-2020 Wolfger Schramm <wolfger@spearwolf.de>
Copyright (C) 2014-2020 Wolfger Schramm <wolfger@spearwolf.de>
Copyright (C) 2014-2020 Wolfger Schramm <wolfger@spearwolf.de>

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL