Skip to content

Simple planetary system generator written in Go. Based on the Gaussian distribution.

License

Notifications You must be signed in to change notification settings

Valkyrie00/simple-planetary-system-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple Planetary System Generator 💫

Go Report Card Go Reference License: MIT

This is a simple planetary system generator written in Go. The generated planetary systems are not realistic or based on scientific data, but they are useful for testing the game mechanics of a space game for example. The entire generator is based on the Gaussian distribution and the generate planets cluster around the center of the system.

Below you can see an example of a generated planetary system:

example-1.gif

Installation

go get github.com/Valkyrie00/simple-planetary-system-go

Usage

You can use the generator in your project by importing the package:

import sps "github.com/Valkyrie00/simple-planetary-system-go"

Then you can generate a planetary system with the following and easy steps.

First you need to define the structure of the planetary system. The structure is defined by the following parameters:

seed := int64(123456) // Alternatively you can use time.Now().UnixNano()
structure := &sps.SystemStructure{
    MinDensity:      29,    // Minimum density of planets
    DensityFactor:   3,     // Density factor of planets
    DeviationFactor: 0.4,   // Deviation Gaussian factor - Increase this value to increase the deviation of the planets
    Size:            50,    // Size of the system
    Seed:            &seed, // System Seed
}

Then you can initialize the planetary system. This step verifies that the structure is valid and generates the planets.

// Generate the system
base, err := sps.NewPlanetarySystem(structure)
if err != nil {
    fmt.Printf("Error: %v\n", err)
    os.Exit(1)
}

You can able now to generate a planetary system with a given seed and iterate over the planets:

system, _ := base.Generate()
fmt.Println("System generated with", len(system.Planets), "planets")
for _, planet := range system.Planets {
    fmt.Println(planet)
}

You can find a full example here. Remember to use a valid seed to generate the same planetary system, to build or recreate the same planetary system.

Visualize the planetary system

You can visualize the planetary system using the small web server included in the example. This visualizer is based on three.js and vite.

To generate the system you can use the generator example:

cd example/generator
go run generator.go

This will generate a planetary system in a new file called system.json under the example/viewer folder.

Then you can start the web server:

cd example/viewer
npm install
npx vite

Then open your browser at http://localhost:5173/ and you should see the planetary system.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Licenza

MIT

About

Simple planetary system generator written in Go. Based on the Gaussian distribution.

Resources

License

Stars

Watchers

Forks