Giter Site home page Giter Site logo

redblobgames / 1843-planet-generation Goto Github PK

View Code? Open in Web Editor NEW
133.0 13.0 19.0 50 KB

One week experiment: learn how to procedurally generate maps on a sphere. Code is messy but it runs.

Home Page: https://www.redblobgames.com/x/1843-planet-generation/

License: Apache License 2.0

JavaScript 96.69% HTML 3.03% Shell 0.28%
procedural-map-generator maps spheres delaunay voronoi

1843-planet-generation's Introduction

http://unmaintained.tech/badge.svg

This was a 9 day (2.5hr/day) experiment to learn how to procedurally generate maps on a sphere. I hadn’t worked with this type of sphere geometry before and wanted to learn.

Geometry

Writeup - Fibonacci points, Delaunay triangles, Voronoi regions

https://www.redblobgames.com/x/1842-delaunay-voronoi-sphere/blog/fibonacci-sphere-voronoi.png

Maps

Writeup - tectonic plates, mountains, oceans, biomes, rivers, rendering

https://www.redblobgames.com/x/1843-planet-generation/blog/continent-boundaries-5-small.jpg

https://www.redblobgames.com/x/1843-planet-generation/blog/planet-12-small.jpg

Installation

To build, run ./build.sh . Then visit embed.html . ]

1843-planet-generation's People

Contributors

redblobgames avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

1843-planet-generation's Issues

Help and brainstorm

  1. I find the hills a bit boring. The kind of go up and come down at +/- same rate, and look like stars on lower regions count. Overall they look not so nice. How I could spice it up by not killing performance and load times?

  2. My drawing engine is a bit limited, I can do only triangles (connect 3 verts etc). What would you advice in this situation, to draw an evaluated map (not flat veronoi)

Info - Keep latlong with triangle data

I see the latlong is generated, converted to cartesian and then to stereographic.

How should I link and retain the triangle vertex latlong data?

I want to pair this with topojson for interaction.

Field assign function

Hi! I could not make sense of some of function you wrote, so i did my version. What it does, is, for example takes mountain 1 and assign distances on its neighbors, than for next mountain etc. When all mountains are iterated, it goes trough again, but assigns neighbor neighbors, etc., until all is assigned. In simple words it kind of radiates the fields out for the seed 1 by 1. What do you think? Seems to work, but results are different.

/* Distance from any point in seeds_r to all other points, but 
 * don't go past any point in stop_r */
function assignDistanceField(mesh, seeds_r, stop_r) {
    const randInt = makeRandInt(SEED);
    let {numRegions} = mesh;
    let r_distance = new Float32Array(numRegions);
    r_distance.fill(Infinity);
    
    let queue = [];
    for (let r of seeds_r) {
        queue.push(r);
        r_distance[r] = 0;
    }


    let r_field = [];
    var i = 0;

    while(queue.length > 0){

        if(r_field[i] === undefined){
            r_field[i] = [queue[i]];
        }

        let new_r_field = [];

        for (let n = 0; n < r_field[i].length; n++) {
            let current_r = r_field[i][n];
            let neighbor_rs = mesh.r_circulate_r([], current_r);            

            for (let neighbor_r of neighbor_rs) {
                if (!stop_r.has(neighbor_r)){
                    let new_r_distance = r_distance[current_r] + 1;

                    if (r_distance[neighbor_r] === Infinity) {
                        r_distance[neighbor_r] = new_r_distance;  
                        new_r_field.push(neighbor_r);
                    }else if(new_r_distance < r_distance[neighbor_r]){
                        r_distance[neighbor_r] = new_r_distance;
                    }
                }                
            }
        }        

        r_field[i] = new_r_field;

        if(r_field[i].length === 0){
            queue.splice(i, 1);
            r_field.splice(i, 1);
        }

        i++;

        if(i >= queue.length){ // shuffle
            i = 0;
        }
    }
    

    /*let out_r = [];
    for (let queue_out = 0; queue_out < mesh.numRegions; queue_out++) {
        let pos = queue_out + randInt(queue.length - queue_out);
        let current_r = queue[pos];
        queue[pos] = queue[queue_out];
        mesh.r_circulate_r(out_r, current_r);
        for (let neighbor_r of out_r) {
            if (r_distance[neighbor_r] === Infinity && !stop_r.has(neighbor_r)) {
                r_distance[neighbor_r] = r_distance[current_r] + 1;
                queue.push(neighbor_r);
            }
        }
    }*/

    return r_distance;
    // TODO: possible enhancement: keep track of which seed is closest
    // to this point, so that we can assign variable mountain/ocean
    // elevation to each seed instead of them always being +1/-1
}

You're amazing

This looks amazing. Haven't tried the code, but the snapshots are beautiful! Good job!

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.