Silk is a utility for creative uses of wave function collapse.

  • By Split-Cube Studios
  • Last update: Oct 8, 2022
  • Comments: 0

Go Reference SCS - Engineering

Silk

Silk is an N-dimensional implementation of the wave function collapse algorithm. This utility was largely inspired by the work of Maxim Gumin and his WaveFunctionCollapse repository.

Silk aims not only to provide a flexible implementation of the algorithm, but also provide out-of-the-box for some common data types/use-cases. Currently Silk only supports generating 2D images, but a user is able to implement their own silk.Shuttle for other data types/dimensions.

Silk CLI

Silk comes with a CLI that can use the provided silk.Shuttle implementations to generate outputs. The CLI can be installed with:

go install github.com/split-cube-studios/silk/cmd/silk

Below is the output of silk help:

NAME:
   silk - Generate procedural data with wave function collapse.

USAGE:
   silk [global options] command [command options] [arguments...]

COMMANDS:
   image    Generate an image.
   help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --help, -h    show help (default: false)
   --seed value  Seed value for the random number generator. (default: 1665169812)

Silk uses subcommands for different datatypes, which each may have different flags. See silk help <command> for more information.

Silk API

Silk can also be used as a library. The silk package provides the core functionality of the algorithm, while the silk/pkg/shuttle package provides some common implementations of the silk.Shuttle interface.

Below is an example of using Silk to generate a 2D image:

package main

import (
    "image"
    "image/color"
    "image/png"
    "os"

    "github.com/split-cube-studios/silk"
    "github.com/split-cube-studios/silk/pkg/shuttle"
)

func main() {

    f, err := os.Open("input.png")
    if err != nil {
        panic(err)
    }
    defer f.Close()

    img, _, err := image.Decode(f)
    if err != nil {
        panic(err)
    }
    
    size := 128
    loom := silk.NewLoom(
        []int{size, size},
        shuttle.NewImageShuttle(
            img,
            shuttle.ImageShuttleOptions{
				W: size,
				H: size,
			},
        ),
    )

    if err := loom.Weave(); err != nil {
        panic(err)
    }
}

Samples

Command Input Output (Progression) Output (Final)
silk image --input ./samples/lines.png -a -r xy Input Output Output
silk image --input ./samples/island.png -a -r x Input Output Output

Contributing

Contributions are welcome! Contribution guides are coming soon.

Download

silk.zip