spectra

command module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2026 License: MIT Imports: 1 Imported by: 0

README

Spectra is a generator of functional art

Installation

To install Spectra run following command:

go install github.com/blihor/spectra@latest

Binary file will be under $HOME/go/bin. You can run it from there or add that directory to $PATH

You can also just clone the repo and build it:

git clone https://github.com/blihor/spectra.git #or
git clone git@github.com:blihor/spectra.git
cd spectra
go build

Modes

Spectra has 2 modes for the time: lightning and terrain

Lightning

You can generate lightning using command:

spectra lightning -o <filename>

In scenario above generator for the lightning is configured based on default values. To change it behavior see config section.

Terrain

Terrain is generated by the command:

spectra terrain -o <filename>

As with lightning it is configured base on default values. If not changed it will result in a partially connected pieces of land with mountains and water. You can change the theme drastically by setting rules. With rules rightly set it can be deserts, ocean with small pieces of land, ash lands, volcanos etc.

Isocontour mode

You can also paint generated terrain in isocontour mode:

spectra terrain --isomode --levels 5 <filename>
  • --isomode flag signalizes that terrain should be painted in isocontour mode
  • --levels flag sets number of levels range of values will be split on

Flags

You can modify terrain generator by using flags:

  • --octaves or -o for number of octaves
  • --gain or -g for gain multiplier
  • --lacunarity or -l for lacunarity value
  • --scale or -s for scale of and generated image

Example of command with all flags set:

spectra terrain -o 5 -g 0.2 -l 3.5 -s 400 -o <filename>

To get better understanding of how each value will influence generation result see config section.

Wallpapers

There is an option to set generated image as wallpapers. For that you just need to omit filename:

spectra lightning 
spectra terrain

Config

Spectra will try to find config file with spectra.yaml file in following places by order:

  • $HOME/.config/spectra
  • $HOME/.spectra/
  • /etc/spectra/

Below is an example of complete config with default values:

screen:
    width: 1920
    height: 1080

lightning:
    generator:
        # Determines how close lateral branches will be to the main one
        attractionweight: 0.02

        # Probability of main segment growing beyond its default wander
        jaggedgrowthrate: 0.85

        # Multiplier of a default step for jagged segment
        jaggedstepmultiplier: 0.15

        # Multiplier of a wander for jagged segment
        jaggedwandermultiplier: 3

        # Range of angles child node on lateral branch can grow in. If parent
        # growth angle was 20 degrees than child node can grow in direction
        # between -20 to 60 degrees relatively to parent angle
        lateralwandermax: 40
        lateralwandermin: -40

        # Range of angles child node on main branch can grow in
        mainwandermax: 15
        mainwandermin: -15

        # Range of children each node can have. Final number will be decided
        # randomly in the range
        maxchildren: 3
        minchildren: 2

        # Distance between parent and child
        step: 256

        # Multiplier for the step on each lateral node generation. The further
        # lateral branch grow the shorter its segments become. It means that
        # if lateral branch consists out of 1 segment (parent node on the main
        # branch and child node on the lateral) next child will grow on a 
        # step multiplier by 0.2 from its parent (that is child node from earlier)
        stepdecay: 0.2

        # Probability of lateral branch to grow further. It will decrease with
        # each generation. For each generation final survival rate is 
        # survivalrate^(generation+1). It means that each time lateral brach
        # is trying to grow off of main one it has 0.85 chance to succeed and 
        # when it will try to grow further it will have only 0.85*0.85 chance.
        survivalrate: 0.85

    painter:
        bgcolor: '#000000'

        # Brush color. If it is an empty string then color will be picked randomly
        color: ""

        # Brush color is intensified (made closer to pure white) before painting.
        # That value determines how close it would be.
        corecolorintensityfactor: 0.5

        # Rate next lateral segment is loosing opacity with. Higher value will
        # result in a more transparent lateral branches
        lateralopacityreductionrate: 0.1

        # Rate next lateral segment is loosing thickness with.
        lateralthicknessreductionrate: 0.2

        # To make lines jagged each line is divided in half and x corrdinate
        # of mid point is being displaced then process repeats with each of the
        # halves

        # Multiplier of a random number in range [0;1] that is distance between
        # original X coordinate of the node and a new displaced one
        linedisplacementmultiplier: 3

        # Number of division of a single segment while making in jagged
        linedivisiondepth: 5

        # Brush thickness
        thickness: 5
terrain:
    generator:
        # Value that determines how scattered overall structure will be.
        # Higher value will result in a larger number of smaller clusters
        frequency: 0.3


        # Value that determines how much strength is retained by next octave.
        # Higher value will result in higher diversion of terrain clusters.
        gain: 0.4


        # Multiplier of frequency for next octave. Higher value will result in a
        # higher fluctation around the edges of adjacent clusters
        lacunarity: 3.5


        # Noise layers number combined with each other. The higher will result in
        # a higher probability of diversion occuring in each point of the map
        octaves: 5


        # Scale of the resulting map. Higher value results in a stronger zoomed
        # in effect
        scale: 400

    painter:
        # Number of level elevation map values will be split on. Higher value will
        # result in a higher number of contours with smaller area
        levels: 5

        # Set of rules for picking the color for any point of the map. Value of
        # the rule represents elevation value of the point on the map and it 
        # should be in a range [0;1] where 0 is complete bottom and 1 is highest
        # top. Point of the map considered following the rule if its value is
        # lower or equals value of the rule.
        # Rules are tested IN ORDER, so they should be provided in ASCENDING
        # ORDER of their values
        rules:
            - value: 0.1
              color: '#08101a'
            - value: 0.2
              color: '#0e2b47'
            - value: 0.3
              color: '#1d587a'
            - value: 0.4
              color: '#3482a6'
            - value: 0.45
              color: '#c2b280'
            - value: 0.55
              color: '#3f6a29'
            - value: 0.6
              color: '#284518'
            - value: 0.7
              color: '#4e4d4a'
            - value: 0.9
              color: '#7e8387'
            - value: 1
              color: '#f0f4f7'

Changing the rules can change sizes of elevation levels presented on the map. Using default colors but with different rule value we can generate ocean with small pieces of land consisted almost only out of sand:

painter:
    rules:
        - value: 0.2
          color: '#08101a'
        - value: 0.4
          color: '#0e2b47'
        - value: 0.6
          color: '#1d587a'
        - value: 0.7
          color: '#3482a6'
        - value: 0.88
          color: '#c2b280'
        - value: 0.92
          color: '#3f6a29'
        - value: 0.96
          color: '#284518'
        - value: 0.98
          color: '#4e4d4a'
        - value: 0.99
          color: '#7e8387'
        - value: 1
          color: '#f0f4f7'

Let's analyze the example. If value of the elevation map is between:

  • 0 and 0.2 then pixel will be of color '#08101a'
  • 0.2 and 0.4 then pixel will be of color '#0e2b47'
  • 0.4 and 0.6 then pixel will be of color '#1d587a' and so on

It means that land is painted if value is greater than 0.7 and for the remaining 0.3 whole 0.18 (from 0.7 to 0.88) represent sand.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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