gah

package module
v0.0.0-...-10f459e Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2022 License: MIT Imports: 17 Imported by: 0

README

GAH

Generative art helpers, written in GO.

All coordinate systems use the common graphics axes (unless otherwise specified):

O-->X
|
v
Y

Expect major breaking changes.

TODOs

  • ColorRamp2D
  • different interpolation functions for mix and colorramp
  • deduplicate noise layering loops
  • properly domainwarping noise

Documentation

Index

Constants

View Source
const QuadTreeLeafThreshold = 10

QuadTreeLeafThreshold defines the maximum amount of points allowed in a QuadTree leafnode before it is split

Variables

View Source
var (
	// MB64E provides a modified encoding of base64 that should work even in urls and filenames
	MB64E = base64.NewEncoding("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-")
)

Functions

func Clamp

func Clamp(inNum float64, inMin float64, inMax float64) float64

Clamp returns a number inside [inMin, inMax]

func DrawQuadTree

func DrawQuadTree(dc *gg.Context, tree *QuadTree)

DEBUG REMOVE

func DrawSeedBarCode1

func DrawSeedBarCode1(dc *gg.Context, data uint64, x float64, y float64, w float64, h float64, ax float64, ay float64)

DrawSeedBarCode1 draws a SBC1 in the RM4SCC style at the desired location calculated as following:

anchor point is `x - w * ax`, `y - h * ay`

use `ax=0.5`, `ay=0.5` to center to a point and both at zero so the code is drawn to the bottom right of the anchor

for best resolution use w in multiples of 112 and h in multiples of 3

func Float64ToBytes

func Float64ToBytes(f float64) []byte

Float64ToBytes returns a byte slice representing the input

func Hash64

func Hash64(s string) uint64

Hash64 returns a uint64 hash of the input string

func ImageToRGBA

func ImageToRGBA(src image.Image) *image.RGBA

ImageToRGBA converts an image to an RGBA image, hopefully using a lower level go construct for better performance ripped straight from fogleman/gg

func ImgFastSaveToPNG

func ImgFastSaveToPNG(img image.Image, path string) error

ImgFastSaveToPNG skips png compression for much faster saving speed at the cost of more memory

func ImgGet

func ImgGet(img image.Image, x, y int) float64

ImgGet returns a [0, 1] grayscale value representing the color on the given image at the given coordinates

func ImgGetRGBA

func ImgGetRGBA(img image.Image, x, y int) (r, g, b, a int)

ImgGetRGBA returns the rgba components of the color on the given image at the given coordinates

func IntToBytes

func IntToBytes(i int) []byte

IntToBytes returns a byte slice representing the input

func MixF

func MixF(val1 float64, val2 float64, ratio2 float64) float64

MixF mixes the provided values together using the given ratio for val2

func MixI

func MixI(val1 int, val2 int, ratio2 float64) int

MixI works as MixF does but on integers

func RGBMix

func RGBMix(color1 color.RGBA, color2 color.RGBA, ratio2 float64, maxAlpha bool) color.RGBA

RGBMix linearly interpolates between the two given colors, alpha may be maxed to 0xFF to prevent decay

func ScaleF2F

func ScaleF2F(inNum float64, inMin float64, inMax float64, outMin float64, outMax float64) float64

ScaleF2F returns a number in the interval [outMin, outMax] that is percentage-wise as much removed from each end of the interval as inNum in [inMin, inMax]

func ScaleF2I

func ScaleF2I(inNum float64, inMin float64, inMax float64, outMin int, outMax int) int

ScaleF2I returns a number in the interval [outMin, outMax] that is percentage-wise as much removed from each end of the interval as inNum in [inMin, inMax]

func ScaleI2F

func ScaleI2F(inNum int, inMin int, inMax int, outMin float64, outMax float64) float64

ScaleI2F returns a number in the interval [outMin, outMax] that is percentage-wise as much removed from each end of the interval as inNum in [inMin, inMax]

func ScaleI2I

func ScaleI2I(inNum int, inMin int, inMax int, outMin int, outMax int) int

ScaleI2I returns a number in the interval [outMin, outMax] that is percentage-wise as much removed from each end of the interval as inNum in [inMin, inMax]

Types

type CoherentNoise

type CoherentNoise struct {
	Noise       opensimplex.Noise // open simplex noise generator
	Scale       float64           // number that determines at what distance to view the noisemap, smaller is closer
	Octaves     int               // the number of levels of detail you want you perlin noise to have, higher gives more possible detail
	Lacunarity  float64           // number that determines how much detail is added or removed at each octave (adjusts frequency), higher gives less blending of octaves
	Persistence float64           // number that determines how much each octave contributes to the overall shape (adjusts amplitude), higher makes rougher
}

CoherentNoise provides automatic layering of opensimplex noise using parameters

func NewCoherentNoise

func NewCoherentNoise(seed int64, scale float64, octaves int, lacunarity float64, persistence float64) *CoherentNoise

NewCoherentNoise returns a CoherentNoise structure with the given parameters

func (*CoherentNoise) Eval1

func (cnoise *CoherentNoise) Eval1(x float64) float64

eval1 works as Eval1 does on opensimplex.noise but applies layering through the CoherentNoise parameters

func (*CoherentNoise) Eval2

func (cnoise *CoherentNoise) Eval2(x, y float64) float64

eval2 works as Eval2 does on opensimplex.noise but applies layering through the CoherentNoise parameters

func (*CoherentNoise) Eval3

func (cnoise *CoherentNoise) Eval3(x, y, z float64) float64

eval3 works as Eval3 does on opensimplex.noise but applies layering through the CoherentNoise parameters

