layout

package
v0.0.0-...-c1a64fe Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package layout provides voronoi generation, the layout mechanic behind murum's images. Each region is defined as the set of points closest to a reference point. It exposes the Generate function, which creates a set of sets of image.Point s.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type L

type L struct {
	Bounds image.Rectangle
	Points map[image.Point][]image.Point
}

func Generate

func Generate(rect image.Rectangle, centerPoints []image.Point) (L, error)

Generate creates an L map, where each key is a single value from centerPoints and its corresponding value is the set of all points closest to the key. If two centerPoints have equal distance, the first point in centerPoints will be used.

type Placer

type Placer func(rect image.Rectangle, xCount int, yCount int) []image.Point

A Placer takes an image.Rectangle and calculates where best to place xCount* yCount nearestCenter points. If xCount <= 0 or yCount <= 0, the following expression should resolve to true:

len(Place(rect, xCount, yCount)) == 0

A Placer should support rectangles with negative regions

func EvenPlacer

func EvenPlacer() Placer

EvenPlacer returns a Placer that places xCount*yCount points evenly across a rectangle. If xCount or yCount <= 0, nil is returned.

func RandomPlacer

func RandomPlacer(src rand.Source) Placer

RandomPlacer returns a Placer that uses a rand.Source to randomly Place points on the passed rectangle.

func TriangularPlacer

func TriangularPlacer() Placer

TriangularPlacer creates and returns a Placer that evenly distributes points across a rectangle in a triangular pattern. When rendered with Generate, the resulting L will have hexagon-shaped sections TODO: Triangular (to create hexagonal voronoi cells)

func VariedPlacer

func VariedPlacer(varyRect image.Rectangle, src rand.Source) Placer

VariedPlacer generates a new Placer. It's based on EvenPlacer, but then moves the centered point a random amount within the varyRect (with the rectangle overlaid such that vr(0, 0) is aligned to the centered point).

varyRect.Min.X <= randomXVariance < varyRect.Max.X
varyRect.Min.Y <= randomYVariance < varyRect.Max.Y

func WeightedPlacer

func WeightedPlacer(center image.Point, gravity float64) Placer

WeightedPlacer creates and returns a Placer that pushes/pulls points to/from a given center point. It is based on the EvenPlacer, and then moves points to create the gravitational effect.

center : Where to apply the gravity from.
gravity: How strong the effect is.
          +ve: Points are pulled towards center;
          -ve: Points are pushed away from center

TODO: Weighted (place more points closer to a given point, and fewer further away. Or vice versa)

Jump to

Keyboard shortcuts

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