Git Product home page Git Product logo

hex-fractal-region-generator's Introduction

Hex Fractal Region Generator

The Grown Biomes method, but implemented using a hex grid instead.

Images

Steps

Bigger Area

How it works

  1. Create a square array of side length (size * 2^steps)+1. This represents a diagonally-compressed square (rhombus) that maps to the hexagonal lattice.
  2. Populate the initial values, spaced out by stride=(2^steps).
    • Care could be taken in this step to ensure that certain region types don't border each other. But in this implementation, they are just assigned randomly.
  3. Between each pair of defined values, set a new value that is randomly chosen between the two. These correspond to the midpoints of the triangular edges.
  4. Repeat #3 until every cell is assigned a value.
  5. Sample the grid using the skew transform from 2D simplex noise.
    • The first implemented sampler just finds the closest hexagon.
    • The second implemented sampler (shown in demo) considers identically-valued cells together, to straighten the edges.

Steps Step order is: Red, Orange, Yellow, Green. Rhombic section is highlighted, with the surrounding area grayed out.

Extensions

Infinite Grid

It would be straightforward to extend this to an infinite grid. Divide the grid into compressed-square / rhombic patches, that overlap on just the padding (the +1 in step 1). Maintain a cache of patches. Have the sampler identify the current patch, then load or generate it. Discard old / infrequently used patches from the cache when appropriate, as part of this step. Replace java.util.random with a hash function that always produces the same value for a given coordinate.

Higher Dimensions

It could be generalized to higher dimensions, using either the A or A* lattice as a generalization of the triangular lattice. See: Simplex or OpenSimplex noise.

Centers not edges

This approach iteratively populates the midpoints of the edges of triangles. An alternative approach could populate the centers of the triangles instead, chosen by the three corners. This is a more complex case, and would require more padding to make all necessary data available. It may also be more difficult to generalize to higher dimensions. But could be worth exploring the different properties it has, if any. The below image illustrates these steps with the same coloring as the image shown above.

Midpoint Steps

Is it better?

Is this better than the square grid approach? Hard to say. I do tend to notice hexagonal bias less readily than square bias. Hexagonal grids also have a number of nice properties, such as having more angles of symmetry, and being both the optimal packing and covering of 2D space. I like the result better than the square approach, but I think it could be improved further. Perhaps the "Centers" approach would provide even better results, or perhaps some bias control measures could be employed.

Source for hex grid image used as a base for some illustrations: https://svgsilh.com/image/156568.html

hex-fractal-region-generator's People

Contributors

kdotjpg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.