func (*CoherentNoise) Eval4

func (cnoise *CoherentNoise) Eval4(x, y, z, w float64) float64

eval4 works as Eval4 does on opensimplex.noise but applies layering through the CoherentNoise parameters

func (*CoherentNoise) GetEvalRange

func (cnoise *CoherentNoise) GetEvalRange() (outMin float64, outMax float64)

GetEvalRange returns the min and max values that can be expected from the Eval2

func (*CoherentNoise) GetParamSignature

func (cnoise *CoherentNoise) GetParamSignature() (signature []byte)

GetParamSignature returns a byte slice containing all relevant unique parameters

type ColorRamp

type ColorRamp struct {
	GradientStops []ColorStop // must be sorted
}

ColorRamp holds multiple colorstops between which can be interpolated use Sort to order them by their position

func (*ColorRamp) Sample

func (cr *ColorRamp) Sample(position float64) color.RGBA

Sample returns the value on the ColorRamp gradient that is calculated at the given position interpolates linearly between the given color stops using this on a ColorRamp with unsorted stops may break

func (*ColorRamp) Sort

func (cr *ColorRamp) Sort()

Sort sorts the ColorStops of a ColorRamp by their position so Sample does not break

type ColorStop

type ColorStop struct {
	Position float64 // in range [0, 1]
	Color    color.RGBA
}

ColorStop defines the position at which a color is strongest in the ColorRamp

type QuadTree

type QuadTree struct {
	// contains filtered or unexported fields
}

QuadTree is a typical 2D QuadTree containing points

func NewQuadTree

func NewQuadTree(x float64, y float64, w float64, h float64) (qt *QuadTree)

NewQuadTree creates a new QuadTree with the given dimensions

func (*QuadTree) Contains

func (qt *QuadTree) Contains(p Vec2f) (bool, quadTreeQuadrant)

func (*QuadTree) GetPoints

func (qt *QuadTree) GetPoints() (results []Vec2f)

TODO make this iterative

func (*QuadTree) InsertPoint

func (qt *QuadTree) InsertPoint(p Vec2f)

InsertPoint inserts the given point into the QuadTree, branching the tree where necessary TODO make this iterative

func (*QuadTree) InsertPoints

func (qt *QuadTree) InsertPoints(p []Vec2f)

InsertPoints inserts the given points into the QuadTree, branching the tree where necessary

func (*QuadTree) Intersects

func (qt *QuadTree) Intersects(x float64, y float64, w float64, h float64) bool

func (*QuadTree) QueryKNN

func (qt *QuadTree) QueryKNN(p Vec2f, k int) []Vec2f

QueryKNN returns the k nearest neighbors to the given point p TODO make this iterative

func (*QuadTree) QueryRange

func (qt *QuadTree) QueryRange(x float64, y float64, w float64, h float64) (results []Vec2f)

QueryRange returns all leaf points of QuadTree inside the given region TODO make this iterative

func (*QuadTree) SignedDistanceToPoint

func (qt *QuadTree) SignedDistanceToPoint(p Vec2f) float64

SignedDistanceToPoint returns a relative distance value from p to the QuadTrees bounding box returns >0 if outside the box, <0 if inside, and 0 when exactly on the line

type TextureCachable

type TextureCachable interface {
	GetParamSignature() (signature []byte)
	GetEvalRange() (outMin float64, outMax float64)
	Eval2(x float64, y float64) float64
}

TextureCachable signifies a texture that can be precomputed and cached for later use

type TextureCache

type TextureCache struct {
	// contains filtered or unexported fields
}

TextureCache represents a cached texture

func NewTextureCache

func NewTextureCache(provider TextureCachable, x int, y int, w int, h int, path string) *TextureCache

NewTextureCache returns a new cached texture provider, path should only be a directory specification (including the trailing '/') this method will block and pre-generate the whole texture

func (*TextureCache) Sample

func (tc *TextureCache) Sample(x int, y int) float64

Sample returns the grayscale value [0, 1] at the given position in the cached texture

type Vec2f

type Vec2f struct {
	X, Y float64
}

Vec2f is a simple 2D float vector

type Vec2i

type Vec2i struct {
	X, Y int
}

Vec2i is a simple 2D int vector

type VoronoiDiagram2D

type VoronoiDiagram2D struct {
	Seed       uint64
	X, Y, W, H float64
	Points     []Vec2f
	Scale      float64
	K          int
	PdsTrys    int
}

VoronoiDiagram2D represents a 2D voronoi diagram

func NewVoronoiDiagram2D

func NewVoronoiDiagram2D(seed uint64, x float64, y float64, w float64, h float64, scale float64, k int, pdsTrys int) *VoronoiDiagram2D

NewVoronoiDiagram2D creates a new voronoi diagram, with points spaced to have a minimum distance given by the scale if k is -1 then crackle will be used instead of k nearest neighbor, i.e. return distance to nearest edge

func (*VoronoiDiagram2D) Eval2

func (vd *VoronoiDiagram2D) Eval2(x, y float64) float64

Eval2 returns the distance to the k nearest neighbor returns within range [0, 1]; or 0 for out of bounds; 1 is closest to a point

func (*VoronoiDiagram2D) GetEvalRange

func (vd *VoronoiDiagram2D) GetEvalRange() (outMin float64, outMax float64)

GetEvalRange returns the min and max values that can be expected from the Eval2

func (*VoronoiDiagram2D) GetParamSignature

func (vd *VoronoiDiagram2D) GetParamSignature() (signature []byte)

GetParamSignature returns a byte slice containing all relevant unique parameters

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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