texture

package module
v0.0.0-...-576f627 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

README

Texture Generation

Go Reference Go Report Card Build Status Ask DeepWiki

A package for the procedural generation of textures. Based on the ideas contained in the Bryce 3D deep texture editor.

example

More examples here, here and here.

The primary interfaces allow for the evaluation of a value, vector or color field at any point in the XY plane.

A subpackage covers the generation of surfaces based on lights illuminating a material.

Documentation

Overview

Package texture contains functions that can be combined to create image textures.

0. Getting Started

Here's a simple example that creates a Perlin value field and renders it to an image:

f := texture.NewPerlin(12345)
// Create a 600x600 image containing a field rendered from 0,0 in 0.075 steps
img := texture.NewTextureGray16(600, 600, f, 0, 0, 0.075, 0.075, false)

1. Fields

Fields are interfaces that support returning a value for any given point in the field.

Three types of texture field are supported:

  1. Field (F) which maintains a field of float64, in the range [-1,1]
  2. VectorField (VF) which maintains a field of slice of float64, typically a triplet
  3. ColorField (CF) which maintains a field of image/color.Color

All fields provide an Eval2(x, y float64) function which takes any x and y and returns either a value, vector or color. If a field type doesn't support the entire 2D plane, then it must return 0, {0, ..., 0}, or image/color.Black for values of x and y not supported.

2. Texture

A texture is a tree made up of field nodes and leaves.

A field is considered a leaf if it is not dependent on any other fields. Examples of leaves are the gradient fields LinearGradient, RadialGradient and ConicGradient.

Any field that relies on another field or fields is considered a node. Examples of nodes are the filter fields like AbsFilter, ClipFilter and InvertFilter. All of these require at least one source field in order to operate.

Textures are built from the leaves upward until a root node has been created. This node can then be passed to a function that will realize it, such as NewTextureRGBA which generates an image.RGBA by repeatedly calling the root's ColorField Eval2 function for each image pixel.

3. Leaves - 1D

1D leaves vary only in one dimension, typically x.

Different rotations, scalings and offsets can be obtained using Transform.

3.1 Uniform (F,VF,CF)

As the name suggests, these return a single value independent of the location within the field.

3.2 LinearGradient (F)

This field defines a gradient going from left to right using a Wave starting at 0 and repeating as a function of the wave's wave length (lambda).

4. Leaves - 2D

2D leaves vary in x and y.

Different rotations, scalings and offsets can be obtained using Transform.

4.1 Chequered (F)

A collection of leaves for generating triangles, squares and hexagonal chequer boards. The size of the cells is determined by the scale value.

The triangle and square boards are colored -1 and 1, whereas the hexagonal board is colored -1, 0 and 1.

4.2 ConicGradient (F)

This field defines a gradient that rotates around {0,0} using a Wave starting at 0 and mapping x to theta / (2 * Pi).

4.3 Image (CF)

The image field uses the underlying image to figure the color value to return for any given location. Supported interpolations are NearestInterp, LinearInterp, CubicInterp, P3Interp and P5Interp.

4.4 Perlin (F)

This field provides Perlin noise (aka gradient noise) using the supplied seed. The field repeats over [256,256]. See Perlin93.

4.5 RadialGradient (F)

This field defines a gradient that extends from {0,0} using a Wave starting at 0 and mapping to the absolute distance from {0,0}.

4.6 Shape (F)

This field is defined by a graphics2d.Shape. Locations within the shape return 1 and all others -1.

4.7 Experimental (F)

Like the heading says, these are 2D field generator experiments, your mileage may vary.

4.8 Third Party Generators (F)

5. Nodes - Filters

5.1 Value Filters (F)

Filters are nodes that do something with the value supplied by their source. They map values in [-1,1] to another in [-1,1]. Some filters take A and B parameters, in which case the value filtered is A*value+B

5.2 Vector Filters (VF)

  • UnitVector modifies the magnitude of the vector to 1

5.3 Color Filters (CF)

6. Nodes - Combiners

The expressive range of the texture package is due to the ability to combine multiple source fields together using some heuristic.

6.1 Value Combiners (F)

6.2 Vector Combiners (VF)

6.3 Color Combiners (CF)

  • ColorBlend src1 and src2 are blended according to the value in src3 (F)
  • ColorSubstitute src1 if src3 < A or src3 > B, otherwise src2 (src3 is F)
  • ShapeCombinerCF src1 if location inside of shape, src2 otherwise

7. Nodes - Converters

Convert between F, VF and CF fields

  • ColorToGray maps color to [-1,1] via [color.Gray16Model]
  • ColorSelect maps one of R, G, B or A channels to [-1,1]
  • Direction takes the direction of a vector based on it's first two values and maps it to [-1,1]
  • Magnitude takes the magnitude of a vector (scaled and clamped to [-1,1])
  • Select takes the selected channel of a vector (scaled and clamped to [-1,1])
  • Weighted takes the weighted sum of a vector and clamps it to [-1,1]
  • VectorFields takes a slice of fields and creates a vector field
  • VectorColor - takes the four channels of a color field and maps them to a vector field
  • Normal - converts a field to a vector field of normals using the finite distance method
  • ColorGray maps [-1,1] to [Black,White] image/color.Gray16 values
  • ColorSinCos uses one of six modes to convert [-1,1] to color using math.Sin and math.Cos
  • ColorConv uses a color interpolator to map [-1,1] to color
  • ColorFields uses 4 sources [-1,1], one each for R, G, B, A or H, S, L, A colors
  • ColorVector uses VF triplets to map to either RGB or HSL colors (A is opaque)

8. Nodes - Transformers

Transformers affect the value of x and y used when a field's Evals method is called. They map (x, y) to (x', y').

8.1 Transform (F,VF,CF)

This transformer applies an affine transform graphics2d.Aff3 to input coordinates allowing for translations, rotations, scalings and shearings. When something other than a gradient in x is required, the affine transform can be used to move, scale and rotate it to the desired location.

8.2 Tiler (F,VF,CF)

Tiler transforms allow finite areas to be replicated across the infinite plane. Useful for creating repeating patterns and images.

8.3 Reflect (F,VF,CF)

The relection transforms take a line defined by two points as the location of a mirror. Points on the positive side of the line remain unchanged while those on the negative are remapped.

8.4 Warp (F,VF,CF)

The warp transforms provide generalized image warping functionality not provided by the preceding. They rely on a function WarpFunc to map points from one domain to the other.

8.5 Displace (F,VF,CF)

The displace transforms use two fields to perturb the location returned from a third field. The degree of perturbation is controlled by a scaling factor. The second version of each transform allows a generalized affine transform to be supplied rather than just a fixed scaling.

8.6 Distort (F)

Distort provides a self referential transform that samples the field three times, once each for the x and y displacements and once with the new x' and y'.

8.7 Pixelate (F,VF,CF)

These transforms apply a resolution filter to x and y. Note that pixelate does not perform true pixelation in terms of averaging values over the desired resolution.

8.8 Strip (F,VF,CF)

These transforms replace y with a fixed value when performing Eval2(x, y). Strip also implements the Wave interface and can be used in gradient leaves.

9. Nodes - Fractal

Three type of fractal nodel are available, Fractal, VariableFractal and IFS.

9.1 Fractal and VariableFractal (F)

Fractal nodes are a combination of both combiner and transformer nodes. Each location is evaluated for each octave, with an affine transform being applied between evaluations to x and y, and the resulting values then combined using an OctaveCombiner.

Two OctaveCombiner are provided

  • FBM from supplied Hurst and Lacunarity values
  • MF from supplied Hurst, Lacunarity and offset valaues

9.2 IFS (F)

IFS, or Iterated Fractal Systems Barnsley88, take a series of contractive affine transformations and apply them repeatedely to some depth (akin to octaves above).

10. Wave

Any type that implements Wave can be used to drive a gradient field. This interface defines two methods - Eval(x float64) which returns a value in [-1, 1], and Lambda() which returns the wave length of the wave.

Three types are defined as starting points and allow a variety of waveforms to be generated:

  1. NLWave multiple wave shapes with varying wave lengths
  2. DCWave one wave shape for the rising edge and one for the falling edge
  3. ACWave a wave shape per quadrant
  4. InvertWave takes a wave and inverts it

All of them utilize the non-linear functions provided in graphics2d. For convenience these are wrapped in NonLinear, primarily so that the output is mapped from [0,1] to [-1,1], and so that the slope name can be captured for JSON marshalling.

10.1 NLWave

NLWave takes a slice of wave lengths and a slice of slopes, together with flags that indicate if slopes should be mirrored, and whether only a single cycle shold be generated.

10.2 DCWave

DCWave takes a slice of one or two wave lengths and a slice of one or two slopes, together with a flag that indicate if only a single cycle shold be generated.

If only one wave length is provided, then it is used for both the rising and falling halves of the wave. If only one slope type is provided, then it is used for both the rising and falling halves of the wave. Hence, providing only one wave length and slope type is equivalent to mirroring.

When once is set, values less than 0 or greater than the wave length are returned as -1.

10.3 ACWave

ACWave takes a slice of one, two or four wave lengths and a slice of one, two or four slopes, together with a flag that indicate if only a single cycle shold be generated. Note this waveform starts at 0, unlike the other two which both start at -1.

If only one wave length is provided, then it is used for all quadrants of the wave. If only one slope type is provided, then it is used for all quadrants of the wave. If only two wave lengths are provided, then they are used for both halves of the wave. If only two slope types are provided, then they are used for both halves of the wave.

When once is set, values less than 0 or greater than the wave length are returned as 0.

11. Utilities

11.1 Realization

Textures are realized by calling the root node's Eval2(x, y) method. Image wrappers are provided that perform this step lazily and in a cacheable fashion. The wrapper is responsible for defining the image bounds, the texture offset and step values. These images can then be passed to image/draw.Draw, graphics2d.RenderShape or to graphics2d.NewFilledPen as source images.

Caching determines whether a value is evaluated once and cached, or always evaluated. If a particular texture subgraph is expensive to compute, it may be better to evaluate it's domain once and cache it in an image that can then be referenced through an Image node.

11.2 Gradients

The 2D graphics packages in other languages, such as Java and SVG, have a notion of a gradient fill or paint. Go, however, doesn't since it's golang.org/x/image/vector.Draw takes an image. To address this texture has some utility functions that use simple gradient textures to create the same effect.

The gradients are all value fields and mapped to either image/color.Gray16 or image/color.RGBA. In the latter case, by using github.com/jphsd/graphics2d/image.Colorizer.

12. Package Examples

Example (Decay)
package main

import (
	"fmt"
	"github.com/jphsd/graphics2d/image"
	"github.com/jphsd/texture"
)

func main() {
	// Original waveform
	nl := texture.NewNLSin()
	w := texture.NewNLWave([]float64{62}, []*texture.NonLinear{nl}, true, false)
	w1 := texture.NewInvertWave(w)
	f := texture.NewLinearGradient(w1)

	// Decay factor
	nl2 := texture.NewNLLinear()
	w2 := texture.NewNLWave([]float64{600}, []*texture.NonLinear{nl2}, false, false)
	w3 := texture.NewInvertWave(w2)
	f2 := texture.NewLinearGradient(w3)

	// Remap [-1,1] => [0,1]
	f4 := texture.NewRemapFilter(f2, 0, 1)

	// Combine waves to get decay waveform
	f3 := texture.NewMulCombiner(f, f4)

	img := texture.NewTextureGray16(600, 600, f3, 0, 0, 1, 1, false)
	image.SaveImage(img, "Example_decay")
	fmt.Printf("Generated Example_decay")
}
Output:
Generated Example_decay
Example (Flames)
package main

import (
	"fmt"
	"github.com/jphsd/graphics2d"
	"github.com/jphsd/graphics2d/image"
	"github.com/jphsd/texture"
	"image/color"
)

func main() {
	f := texture.NewPerlin(12345)

	fx := texture.NewPerlin(12346)

	fy := texture.NewPerlin(12347)

	f2 := texture.NewDisplace(f, fx, fy, 1)

	xfm := graphics2d.Scale(1, 0.3)
	f3 := texture.NewTransform(f2, xfm)

	img := texture.NewTextureGray16(600, 600, f3, 0, 0, .015, .015, false)
	// Colorize it
	c1, c2 := color.RGBA{0x19, 0, 0, 0xff}, color.RGBA{0xff, 0xff, 0x85, 0xff}
	stops := []int{
		64,
		128,
		160,
		250,
	}
	colors := []color.Color{
		color.RGBA{0x76, 0, 0, 0xff},
		color.RGBA{0xff, 0, 0, 0xff},
		color.RGBA{0xff, 0x7c, 0, 0xff},
		color.RGBA{0xff, 0xff, 0x7a, 0xff},
	}
	img2 := image.NewColorizer(img, c1, c2, stops, colors, false)
	image.SaveImage(img2, "Example_flames")
	fmt.Printf("Generated Example_flames")
}
Output:
Generated Example_flames

Index

Examples

Constants

This section is empty.

Variables

View Source
var DefaultNormal = &UniformVF{"UniformVF", []float64{0, 0, 1}}

DefaultNormal describes the unit normal point straight up from the XY plane.

Functions

func ColorRGBABiLerp

func ColorRGBABiLerp(u, v float64, colors []color.Color) color.RGBA

ColorRGBABiLerp calculates the color value at u, v [0,1] given colors at [0,0], [1,0], [0,1], [1,1] in RGB space.

func Cubic

func Cubic(t float64, p []float64) float64

Cubic calculates the value of f(t) for t in range [0,1] given the values of t at -1, 0, 1, 2 in p[] fitted to a cubic polynomial: f(t) = at^3 + bt^2 + ct + d. (From graphics2d/util/nlerp.go and https://www.paulinternet.nl/?page=bicubic)

func Linear

func Linear(t float64, p []float64) float64

Linear calculates the value of f(t) for t in range [0,1] given the values of t at -1, 0, 1, 2 in p[] using linear interpolation.

func MapValueToLambda

func MapValueToLambda(v, lambda float64) (int, float64)

func Nearest

func Nearest(t float64, p []float64) float64

Nearest calculates the value of f(t) for t in range [0,1] given the values of t at -1, 0, 1, 2 in p[] using the closest value to t.

func NewConicRGBA

func NewConicRGBA(w, h int, c []float64, th float64, c1, c2 color.Color, wf *NonLinear) *image.Colorizer

func NewEllipticalRGBA

func NewEllipticalRGBA(w, h int, c []float64, rx, ry, th float64, c1, c2 color.Color, wf *NonLinear, mirror, once bool) *image.Colorizer

func NewLinearRGBA

func NewLinearRGBA(w, h int, p1, p2 []float64, c1, c2 color.Color, wf *NonLinear, mirror, once bool) *image.Colorizer

func NewRadialRGBA

func NewRadialRGBA(w, h int, c []float64, r float64, c1, c2 color.Color, wf *NonLinear, mirror, once bool) *image.Colorizer

func P3

func P3(t float64, p []float64) float64

P3 calculates the value of f(t) for t in range [0,1] given the values of t at -1, 0, 1, 2 in p[] uses a cubic s-curve

func P5

func P5(t float64, p []float64) float64

P5 calculates the value of f(t) for t in range [0,1] given the values of t at -1, 0, 1, 2 in p[] uses a quintic s-curve

func SaveJSON

func SaveJSON(v any, name string) error

func X3Support

func X3Support(sx, sy float64) [][]float64

func Z4Support

func Z4Support(sx, sy float64) [][]float64

func Z8Support

func Z8Support(sx, sy float64) [][]float64

Types

type ACWave

type ACWave struct {
	Name      string
	Lambdas   [4]float64
	CumLambda [4]float64
	NLFs      [4]*NonLinear
	Once      bool
}

func NewACWave

func NewACWave(lambdas []float64, nlfs []*NonLinear, once bool) *ACWave

func (*ACWave) Eval

func (g *ACWave) Eval(v float64) float64

func (*ACWave) Lambda

func (g *ACWave) Lambda() float64

type AbsFilter

type AbsFilter struct {
	Name string
	Src  Field
	A, B float64
}

Abs returns Abs(At+B) (clamped).

func NewAbsFilter

func NewAbsFilter(src Field, a, b float64) *AbsFilter

func (*AbsFilter) Eval2

func (f *AbsFilter) Eval2(x, y float64) float64

Eval2 implements the Field interface.

type AddCombiner

type AddCombiner struct {
	Name string
	Src1 Field
	Src2 Field
	Offs float64
	Scal float64
}

AddCombiner is an adding combiner (clamped).

func NewAddCombiner

func NewAddCombiner(src1, src2 Field) *AddCombiner

func (*AddCombiner) Eval2

func (c *AddCombiner) Eval2(x, y float64) float64

Eval2 implements the Field interface.

type AvgCombiner

type AvgCombiner struct {
	Name string
	Src1 Field
	Src2 Field
}

AvgCombiner is an averaging combiner.

func NewAvgCombiner

func NewAvgCombiner(src1, src2 Field) *AvgCombiner

func (*AvgCombiner) Eval2

func (c *AvgCombiner) Eval2(x, y float64) float64

Eval2 implements the Field interface.

type Binary

type Binary struct {
	Name string
	Seed int64
	Perc float64
	// contains filtered or unexported fields
}

func NewBinary

func NewBinary(width, height int, seed int64, perc float64) *Binary

func (*Binary) Eval2

func (b *Binary) Eval2(x, y float64) float64

type Blend

type Blend struct {
	Name string
	Src1 Field
	Src2 Field
	Src3 Field
}
Example
package main

import (
	"fmt"
	"github.com/jphsd/graphics2d/image"
	"github.com/jphsd/texture"
)

func main() {
	f := texture.NewHexagons(20)

	f2 := texture.NewSquares(40)

	nl := texture.NewNLLinear()
	w := texture.NewNLWave([]float64{600}, []*texture.NonLinear{nl}, false, false)
	f3 := texture.NewLinearGradient(w)

	f4 := texture.NewBlend(f, f2, f3)

	img := texture.NewTextureGray16(600, 600, f4, 0, 0, 1, 1, false)
	image.SaveImage(img, "ExampleBlend")
	fmt.Printf("Generated ExampleBlend")
}
Output:
Generated ExampleBlend

func NewBlend

func NewBlend(src1, src2, src3 Field) *Blend

func (*Blend) Eval2

func (b *Blend) Eval2(x, y float64) float64

Eval2 implements the Field interface.

type BlinnField

type BlinnField struct {
	Name   string
	Points [][]float64
	A      []float64
	B      []float64
	D      func([]float64, []float64) float64
	F      func(float64) float64
	Scale  float64
	Offset float64
}

BlinnField implements the ideas from Blinn's 1982 paper, A Generalization of Algebraic Surface Drawing. In Blinn's paper, D() is the distance squared, F() is the exponential function and the values of A and B are determined from the desired metaball radius and blobiness.

func NewBlinnField

func NewBlinnField(points [][]float64, a, b []float64,
	d func([]float64, []float64) float64, f func(float64) float64,
	scale, offset float64) *BlinnField

func (*BlinnField) Eval2

func (pf *BlinnField) Eval2(x, y float64) float64

Eval2 implements the Field interface.

type BlockNoise

type BlockNoise struct {
	Name   string
	Domain []float64
	Rows   int
	Cols   int
	Seed   int64
	Samps  int
	UseMax bool
	CellW  float64
	CellH  float64
	CLen   int
	// contains filtered or unexported fields
}

func NewBlockNoise

func NewBlockNoise(w, h float64, r, c int, d float64) *BlockNoise

func (*BlockNoise) Eval2

func (bn *BlockNoise) Eval2(x, y float64) float64

Eval2 implements the Field interface.

type BottomHat

type BottomHat struct {
	Name string
	Src1 Field
	Src2 Field
}

BottomHat - C - orig

func NewBottomHat

func NewBottomHat(src Field, supp [][]float64) *BottomHat

func (*BottomHat) Eval2

func (m *BottomHat) Eval2(x, y float64) float64

type Cache

type Cache struct {
	Name       string
	Src        Field
	Resolution float64
	Limit      int
	// contains filtered or unexported fields
}

Cache provides a simple caching layer for a field which can be used when the expense of recalcuating a source is expensive or for when multiple queries are likely to be made e.g. morphological and convolution operations.

func NewCache

func NewCache(src Field, resolution float64, limit int) *Cache

NewCache creates a new Cache with the specified resolution and limit. Once the limit is reached, the cache will be reset. The resolution determines the accuracy of the x,y mapping to previous requests.

func (*Cache) Eval2

func (c *Cache) Eval2(x, y float64) float64

Eval2 implements the Field interface.

type CeilFilter

type CeilFilter struct {
	Name string
	Src  Field
	A, B float64
	C    float64
}

CeilFilter maps Av+B to [-1,C]

func NewCeilFilter

func NewCeilFilter(src Field, a, b float64, c float64) *CeilFilter

func (*CeilFilter) Eval2

func (f *CeilFilter) Eval2(x, y float64) float64

Eval2 implements the Field interface.

type ClipFilter

type ClipFilter struct {
	Name string
	Src  Field
	A, B float64
}

Clip limits At+B to [-1,1].

func NewClipFilter

func NewClipFilter(src Field, a, b float64) *ClipFilter

func (*ClipFilter) Eval2

func (f *ClipFilter) Eval2(x, y float64) float64

Eval2 implements the Field interface.

type Close

type Close struct {
	Name string
	Src  Field
}

Close - D then E

func NewClose

func NewClose(src Field, supp [][]float64) *Close

func (*Close) Eval2

func (m *Close) Eval2(x, y float64) float64

type ColorBlend

type ColorBlend struct {
	Name string
	Src1 ColorField
	Src2 ColorField
	Src3 Field
	Lerp LerpType
}

ColorBlend takes colors from the two color field sources and blends them based on the value from the third source using the specified color lerp.

func NewColorBlend

func NewColorBlend(src1, src2 ColorField, src3 Field, lerp LerpType) *ColorBlend

func (*ColorBlend) Eval2

func (c *ColorBlend) Eval2(x, y float64) color.Color

Eval2 implements the ColorField interface.

type ColorConv

type ColorConv struct {
	Name   string
	Src    Field
	Colors []color.Color
	TVals  []float64
	Lerp   LerpType
}

ColorConv combines the field with a color interpolator.

func NewColorConv

func NewColorConv(src Field, start, end color.Color, cols []color.Color, tvals []float64, lerp LerpType) *ColorConv

func (*ColorConv) Eval2

func (c *ColorConv) Eval2(x, y float64) color.Color

Eval2 implements the ColorField interface.

type ColorField

type ColorField interface {
	Eval2(x, y float64) color.Color
}

ColorField defines an evaluation method that given an x and y value, returns a Color.

type ColorFields

type ColorFields struct {
	Name string
	Src1 Field
	Src2 Field
	Src3 Field
	Src4 Field
	HSL  bool
}

ColorFields uses the four field sources to form {R, G, B, A} or {H, S, L, A}.

func NewColorFields

func NewColorFields(src1, src2, src3, src4 Field, hsl bool) *ColorFields

func (*ColorFields) Eval2

func (c *ColorFields) Eval2(x, y float64) color.Color

Eval2 implements the ColorField interface.

type ColorGray

type ColorGray struct {
	Name string
	Src  Field
}

ColorGray contains the field to use in the color evaluation and produces a grayscale color.

func NewColorGray

func NewColorGray(src Field) *ColorGray

func (*ColorGray) Eval2

func (c *ColorGray) Eval2(x, y float64) color.Color

Eval2 implements the ColorField interface.

type ColorSelect

type ColorSelect struct {
	Name string
	Src  ColorField
	Chan int
}

func NewColorSelect

func NewColorSelect(src ColorField, ch int) *ColorSelect

func (*ColorSelect) Eval2

func (c *ColorSelect) Eval2(x, y float64) float64

type ColorSinCos

type ColorSinCos struct {
	Name string
	Src  Field
	Mode int
	HSL  bool
}

ColorSinCos contains the field used in the color evaluation. The color produced depends on the mode and color space.

func NewColorSinCos

func NewColorSinCos(src Field, mode int, hsl bool) *ColorSinCos

func (*ColorSinCos) Eval2

func (c *ColorSinCos) Eval2(x, y float64) color.Color

Eval2 implements the ColorField interface.

type ColorSubstitute

type ColorSubstitute struct {
	Name string
	Src1 ColorField
	Src2 ColorField
	Src3 Field
	A, B float64
}

ColorSubstitute returns a color from either Src1 or Src2 depending on if the value from the third source is between the supplied start and end values.

func NewColorSubstitute

func NewColorSubstitute(src1, src2 ColorField, src3 Field, a, b float64) *ColorSubstitute

func (*ColorSubstitute) Eval2

func (c *ColorSubstitute) Eval2(x, y float64) color.Color

Eval2 implements the ColorField interface.

type ColorToGray

type ColorToGray struct {
	Name string
	Src  ColorField
}

func NewColorToGray

func NewColorToGray(src ColorField) *ColorToGray

func (*ColorToGray) Eval2

func (c *ColorToGray) Eval2(x, y float64) float64

type ColorVector

type ColorVector struct {
	Name string
	Src  VectorField
	HSL  bool
}

ColorVector uses the three values from a vector field to populate either R, G, B or H, S, L. Alpha is set to opaque.

func NewColorVector

func NewColorVector(src VectorField, hsl bool) *ColorVector

func (*ColorVector) Eval2

func (c *ColorVector) Eval2(x, y float64) color.Color

Eval2 implements the ColorField interface.

type Component

type Component struct {
	Name   string
	Value  Field
	Vector VectorField
	Color  ColorField
}

Component composes a value, vector and color field.

func NewComponent

func NewComponent(src Field,
	c1, c2, c3 color.Color,
	lerp LerpType,
	bscale float64) *Component

NewComponent takes a source field and returns a component instance. The three colors control the color values at t = 0, 0.5, 1 in the supplied nonlinear color field created from the nonlinear and lerp functions. The vector field is produced by calculating the normals of the source field, scaled by bscale.

type ConicGradient

type ConicGradient struct {
	Name string
	WF   Wave
}
Example
package main

import (
	"fmt"
	"github.com/jphsd/graphics2d/image"
	"github.com/jphsd/texture"
)

func main() {
	nl := texture.NewNLSin()
	w := texture.NewNLWave([]float64{125, 125, 125}, []*texture.NonLinear{nl, nl, nl}, true, false)
	f := texture.NewConicGradient(w)

	img := texture.NewTextureGray16(600, 600, f, -300, -300, 1, 1, false)
	image.SaveImage(img, "ExampleConicGradient")
	fmt.Printf("Generated ExampleConicGradient")
}
Output:
Generated ExampleConicGradient

func NewConicGradient

func NewConicGradient(wf Wave) *ConicGradient

func (*ConicGradient) Eval2

func (g *ConicGradient) Eval2(x, y float64) float64

type Convolution

type Convolution struct {
	Name string
	Src  Field
	Kern [][]float64 // triplet {dx, dy, w}
}

func NewConvolution

func NewConvolution(src Field, kern [][]float64, norm bool) *Convolution

kernel {dx, dy, w}

func (*Convolution) Eval2

func (c *Convolution) Eval2(x, y float64) float64

type DCWave

type DCWave struct {
	Name string
	L1   float64
	L2   float64
	Sum  float64
	NL1  *NonLinear
	NL2  *NonLinear
	Once bool
}

func NewDCWave

func NewDCWave(lambdas []float64, nlfs []*NonLinear, once bool) *DCWave

func (*DCWave) Eval

func (g *DCWave) Eval(v float64) float64

func (*DCWave) Lambda

func (g *DCWave) Lambda() float64

type DiffCombiner

type DiffCombiner struct {
	Name string
	Src1 Field
	Src2 Field
}

DiffCombiner combines two values by weighting them in proportion to the difference between them.

func NewDiffCombiner

func NewDiffCombiner(src1, src2 Field) *DiffCombiner

func (*DiffCombiner) Eval2

func (c *DiffCombiner) Eval2(x, y float64) float64

Eval2 implements the Field interface.

type Dilate

type Dilate struct {
	Name string
	Src  Field
	Supp [][]float64
}

func NewDilate

func NewDilate(src Field, supp [][]float64) *Dilate

func (*Dilate) Eval2

func (m *Dilate) Eval2(x, y float64) float64

type Direction

type Direction struct {
	Name string
	Src  VectorField
}

Direction converts a VectorField to a Field based on the vector's direction in the XY plane.

func NewDirection

func NewDirection(src VectorField) *Direction

func (*Direction) Eval2

func (d *Direction) Eval2(x, y float64) float64

Eval2 implements the Field interface.

type Displace

type Displace struct {
	Name            string
	Src, SrcX, SrcY Field
	Xfm             *graphics2d.Aff3
	Indep           bool
}

Displace allows a source field to be evaluated at locations determined by an offset and scaling of the input x, y coordinates taken from other sources. If Indep is true, then the mapped x, y is independent of the original x, y location.

Example
package main

import (
	"fmt"
	"github.com/jphsd/graphics2d/image"
	"github.com/jphsd/texture"
)

func main() {
	f := texture.NewPerlin(12345)

	fx := texture.NewPerlin(12346)

	fy := texture.NewPerlin(12347)

	f2 := texture.NewDisplace(f, fx, fy, 1)

	img := texture.NewTextureGray16(600, 600, f2, 0, 0, .015, .015, false)
	image.SaveImage(img, "ExampleDisplace")
	fmt.Printf("Generated ExampleDisplace")
}
Output:
Generated ExampleDisplace

func NewDisplace

func NewDisplace(in, dx, dy Field, scale float64) *Displace

NewDisplace creates a new Displace instance using the same transform for both x and y displacements.

func (*Displace) Eval2

func (d *Displace) Eval2(x, y float64) float64

Eval2 implements the Field interface.

type Displace2

type Displace2 struct {
	Name            string
	Src, SrcX, SrcY Field
	XfmX, XfmY      *graphics2d.Aff3
	Indep           bool
}

Displace2 allows a source field to be evaluated at locations determined by axis independent transforms of the input x, y coordinates taken from other sources. If Indep is true, then the mapped x, y is independent of the original x, y location.

func NewDisplace2

func NewDisplace2(in, dx, dy Field, xfmx, xfmy *graphics2d.Aff3) *Displace2

NewDisplace2 creates a new Displace2 instance using the same source for both x and y displacements.

func (*Displace2) Eval2

func (d *Displace2) Eval2(x, y float64) float64

Eval2 implements the Field interface.

type Displace2CF

type Displace2CF struct {
	Name       string
	Src        ColorField
	SrcX, SrcY Field
	XfmX, XfmY *graphics2d.Aff3
	Indep      bool
}

Displace2CF allows a source field to be evaluated at locations determined by axis independent transforms of the input x, y coordinates taken from other sources. If Indep is true, then the mapped x, y is independent of the original x, y location.

func NewDisplace2CF

func NewDisplace2CF(in ColorField, dx, dy Field, xfmx, xfmy *graphics2d.Aff3) *Displace2CF

NewDisplace2CF creates a new Displace2 instance using the same source for both x and y displacements.

func (*Displace2CF) Eval2

func (d *Displace2CF) Eval2(x, y float64) color.Color

Eval2 implements the Field interface.

type Displace2VF

type Displace2VF struct {
	Name       string
	Src        VectorField
	SrcX, SrcY Field
	XfmX, XfmY *graphics2d.Aff3
	Indep      bool
}

Displace2VF allows a source field to be evaluated at locations determined by axis independent transforms of the input x, y coordinates taken from other sources. If Indep is true, then the mapped x, y is independent of the original x, y location.

func NewDisplace2VF

func NewDisplace2VF(in VectorField, dx, dy Field, xfmx, xfmy *graphics2d.Aff3) *Displace2VF

NewDisplace2VF creates a new Displace2 instance using the same source for both x and y displacements.

func (*Displace2VF) Eval2

func (d *Displace2VF) Eval2(x, y float64) []float64

Eval2 implements the Field interface.

type DisplaceCF

type DisplaceCF struct {
	Name       string
	Src        ColorField
	SrcX, SrcY Field
	Xfm        *graphics2d.Aff3
	Indep      bool
}

DisplaceCF allows a source field to be evaluated at locations determined by an offset and scaling of the input x, y coordinates taken from other sources. If Indep is true, then the mapped x, y is independent of the original x, y location.

func NewDisplaceCF

func NewDisplaceCF(in ColorField, dx, dy Field, scale float64) *DisplaceCF

NewDisplaceCF creates a new Displace instance using the same transform for both x and y displacements.

func (*DisplaceCF) Eval2

func (d *DisplaceCF) Eval2(x, y float64) color.Color

Eval2 implements the Field interface.

type DisplaceVF

type DisplaceVF struct {
	Name       string
	Src        VectorField
	SrcX, SrcY Field
	Xfm        *graphics2d.Aff3
	Indep      bool
}

DisplaceVF allows a source field to be evaluated at locations determined by an offset and scaling of the input x, y coordinates taken from other sources. If Indep is true, then the mapped x, y is independent of the original x, y location.

func NewDisplaceVF

func NewDisplaceVF(in VectorField, dx, dy Field, scale float64) *DisplaceVF

NewDisplaceVF creates a new Displace instance using the same transform for both x and y displacements.

func (*DisplaceVF) Eval2

func (d *DisplaceVF) Eval2(x, y float64) []float64

Eval2 implements the Field interface.

type Distort

type Distort struct {
	Name           string
	Src            Field
	OffsX, OffsY   float64
	NOffsX, NOffsY float64
	Distortion     float64
}

Distort applies a distortion to a source field based on the values it contains. Based on Musgrave's VLNoise3() in Ch 8 of Texturing and Modeling

Example
package main

import (
	"fmt"
	"github.com/jphsd/graphics2d/image"
	"github.com/jphsd/texture"
)

func main() {
	f := texture.NewPerlin(12345)

	f2 := texture.NewDistort(f, 10)

	img := texture.NewTextureGray16(600, 600, f2, 0, 0, .015, .015, false)
	image.SaveImage(img, "ExampleDistort")
	fmt.Printf("Generated ExampleDistort")
}
Output:
Generated ExampleDistort

func NewDistort

func NewDistort(src Field, dist float64) *Distort

NewDistort creates a new Distort instance.

func (*Distort) Eval2

func (d *Distort) Eval2(x, y float64) float64

Eval2 implements the Field interface.

type DrainWF

type DrainWF struct {
	Name   string
	Center []float64 // Center of warp
	Scale  float64   // Scale factor
	Effct  float64   // Effect radius
}

DrainWF performs a drain warp around Center in x for use in the above warp types. The x value is scaled about the central x value by |dy|^alpha*scale

func NewDrainWF

func NewDrainWF(c []float64, s, e float64) *DrainWF

func (*DrainWF) Eval

func (wf *DrainWF) Eval(x, y float64) (float64, float64)

Eval implements the WarpFunc interface

type Edge

type Edge struct {
	Name string
	Src1 Field
	Src2 Field
}

Edge - D - E

func NewEdge

func NewEdge(src Field, supp [][]float64) *Edge

func (*Edge) Eval2

func (m *Edge) Eval2(x, y float64) float64

type EdgeIn

type EdgeIn struct {
	Name string
	Src1 Field
	Src2 Field
}

EdgeIn - orig - E

func NewEdgeIn

func NewEdgeIn(src Field, supp [][]float64) *EdgeIn

func (*EdgeIn) Eval2

func (m *EdgeIn) Eval2(x, y float64) float64

type EdgeOut

type EdgeOut struct {
	Name string
	Src1 Field
	Src2 Field
}

EdgeOut - D - orig

func NewEdgeOut

func NewEdgeOut(src Field, supp [][]float64) *EdgeOut

func (*EdgeOut) Eval2

func (m *EdgeOut) Eval2(x, y float64) float64

type Erode

type Erode struct {
	Name string
	Src  Field
	Supp [][]float64
}

func NewErode

func NewErode(src Field, supp [][]float64) *Erode

func (*Erode) Eval2

func (m *Erode) Eval2(x, y float64) float64

type FBM

type FBM struct {
	Name    string
	Weights []float64
}

FBM holds the precomputed weights for an fBM.

func NewFBM

func NewFBM(hurst, lacunarity float64, maxoct int) *FBM

NewFBM returns a new FBM instance based on the Hurst and Lacunarity parameters.

func (*FBM) Combine

func (f *FBM) Combine(values ...float64) float64

Combine takes the values from the successive applications of the affine transform and combines them using the precomputed weights.

type Field

type Field interface {
	Eval2(x, y float64) float64
}

Field defines an evaluation method that given an x and y value, returns a value in the range [-1,1].

type FloorFilter

type FloorFilter struct {
	Name string
	Src  Field
	A, B float64
	C    float64
}

FloorFilter maps Av+B to [C, 1]

func NewFloorFilter

func NewFloorFilter(src Field, a, b float64, c float64) *FloorFilter

func (*FloorFilter) Eval2

func (f *FloorFilter) Eval2(x, y float64) float64

Eval2 implements the Field interface.

type FoldFilter

type FoldFilter struct {
	Name string
	Src  Field
	A, B float64
}

Fold wraps values (aX+b) outside of the domain [-1,1] back into it.

func NewFoldFilter

func NewFoldFilter(src Field, a, b float64) *FoldFilter

func (*FoldFilter) Eval2

func (f *FoldFilter) Eval2(x, y float64) float64

Eval2 implements the Field interface.

type Fractal

type Fractal struct {
	Name    string
	Src     Field
	Xfm     *g2d.Aff3
	Comb    OctaveCombiner
	Octaves float64
	Weights []float64
}

Fractal holds the pieces necessary for fractal generation. Xfm defines the affine transformation applied successively to the coordinate space and Comb, how the multiple resultant values should be combined. Bands can also be manipulated through the weight values (typically [0, 1]) which allows certain frequencies to be attenuated.

Example (Fbm)
package main

import (
	"fmt"
	"github.com/jphsd/graphics2d"
	"github.com/jphsd/graphics2d/image"
	"github.com/jphsd/texture"
)

func main() {
	f := texture.NewPerlin(12345)

	lac := 2.0
	hurst := 1.0
	oct := 3.0
	xfm := graphics2d.Scale(lac, lac)
	fbm := texture.NewFBM(hurst, lac, int(oct+1))
	f2 := texture.NewFractal(f, xfm, fbm, 3)

	img := texture.NewTextureGray16(600, 600, f2, 0, 0, .015, .015, false)
	image.SaveImage(img, "ExampleFractal_fbm")
	fmt.Printf("Generated ExampleFractal_fbm")
}
Output:
Generated ExampleFractal_fbm
Example (Mf)
package main

import (
	"fmt"
	"github.com/jphsd/graphics2d"
	"github.com/jphsd/graphics2d/image"
	"github.com/jphsd/texture"
)

func main() {
	f := texture.NewPerlin(12345)

	lac := 2.0
	hurst := 1.0
	oct := 3.0
	xfm := graphics2d.Scale(lac, lac)
	fbm := texture.NewMF(hurst, lac, 0.5, int(oct+1))
	f2 := texture.NewFractal(f, xfm, fbm, 3)

	img := texture.NewTextureGray16(600, 600, f2, 0, 0, .015, .015, false)
	image.SaveImage(img, "ExampleFractal_mf")
	fmt.Printf("Generated ExampleFractal_mf")
}
Output:
Generated ExampleFractal_mf

func NewFractal

func NewFractal(src Field, xfm *g2d.Aff3, comb OctaveCombiner, octaves float64) *Fractal

NewFractal returns a new Fractal instance.

func (*Fractal) Eval2

func (f *Fractal) Eval2(x, y float64) float64

Eval2 implements the Field interface.

type Hexagons

type Hexagons struct {
	Name  string
	Scale float64
}
Example
package main

import (
	"fmt"
	"github.com/jphsd/graphics2d/image"
	"github.com/jphsd/texture"
)

func main() {
	f := texture.NewHexagons(20)

	img := texture.NewTextureGray16(600, 600, f, 0, 0, 1, 1, false)
	image.SaveImage(img, "ExampleHexagons")
	fmt.Printf("Generated ExampleHexagons")
}
Output:
Generated ExampleHexagons

func NewHexagons

func NewHexagons(s float64) *Hexagons

func (*Hexagons) Eval2

func (h *Hexagons) Eval2(x, y float64) float64

type IFS

type IFS struct {
	Name string
	Dom  []float64
	Xfms []*g2d.Aff3 // Inverses of the IFS contractive affine transformations
	Itr  int
}

IFS represents a collection of affine transforms comprising an iterated function system.

func NewIFS

func NewIFS(dom []float64, xfms []*g2d.Aff3, itr int) *IFS

NewIFS returns a new instance of IFS. Note that the number of sub evaluations required is the number of transforms to the power of the number of iterations per evaluation.

func (*IFS) Eval2

func (f *IFS) Eval2(x, y float64) float64

Eval2 implements the Field interface.

type IFSCombiner

type IFSCombiner struct {
	Name string
	Src1 Field
	Src2 Field
	Dom  []float64
	Xfms []*g2d.Aff3 // Inverses of the IFS contractive affine transformations
	Itr  int
}

IFS represents a collection of affine transforms comprising an iterated function system.

func NewIFSCombiner

func NewIFSCombiner(src1, src2 Field, dom []float64, xfms []*g2d.Aff3, itr int) *IFSCombiner

NewIFSCombiner returns a new instance of IFS. Note that the number of sub evaluations required is the number of transforms to the power of the number of iterations per evaluation.

func (*IFSCombiner) Eval2

func (f *IFSCombiner) Eval2(x, y float64) float64

Eval2 implements the Field interface.

type Image

type Image struct {
	Name string

	MinX  int
	LastX int
	MinY  int
	LastY int
	Func  Interp
	// contains filtered or unexported fields
}

Image holds the data to support a continuous bicubic interpolation over an image.

func NewImage

func NewImage(img image.Image, interp Interp) *Image

NewImage sets up a new field with the supplied image. The image is converted to a {0, 0} offset NRGBA image.

func (*Image) Eval2

func (f *Image) Eval2(x, y float64) color.Color

Eval2 implements the ColorField interface.

type Interp

type Interp int
const (
	NearestInterp Interp = iota
	LinearInterp
	CubicInterp
	P3Interp
	P5Interp
)

type InvertFilter

type InvertFilter struct {
	Name string
	Src  Field
}

InvertFilter flips the sign of v.

func NewInvertFilter

func NewInvertFilter(src Field) *InvertFilter

func (*InvertFilter) Eval2

func (f *InvertFilter) Eval2(x, y float64) float64

Eval2 implements the Field interface.

type InvertWave

type InvertWave struct {
	Name string
	Src  Wave
}

func NewInvertWave

func NewInvertWave(src Wave) *InvertWave

func (*InvertWave) Eval

func (g *InvertWave) Eval(v float64) float64

func (*InvertWave) Lambda

func (g *InvertWave) Lambda() float64

type JitterBlend

type JitterBlend struct {
	Name string
	Src1 Field
	Src2 Field
	Src3 Field
	Perc float64
}

func NewJitterBlend

func NewJitterBlend(src1, src2, src3 Field, perc float64) *JitterBlend

func (*JitterBlend) Eval2

func (b *JitterBlend) Eval2(x, y float64) float64

Eval2 implements the Field interface.

type LerpType

type LerpType int

LerpType defines the type of lerp -

const (
	LerpRGBA LerpType = iota
	LerpHSL
	LerpHSLs
)

Constants for lerp types.

type LinearGradient

type LinearGradient struct {
	Name string
	WF   Wave
}
Example (Circular)
package main

import (
	"fmt"
	"github.com/jphsd/graphics2d/image"
	"github.com/jphsd/texture"
)

func main() {
	nl1 := texture.NewNLCircle1()
	nl2 := texture.NewNLCircle2()
	w := texture.NewDCWave([]float64{125}, []*texture.NonLinear{nl1, nl2}, false)
	f := texture.NewLinearGradient(w)

	img := texture.NewTextureGray16(600, 600, f, 0, 0, 1, 1, false)
	image.SaveImage(img, "ExampleLinearGradient_circular")
	fmt.Printf("Generated ExampleLinearGradient_circular")
}
Output:
Generated ExampleLinearGradient_circular
Example (Saw)
package main

import (
	"fmt"
	"github.com/jphsd/graphics2d/image"
	"github.com/jphsd/texture"
)

func main() {
	nl := texture.NewNLLinear()
	w := texture.NewNLWave([]float64{125}, []*texture.NonLinear{nl}, false, false)
	f := texture.NewLinearGradient(w)

	img := texture.NewTextureGray16(600, 600, f, 0, 0, 1, 1, false)
	image.SaveImage(img, "ExampleLinearGradient_saw")
	fmt.Printf("Generated ExampleLinearGradient_saw")
}
Output:
Generated ExampleLinearGradient_saw
Example (Sine)
package main

import (
	"fmt"
	"github.com/jphsd/graphics2d/image"
	"github.com/jphsd/texture"
)

func main() {
	nl := texture.NewNLSin()
	w := texture.NewNLWave([]float64{125}, []*texture.NonLinear{nl}, true, false)
	f := texture.NewLinearGradient(w)

	img := texture.NewTextureGray16(600, 600, f, 0, 0, 1, 1, false)
	image.SaveImage(img, "ExampleLinearGradient_sine")
	fmt.Printf("Generated ExampleLinearGradient_sine")
}
Output:
Generated ExampleLinearGradient_sine
Example (Triangle)
package main

import (
	"fmt"
	"github.com/jphsd/graphics2d/image"
	"github.com/jphsd/texture"
)

func main() {
	nl := texture.NewNLLinear()
	w := texture.NewNLWave([]float64{125}, []*texture.NonLinear{nl}, true, false)
	f := texture.NewLinearGradient(w)

	img := texture.NewTextureGray16(600, 600, f, 0, 0, 1, 1, false)
	image.SaveImage(img, "ExampleLinearGradient_triangle")
	fmt.Printf("Generated ExampleLinearGradient_triangle")
}
Output:
Generated ExampleLinearGradient_triangle

func NewLinearGradient

func NewLinearGradient(wf Wave) *LinearGradient

func (*LinearGradient) Eval2

func (g *LinearGradient) Eval2(x, y float64) float64

type MF

type MF struct {
	Name    string
	Weights []float64
	Offset  float64
}

MF holds the precomputed weights and offset for an multifractal.

func NewMF

func NewMF(hurst, lacunarity, offset float64, maxoct int) *MF

NewMF returns a new MF instance based on the Hurst and Lacunarity parameters.

func (*MF) Combine

func (f *MF) Combine(values ...float64) float64

Combine takes the values from the successive applications of the affine transform and combines them using the precomputed weights and offset.

type Magnitude

type Magnitude struct {
	Name  string
	Src   VectorField
	Scale float64
}

Magnitude converts a VectorField to a Field based on the vector's magnitude.

func NewMagnitude

func NewMagnitude(src VectorField, scale float64) *Magnitude

func (*Magnitude) Eval2

func (m *Magnitude) Eval2(x, y float64) float64

Eval2 implements the Field interface. Always >= 0

type MaxCombiner

type MaxCombiner struct {
	Name string
	Src1 Field
	Src2 Field
}

MaxCombiner is a maximizing combiner.

Example
package main

import (
	"fmt"
	"github.com/jphsd/graphics2d"
	"github.com/jphsd/graphics2d/image"
	"github.com/jphsd/texture"
)

func main() {
	nl := texture.NewNLSin()
	w := texture.NewNLWave([]float64{125}, []*texture.NonLinear{nl}, true, false)
	f := texture.NewLinearGradient(w)

	xfm := graphics2d.Rotate(graphics2d.HalfPi)
	f2 := texture.NewTransform(f, xfm)

	f3 := texture.NewMaxCombiner(f, f2)

	img := texture.NewTextureGray16(600, 600, f3, 0, 0, 1, 1, false)
	image.SaveImage(img, "ExampleMaxCombiner")
	fmt.Printf("Generated ExampleMaxCombiner")
}
Output:
Generated ExampleMaxCombiner

func NewMaxCombiner

func NewMaxCombiner(src1, src2 Field) *MaxCombiner

func (*MaxCombiner) Eval2

func (c *MaxCombiner) Eval2(x, y float64) float64

Eval2 implements the Field interface.

type MinCombiner

type MinCombiner struct {
	Name string
	Src1 Field
	Src2 Field
}

MinCombiner is a minimizing combiner.

func NewMinCombiner

func NewMinCombiner(src1, src2 Field) *MinCombiner

func (*MinCombiner) Eval2

func (c *MinCombiner) Eval2(x, y float64) float64

Eval2 implements the Field interface.

type MulCombiner

type MulCombiner struct {
	Name string
	Src1 Field
	Src2 Field
	Offs float64
	Scal float64
}

MulCombiner is a multiplying combiner.

Example
package main

import (
	"fmt"
	"github.com/jphsd/graphics2d"
	"github.com/jphsd/graphics2d/image"
	"github.com/jphsd/texture"
)

func main() {
	nl := texture.NewNLSin()
	w := texture.NewNLWave([]float64{125}, []*texture.NonLinear{nl}, true, false)
	f := texture.NewLinearGradient(w)

	xfm := graphics2d.Rotate(graphics2d.HalfPi)
	f2 := texture.NewTransform(f, xfm)

	f3 := texture.NewMulCombiner(f, f2)

	img := texture.NewTextureGray16(600, 600, f3, 0, 0, 1, 1, false)
	image.SaveImage(img, "ExampleMulCombiner")
	fmt.Printf("Generated ExampleMulCombiner")
}
Output:
Generated ExampleMulCombiner

func NewMulCombiner

func NewMulCombiner(src1, src2 Field) *MulCombiner

func (*MulCombiner) Eval2

func (c *MulCombiner) Eval2(x, y float64) float64

Eval2 implements the Field interface.

type NLFilter

type NLFilter struct {
	Name   string
	Src    Field
	NLFunc *NonLinear
	A, B   float64
}

NLFilter holds the parameters for a symmetric non-linear filter mapping.

func NewNLFilter

func NewNLFilter(src Field, nlf *NonLinear, a, b float64) *NLFilter

func (*NLFilter) Eval2

func (f *NLFilter) Eval2(x, y float64) float64

Eval2 implements the Field interface.

type NLWave

type NLWave struct {
	Name      string
	Lambdas   []float64
	CumLambda []float64
	NLFs      []*NonLinear
	Mirrored  bool
	Once      bool
}

func NewNLWave

func NewNLWave(lambdas []float64, nlfs []*NonLinear, mirror, once bool) *NLWave

func (*NLWave) Eval

func (g *NLWave) Eval(v float64) float64

func (*NLWave) Lambda

func (g *NLWave) Lambda() float64

type NonLinear

type NonLinear struct {
	Name string
	NLF  nonlinear.NonLinear
}

func NewNLCatenary

func NewNLCatenary() *NonLinear

func NewNLCircle1

func NewNLCircle1() *NonLinear

func NewNLCircle2

func NewNLCircle2() *NonLinear

func NewNLCube

func NewNLCube() *NonLinear

func NewNLExponential

func NewNLExponential(v float64) *NonLinear

func NewNLGauss

func NewNLGauss(v float64) *NonLinear

func NewNLLinear

func NewNLLinear() *NonLinear

func NewNLLogarithmic

func NewNLLogarithmic(v float64) *NonLinear

func NewNLLogistic

func NewNLLogistic(u, v float64) *NonLinear

func NewNLP3

func NewNLP3() *NonLinear

func NewNLP5

func NewNLP5() *NonLinear

func NewNLSin

func NewNLSin() *NonLinear

func NewNLSin1

func NewNLSin1() *NonLinear

func NewNLSin2

func NewNLSin2() *NonLinear

func NewNLSquare

func NewNLSquare() *NonLinear

func (*NonLinear) Eval

func (nl *NonLinear) Eval(t float64) float64

func (*NonLinear) Eval0

func (nl *NonLinear) Eval0(t float64) float64

type Normal

type Normal struct {
	Name     string
	Src      Field
	SDx, SDy float64
	Dx, Dy   float64
}

Normal provides a VectorField calculated from a Field using the finite difference method.

func NewNormal

func NewNormal(src Field, sx, sy, dx, dy float64) *Normal

NewNormal returns a new instance of Normal.

func (*Normal) Eval2

func (n *Normal) Eval2(x, y float64) []float64

Eval2 implements the VectorField interface.

type OctaveCombiner

type OctaveCombiner interface {
	Combine(...float64) float64
}

type OffsScaleFilter

type OffsScaleFilter struct {
	Name string
	Src  Field
	A, B float64
}

OffsScaleFilter limits A(t+B) to [-1,1].

func NewOffsScaleFilter

func NewOffsScaleFilter(src Field, a, b float64) *OffsScaleFilter

func (*OffsScaleFilter) Eval2

func (f *OffsScaleFilter) Eval2(x, y float64) float64

Eval2 implements the Field interface.

type Open

type Open struct {
	Name string
	Src  Field
}

Open - E then D

func NewOpen

func NewOpen(src Field, supp [][]float64) *Open

func (*Open) Eval2

func (m *Open) Eval2(x, y float64) float64

type PatternWave

type PatternWave struct {
	Name      string
	Lambdas   []float64
	CumLambda []float64
	Patterns  [][]float64
	Mirrored  bool
	Once      bool
}

func NewPatternWave

func NewPatternWave(lambdas []float64, patterns [][]float64, mirror, once bool) *PatternWave

func (*PatternWave) Eval

func (g *PatternWave) Eval(v float64) float64

func (*PatternWave) Lambda

func (g *PatternWave) Lambda() float64

type Perlin

type Perlin struct {
	Name string
	Seed int64
	// contains filtered or unexported fields
}

Perlin contains the hash structures for generating a noise value between [-1,1). Note noise wraps in 256.

Example
package main

import (
	"fmt"
	"github.com/jphsd/graphics2d/image"
	"github.com/jphsd/texture"
)

func main() {
	f := texture.NewPerlin(12345)

	img := texture.NewTextureGray16(600, 600, f, 0, 0, .015, .015, false)
	image.SaveImage(img, "ExamplePerlin")
	fmt.Printf("Generated ExamplePerlin")
}
Output:
Generated ExamplePerlin

func NewPerlin

func NewPerlin(seed int64) *Perlin

NewPerlin initializes a new Perlin hash structure.

func (*Perlin) Eval2

func (p *Perlin) Eval2(x, y float64) float64

Eval2 calculates the value at x,y based on the interpolated gradients of the four corners of the square which x,y resides in. It implements the Field interface.

type PinchXWF

type PinchXWF struct {
	Name   string
	Center []float64 // Center of warp
	Init   float64   // Initial scale
	Scale  float64   // Scale factor
	Alpha  float64   // Power factor
}

PinchXWF performs a pinched warp around Center in x for use in the above warp types. The x value is scaled about the central x value by |dy|^alpha*scale

func NewPinchXWF

func NewPinchXWF(c []float64, i, s, a float64) *PinchXWF

func (*PinchXWF) Eval

func (wf *PinchXWF) Eval(x, y float64) (float64, float64)

Eval implements the WarpFunc interface

type Pixelate

type Pixelate struct {
	Name       string
	Src        Field
	Resolution float64
}

Pixelate provides pixelation for a field.

func NewPixelate

func NewPixelate(src Field, resolution float64) *Pixelate

NewPixelate creates a new Pixelate with the specified resolution.

func (*Pixelate) Eval2

func (p *Pixelate) Eval2(x, y float64) float64

Eval2 implements the Field interface.

type PixelateCF

type PixelateCF struct {
	Name       string
	Src        ColorField
	Resolution float64
}

PixelateCF provides pixelation for a color field.

func NewPixelateCF

func NewPixelateCF(src ColorField, resolution float64) *PixelateCF

NewPixelateCF creates a new Pixelate with the specified resolution.

func (*PixelateCF) Eval2

func (p *PixelateCF) Eval2(x, y float64) color.Color

Eval2 implements the Field interface.

type PixelateVF

type PixelateVF struct {
	Name       string
	Src        VectorField
	Resolution float64
}

PixelateVF provides pixelation for a vector field.

func NewPixelateVF

func NewPixelateVF(src VectorField, resolution float64) *PixelateVF

NewPixelateVF creates a new Pixelate with the specified resolution.

func (*PixelateVF) Eval2

func (p *PixelateVF) Eval2(x, y float64) []float64

Eval2 implements the Field interface.

type QuantizeFilter

type QuantizeFilter struct {
	Name string
	Src  Field
	A, B float64
	C    int
}

Quantize maps Av+B into one of C buckets.

func NewQuantizeFilter

func NewQuantizeFilter(src Field, a, b float64, c int) *QuantizeFilter

func (*QuantizeFilter) Eval2

func (f *QuantizeFilter) Eval2(x, y float64) float64

Eval2 implements the Field interface.

type RadialGradient

type RadialGradient struct {
	Name string
	WF   Wave
}
Example (Circular)
package main

import (
	"fmt"
	"github.com/jphsd/graphics2d/image"
	"github.com/jphsd/texture"
)

func main() {
	nl1 := texture.NewNLCircle1()
	nl2 := texture.NewNLCircle2()
	w := texture.NewDCWave([]float64{125}, []*texture.NonLinear{nl1, nl2}, false)
	f := texture.NewRadialGradient(w)

	img := texture.NewTextureGray16(600, 600, f, 0, 0, 1, 1, false)
	image.SaveImage(img, "ExampleRadialGradient_circular")
	fmt.Printf("Generated ExampleRadialGradient_circular")
}
Output:
Generated ExampleRadialGradient_circular
Example (Saw)
package main

import (
	"fmt"
	"github.com/jphsd/graphics2d/image"
	"github.com/jphsd/texture"
)

func main() {
	nl := texture.NewNLLinear()
	w := texture.NewNLWave([]float64{125}, []*texture.NonLinear{nl}, false, false)
	f := texture.NewRadialGradient(w)

	img := texture.NewTextureGray16(600, 600, f, 0, 0, 1, 1, false)
	image.SaveImage(img, "ExampleRadialGradient_saw")
	fmt.Printf("Generated ExampleRadialGradient_saw")
}
Output:
Generated ExampleRadialGradient_saw
Example (Sine)
package main

import (
	"fmt"
	"github.com/jphsd/graphics2d/image"
	"github.com/jphsd/texture"
)

func main() {
	nl := texture.NewNLSin()
	w := texture.NewNLWave([]float64{125}, []*texture.NonLinear{nl}, true, false)
	f := texture.NewRadialGradient(w)

	img := texture.NewTextureGray16(600, 600, f, 0, 0, 1, 1, false)
	image.SaveImage(img, "ExampleRadialGradient_sine")
	fmt.Printf("Generated ExampleRadialGradient_sine")
}
Output:
Generated ExampleRadialGradient_sine
Example (Triangle)
package main

import (
	"fmt"
	"github.com/jphsd/graphics2d/image"
	"github.com/jphsd/texture"
)

func main() {
	nl := texture.NewNLLinear()
	w := texture.NewNLWave([]float64{125}, []*texture.NonLinear{nl}, true, false)
	f := texture.NewRadialGradient(w)

	img := texture.NewTextureGray16(600, 600, f, 0, 0, 1, 1, false)
	image.SaveImage(img, "ExampleRadialGradient_triangle")
	fmt.Printf("Generated ExampleRadialGradient_triangle")
}
Output:
Generated ExampleRadialGradient_triangle

func NewRadialGradient

func NewRadialGradient(wf Wave) *RadialGradient

func (*RadialGradient) Eval2

func (g *RadialGradient) Eval2(x, y float64) float64

type RadialNLWF

type RadialNLWF struct {
	Name   string
	Center []float64  // Center of warp
	NL     *NonLinear // [0,1] => [0,1]
	Effct  float64    // Effect radius
}

RadialNLWF performs a radius warp around Center based on an NL

func NewRadialNLWF

func NewRadialNLWF(c []float64, nl *NonLinear, e float64) *RadialNLWF

func (*RadialNLWF) Eval

func (wf *RadialNLWF) Eval(x, y float64) (float64, float64)

Eval implements the WarpFunc interface

type RadialRippleWF

type RadialRippleWF struct {
	Name   string
	Center []float64
	Lambda float64
	Amplit float64
	Offset float64
}

RadialRippleWF performs a sin warp using the r value, lambda and offset and applies it to the r value, scaled by the amplitude.

func NewRadialRippleWF

func NewRadialRippleWF(c []float64, l, a, o float64) *RadialRippleWF

func (*RadialRippleWF) Eval

func (wf *RadialRippleWF) Eval(x, y float64) (float64, float64)

Eval implements the WarpFunc interface

type RadialWF

type RadialWF struct {
	Name   string
	Center []float64 // Center of warp
	RScale float64   // Radial scale
	CScale float64   // Circumference scale
}

RadialWF performs a scaled warp around Center for use in the above warp types.

func NewRadialWF

func NewRadialWF(c []float64, rs, cs float64) *RadialWF

func (*RadialWF) Eval

func (wf *RadialWF) Eval(x, y float64) (float64, float64)

Eval implements the WarpFunc interface

type RadialWiggleWF

type RadialWiggleWF struct {
	Name   string
	Center []float64
	Lambda float64
	Amplit float64
	Offset float64
}

RadialWiggleWF performs a sin warp using the r value, lambda and offset and applies it to the th value, scaled by the amplitude.

func NewRadialWiggleWF

func NewRadialWiggleWF(c []float64, l, a, o float64) *RadialWiggleWF

func (*RadialWiggleWF) Eval

func (wf *RadialWiggleWF) Eval(x, y float64) (float64, float64)

Eval implements the WarpFunc interface

type RandQuantFilter

type RandQuantFilter struct {
	Src  Field
	A, B float64
	C    int
	M    []float64
}

RandQuantFilter supports a randomized quatization filter.

func NewRandQuantFilter

func NewRandQuantFilter(src Field, a, b float64, c int) *RandQuantFilter

NewRandQuantFilter returns a new RandFilter instance for use in quantization.

func (*RandQuantFilter) Eval2

func (f *RandQuantFilter) Eval2(x, y float64) float64

Eval2 implements the Field interface.

type Reflect

type Reflect struct {
	Name  string
	Src   Field
	Start []float64
	End   []float64
	Xfm   *graphics2d.Aff3
}

Reflect contains a line along which a reflection is performed. The line defines where the mirror is. Points on the + side of the line remain untransformed, points on the other are reflected through the transformation.

Example
package main

import (
	"fmt"
	"github.com/jphsd/graphics2d/image"
	"github.com/jphsd/texture"
)

func main() {
	f := texture.NewPerlin(12345)

	f2 := texture.NewReflect(f, []float64{0, 9}, []float64{9, 0})

	img := texture.NewTextureGray16(600, 600, f2, 0, 0, .015, .015, false)
	image.SaveImage(img, "ExampleReflect")
	fmt.Printf("Generated ExampleReflect")
}
Output:
Generated ExampleReflect

func NewReflect

func NewReflect(src Field, lp1, lp2 []float64) *Reflect

NewReflect creates a new Reflection placing the mirror along lp1, lp2.

func (*Reflect) Eval2

func (r *Reflect) Eval2(x, y float64) float64

Eval2 implements the Field interface.

type ReflectCF

type ReflectCF struct {
	Name  string
	Src   ColorField
	Start []float64
	End   []float64
	Xfm   *graphics2d.Aff3
}

ReflectCF contains a line along which a reflection is performed. The line defines where the mirror is. Points on the + side of the line remain untransformed, points on the other are reflected through the transformation.

func NewReflectCF

func NewReflectCF(src ColorField, lp1, lp2 []float64) *ReflectCF

NewReflect creates a new Reflection placing the mirror along lp1, lp2.

func (*ReflectCF) Eval2

func (r *ReflectCF) Eval2(x, y float64) color.Color

Eval2 implements the Field interface.

type ReflectVF

type ReflectVF struct {
	Name  string
	Src   VectorField
	Start []float64
	End   []float64
	Xfm   *graphics2d.Aff3
}

ReflectVF contains a line along which a reflection is performed. The line defines where the mirror is. Points on the + side of the line remain untransformed, points on the other are reflected through the transformation.

func NewReflectVF

func NewReflectVF(src VectorField, lp1, lp2 []float64) *ReflectVF

NewReflect creates a new Reflection placing the mirror along lp1, lp2.

func (*ReflectVF) Eval2

func (r *ReflectVF) Eval2(x, y float64) []float64

Eval2 implements the Field interface.

type RemapFilter

type RemapFilter struct {
	Name string
	Src  Field
	A, B float64
}

RemapFilter holds the parameters for a linear filter remapping [-1,1] => [a,b].

func NewRemapFilter

func NewRemapFilter(src Field, a, b float64) *RemapFilter

func (*RemapFilter) Eval2

func (f *RemapFilter) Eval2(x, y float64) float64

Eval2 implements the Field interface.

type RippleXWF

type RippleXWF struct {
	Name   string
	Lambda float64
	Amplit float64
	Offset float64
}

RippleXWF performs a sin warp using the y value, lambda and offset and applies it to the x value, scaled by the amplitude.

func NewRippleXWF

func NewRippleXWF(l, a, o float64) *RippleXWF

func (*RippleXWF) Eval

func (wf *RippleXWF) Eval(x, y float64) (float64, float64)

Eval implements the WarpFunc interface

type Select

type Select struct {
	Name  string
	Src   VectorField
	Chan  int
	Scale float64
}

Select converts a VectorField to a field by selecting one of its components.

func NewSelect

func NewSelect(src VectorField, ch int, scale float64) *Select

func (*Select) Eval2

func (s *Select) Eval2(x, y float64) float64

Eval2 implements the Field interface.

type Shape

type Shape struct {
	Name  string
	Shape *graphics2d.Shape
	Style ShapeStyle
}
Example
package main

import (
	"fmt"
	"github.com/jphsd/graphics2d"
	"github.com/jphsd/graphics2d/image"
	"github.com/jphsd/texture"
)

func main() {
	shape := graphics2d.NewShape(graphics2d.ReentrantPolygon([]float64{300, 300}, 300, 5, .65, 0))
	f := texture.NewShape(shape, texture.BinaryStyle)

	img := texture.NewTextureGray16(600, 600, f, 0, 0, 1, 1, false)
	image.SaveImage(img, "ExampleShape")
	fmt.Printf("Generated ExampleShape")
}
Output:
Generated ExampleShape

func NewShape

func NewShape(shape *graphics2d.Shape, style ShapeStyle) *Shape

func (*Shape) Eval2

func (s *Shape) Eval2(x, y float64) float64

type ShapeCombiner

type ShapeCombiner struct {
	Name  string
	Src1  Field
	Src2  Field
	Shape *graphics2d.Shape
}

Could do these with from primitive operations

Example
package main

import (
	"fmt"
	"github.com/jphsd/graphics2d"
	"github.com/jphsd/graphics2d/image"
	"github.com/jphsd/texture"
)

func main() {
	nl := texture.NewNLSin()
	w := texture.NewNLWave([]float64{32}, []*texture.NonLinear{nl}, true, false)
	f := texture.NewRadialGradient(w)

	xfm := graphics2d.Translate(-300, -300)
	f2 := texture.NewTransform(f, xfm)

	f3 := texture.NewSquares(40)

	shape := graphics2d.NewShape(graphics2d.ReentrantPolygon([]float64{300, 300}, 300, 5, .65, 0))
	f4 := texture.NewShapeCombiner(f2, f3, shape)

	img := texture.NewTextureGray16(600, 600, f4, 0, 0, 1, 1, false)
	image.SaveImage(img, "ExampleShapeCombiner")
	fmt.Printf("Generated ExampleShapeCombiner")
}
Output:
Generated ExampleShapeCombiner

func NewShapeCombiner

func NewShapeCombiner(src1, src2 Field, shape *graphics2d.Shape) *ShapeCombiner

func (*ShapeCombiner) Eval2

func (s *ShapeCombiner) Eval2(x, y float64) float64

type ShapeCombinerCF

type ShapeCombinerCF struct {
	Name  string
	Src1  ColorField
	Src2  ColorField
	Shape *graphics2d.Shape
}

func NewShapeCombinerCF

func NewShapeCombinerCF(src1, src2 ColorField, shape *graphics2d.Shape) *ShapeCombinerCF

func (*ShapeCombinerCF) Eval2

func (s *ShapeCombinerCF) Eval2(x, y float64) color.Color

type ShapeCombinerVF

type ShapeCombinerVF struct {
	Name  string
	Src1  VectorField
	Src2  VectorField
	Shape *graphics2d.Shape
}

func NewShapeCombinerVF

func NewShapeCombinerVF(src1, src2 VectorField, shape *graphics2d.Shape) *ShapeCombinerVF

func (*ShapeCombinerVF) Eval2

func (s *ShapeCombinerVF) Eval2(x, y float64) []float64

type ShapeStyle

type ShapeStyle int
const (
	BinaryStyle ShapeStyle = iota
	PathSumStyle
	PathOccStyle
)

Constants for shape styles

type Squares

type Squares struct {
	Name  string
	Scale float64
}
Example
package main

import (
	"fmt"
	"github.com/jphsd/graphics2d/image"
	"github.com/jphsd/texture"
)

func main() {
	f := texture.NewSquares(40)

	img := texture.NewTextureGray16(600, 600, f, 0, 0, 1, 1, false)
	image.SaveImage(img, "ExampleSquares")
	fmt.Printf("Generated ExampleSquares")
}
Output:
Generated ExampleSquares

func NewSquares

func NewSquares(s float64) *Squares

func (*Squares) Eval2

func (s *Squares) Eval2(x, y float64) float64

type StochasticBlend

type StochasticBlend struct {
	Name string
	Src1 Field
	Src2 Field
	Src3 Field
}

func NewStochasticBlend

func NewStochasticBlend(src1, src2, src3 Field) *StochasticBlend

func (*StochasticBlend) Eval2

func (b *StochasticBlend) Eval2(x, y float64) float64

Eval2 implements the Field interface.

type StochasticTiler

type StochasticTiler struct {
	Name   string
	Srcs   []Field
	Domain []float64
	// contains filtered or unexported fields
}

func NewStochasticTiler

func NewStochasticTiler(srcs []Field, dom []float64) *StochasticTiler

func (*StochasticTiler) Eval2

func (t *StochasticTiler) Eval2(x, y float64) float64

type StochasticTilerCF

type StochasticTilerCF struct {
	Name   string
	Srcs   []ColorField
	Domain []float64
	// contains filtered or unexported fields
}

func NewStochasticTilerCF

func NewStochasticTilerCF(srcs []ColorField, dom []float64) *StochasticTilerCF

func (*StochasticTilerCF) Eval2

func (t *StochasticTilerCF) Eval2(x, y float64) color.Color

type StochasticTilerVF

type StochasticTilerVF struct {
	Name   string
	Srcs   []VectorField
	Domain []float64
	// contains filtered or unexported fields
}

func NewStochasticTilerVF

func NewStochasticTilerVF(srcs []VectorField, dom []float64) *StochasticTilerVF

func (*StochasticTilerVF) Eval2

func (t *StochasticTilerVF) Eval2(x, y float64) []float64

type Strip

type Strip struct {
	Name  string
	Src   Field
	Value float64
}

func NewStrip

func NewStrip(src Field, y float64) *Strip

func (*Strip) Eval

func (s *Strip) Eval(x float64) float64

func (*Strip) Eval2

func (s *Strip) Eval2(x, y float64) float64

func (*Strip) Lambda

func (s *Strip) Lambda() float64

type StripCF

type StripCF struct {
	Name  string
	Src   ColorField
	Value float64
}

func NewStripCF

func NewStripCF(src ColorField, y float64) *StripCF

func (*StripCF) Eval2

func (s *StripCF) Eval2(x, y float64) color.Color

type StripVF

type StripVF struct {
	Name  string
	Src   VectorField
	Value float64
}

func NewStripVF

func NewStripVF(src VectorField, y float64) *StripVF

func (*StripVF) Eval2

func (s *StripVF) Eval2(x, y float64) []float64

type SubCombiner

type SubCombiner struct {
	Name string
	Src1 Field
	Src2 Field
	Offs float64
	Scal float64
}

SubCombiner is a subtracting combiner (clamped).

func NewSubCombiner

func NewSubCombiner(src1, src2 Field) *SubCombiner

func (*SubCombiner) Eval2

func (c *SubCombiner) Eval2(x, y float64) float64

Eval2 implements the Field interface.

type SubstituteCombiner

type SubstituteCombiner struct {
	Name string
	Src1 Field
	Src2 Field
	Src3 Field
	A, B float64
}

SubstituteCombiner combines two fields based on the supplied values.

func NewSubstituteCombiner

func NewSubstituteCombiner(src1, src2, src3 Field, a, b float64) *SubstituteCombiner

func (*SubstituteCombiner) Eval2

func (c *SubstituteCombiner) Eval2(x, y float64) float64

Eval2 implements the Field interface.

type SwirlWF

type SwirlWF struct {
	Name   string
	Center []float64 // Center of warp
	Scale  float64   // Scale factor
}

SwirlWF performs a swirl warp around Center in x for use in the above warp types. The cordinates are converted to polar (r, th) and th advanced by scale * r.

func NewSwirlWF

func NewSwirlWF(c []float64, s float64) *SwirlWF

func (*SwirlWF) Eval

func (wf *SwirlWF) Eval(x, y float64) (float64, float64)

Eval implements the WarpFunc interface

type TextureGray16

type TextureGray16 struct {
	Src    Field
	Rect   image.Rectangle
	Img    *image.Gray16 // Evaluated pixels
	Stride int
	Ox, Oy float64
	Dx, Dy float64
	// contains filtered or unexported fields
}

TextureGray16 is a lazily evaluated Gray16 image. For expensive textures this allows only the requested pixels to be calculated, and not the entire image.

func NewConicGray16

func NewConicGray16(w, h int, c []float64, th float64, wf *NonLinear) *TextureGray16

func NewEllipticalGray16

func NewEllipticalGray16(w, h int, c []float64, rx, ry, th float64, wf *NonLinear, mirror, once bool) *TextureGray16

func NewLinearGray16

func NewLinearGray16(w, h int, p1, p2 []float64, wf *NonLinear, mirror, once bool) *TextureGray16

func NewRadialGray16

func NewRadialGray16(w, h int, c []float64, r float64, wf *NonLinear, mirror, once bool) *TextureGray16

func NewTextureGray16

func NewTextureGray16(width, height int, src Field, ox, oy, dx, dy float64, cache bool) *TextureGray16

NewTextureGray16 creates a new TextureGray16 from the supplied parameters

func (*TextureGray16) At

func (t *TextureGray16) At(x, y int) color.Color

At implements the At function in the Image interface.

func (*TextureGray16) Bounds

func (t *TextureGray16) Bounds() image.Rectangle

Bounds implements the Bounds function in the Image interface.

func (*TextureGray16) ColorModel

func (t *TextureGray16) ColorModel() color.Model

ColorModel implements the ColorModel function in the Image interface.

func (*TextureGray16) Gray16At

func (t *TextureGray16) Gray16At(x, y int) color.Color

type TextureRGBA

type TextureRGBA struct {
	Src    ColorField
	Rect   image.Rectangle
	Img    *image.RGBA // Evaluated pixels
	Stride int
	Ox, Oy float64
	Dx, Dy float64
	// contains filtered or unexported fields
}

TextureRGBA is a lazily evaluated RGBA image. For expensive textures this allows only the requested pixels to be calculated, and not the entire image.

func NewTextureRGBA

func NewTextureRGBA(width, height int, src ColorField, ox, oy, dx, dy float64, cache bool) *TextureRGBA

NewTextureRGBA creates a new TextureRGBA from the supplied parameters

func (*TextureRGBA) At

func (t *TextureRGBA) At(x, y int) color.Color

At implements the At function in the Image interface.

func (*TextureRGBA) Bounds

func (t *TextureRGBA) Bounds() image.Rectangle

Bounds implements the Bounds function in the Image interface.

func (*TextureRGBA) ColorModel

func (t *TextureRGBA) ColorModel() color.Model

ColorModel implements the ColorModel function in the Image interface.

func (*TextureRGBA) RGBAAt

func (t *TextureRGBA) RGBAAt(x, y int) color.Color

type TextureRGBA64

type TextureRGBA64 struct {
	Src    ColorField
	Rect   image.Rectangle
	Img    *image.RGBA64 // Evaluated pixels
	Stride int
	Ox, Oy float64
	Dx, Dy float64
	// contains filtered or unexported fields
}

TextureRGBA64 is a lazily evaluated RGBA64 image. For expensive textures this allows only the requested pixels to be calculated, and not the entire image.

func NewTextureRGBA64

func NewTextureRGBA64(width, height int, src ColorField, ox, oy, dx, dy float64, cache bool) *TextureRGBA64

NewTextureRGBA64 creates a new TextureRGBA64 from the supplied parameters

func (*TextureRGBA64) At

func (t *TextureRGBA64) At(x, y int) color.Color

At implements the At function in the Image interface.

func (*TextureRGBA64) Bounds

func (t *TextureRGBA64) Bounds() image.Rectangle

Bounds implements the Bounds function in the Image interface.

func (*TextureRGBA64) ColorModel

func (t *TextureRGBA64) ColorModel() color.Model

ColorModel implements the ColorModel function in the Image interface.

func (*TextureRGBA64) RGBA64At

func (t *TextureRGBA64) RGBA64At(x, y int) color.Color

type ThresholdCombiner

type ThresholdCombiner struct {
	Name string
	Src1 Field
	Src2 Field
	Src3 Field
	A    float64
}

ThresholdCombiner selects between two sources based on whether src3 exceeds A.

func NewThresholdCombiner

func NewThresholdCombiner(src1, src2, src3 Field, a float64) *ThresholdCombiner

func (*ThresholdCombiner) Eval2

func (c *ThresholdCombiner) Eval2(x, y float64) float64

Eval2 implements the Field interface.

type ThresholdFilter

type ThresholdFilter struct {
	Name    string
	Src     Field
	A, B, C float64
}

ThresholdFilter returns B if src < A, and C if equal or greater. See also ThresholdCombiner.

func NewThresholdFilter

func NewThresholdFilter(src Field, a, b, c float64) *ThresholdFilter

func (*ThresholdFilter) Eval2

func (f *ThresholdFilter) Eval2(x, y float64) float64

Eval2 implements the Field interface.

type Tiler

type Tiler struct {
	Name   string
	Src    Field
	Domain []float64
}
Example
package main

import (
	"fmt"
	"github.com/jphsd/graphics2d"
	"github.com/jphsd/graphics2d/image"
	"github.com/jphsd/texture"
)

func main() {
	nl := texture.NewNLCircle1()
	w := texture.NewNLWave([]float64{47}, []*texture.NonLinear{nl}, false, true)
	iw := texture.NewInvertWave(w)
	f := texture.NewRadialGradient(iw)

	xfm := graphics2d.Translate(-50, -50)
	f2 := texture.NewTransform(f, xfm)

	f3 := texture.NewTiler(f2, []float64{100, 100})

	img := texture.NewTextureGray16(600, 600, f3, 0, 0, 1, 1, false)
	image.SaveImage(img, "ExampleTiler")
	fmt.Printf("Generated ExampleTiler")
}
Output:
Generated ExampleTiler

func NewTiler

func NewTiler(src Field, dom []float64) *Tiler

func (*Tiler) Eval2

func (t *Tiler) Eval2(x, y float64) float64

type TilerCF

type TilerCF struct {
	Name   string
	Src    ColorField
	Domain []float64
}

func NewTilerCF

func NewTilerCF(src ColorField, dom []float64) *TilerCF

func (*TilerCF) Eval2

func (t *TilerCF) Eval2(x, y float64) color.Color

type TilerVF

type TilerVF struct {
	Name   string
	Src    VectorField
	Domain []float64
}

func NewTilerVF

func NewTilerVF(src VectorField, dom []float64) *TilerVF

func (*TilerVF) Eval2

func (t *TilerVF) Eval2(x, y float64) []float64

type TopHat

type TopHat struct {
	Name string
	Src1 Field
	Src2 Field
}

TopHat - orig - O

func NewTopHat

func NewTopHat(src Field, supp [][]float64) *TopHat

func (*TopHat) Eval2

func (m *TopHat) Eval2(x, y float64) float64

type Transform

type Transform struct {
	Name string
	Src  Field
	Xfm  *g2d.Aff3
}

Transform applies an affine transform to the values passed into the Eval2 function.

Example
package main

import (
	"fmt"
	"github.com/jphsd/graphics2d"
	"github.com/jphsd/graphics2d/image"
	"github.com/jphsd/texture"
	"math"
)

func main() {
	f := texture.NewTriangles(40)

	// Apply a transform to convert to equilateral triangles
	xfm := graphics2d.Rotate(-math.Pi / 4)
	xfm.Scale(math.Sqrt2, 1)
	f2 := texture.NewTransform(f, xfm)

	img := texture.NewTextureGray16(600, 600, f2, 0, 0, 1, 1, false)
	image.SaveImage(img, "ExampleTransform")
	fmt.Printf("Generated ExampleTransform")
}
Output:
Generated ExampleTransform

func NewTransform

func NewTransform(src Field, xfm *g2d.Aff3) *Transform

func (*Transform) Eval2

func (t *Transform) Eval2(x, y float64) float64

Eval2 implements the Field interface.

type TransformCF

type TransformCF struct {
	Name string
	Src  ColorField
	Xfm  *g2d.Aff3
}

TransformCF applies an affine transform to the values passed into the Eval2 function.

func NewTransformCF

func NewTransformCF(src ColorField, xfm *g2d.Aff3) *TransformCF

func (*TransformCF) Eval2

func (t *TransformCF) Eval2(x, y float64) color.Color

Eval2 implements the ColorField interface.

type TransformVF

type TransformVF struct {
	Name string
	Src  VectorField
	Xfm  *g2d.Aff3
}

TransformVF applies an affine transform to the values passed into the Eval2 function.

func NewTransformVF

func NewTransformVF(src VectorField, xfm *g2d.Aff3) *TransformVF

func (*TransformVF) Eval2

func (t *TransformVF) Eval2(x, y float64) []float64

Eval2 implements the VectorField interface.

type Triangles

type Triangles struct {
	Name  string
	Scale float64
}
Example
package main

import (
	"fmt"
	"github.com/jphsd/graphics2d/image"
	"github.com/jphsd/texture"
)

func main() {
	f := texture.NewTriangles(40)

	img := texture.NewTextureGray16(600, 600, f, 0, 0, 1, 1, false)
	image.SaveImage(img, "ExampleTriangles")
	fmt.Printf("Generated ExampleTriangles")
}
Output:
Generated ExampleTriangles

func NewTriangles

func NewTriangles(s float64) *Triangles

func (*Triangles) Eval2

func (t *Triangles) Eval2(x, y float64) float64

type Uniform

type Uniform struct {
	Name  string
	Value float64
}

func NewUniform

func NewUniform(v float64) *Uniform

func (*Uniform) Eval2

func (f *Uniform) Eval2(x, y float64) float64

type UniformCF

type UniformCF struct {
	Name  string
	Value color.Color
}

func NewUniformCF

func NewUniformCF(v color.Color) *UniformCF

func (*UniformCF) Eval2

func (f *UniformCF) Eval2(x, y float64) color.Color

type UniformVF

type UniformVF struct {
	Name  string
	Value []float64
}

func NewUniformVF

func NewUniformVF(v []float64) *UniformVF

func (*UniformVF) Eval2

func (f *UniformVF) Eval2(x, y float64) []float64

type UnitVector

type UnitVector struct {
	Name string
	Src  VectorField
}

UnitVector provides a unit vector (i.e. magnitude = 1) version of a VectorField.

func (*UnitVector) Eval2

func (u *UnitVector) Eval2(x, y float64) []float64

Eval2 implements the VectorField interface.

type VariableFractal

type VariableFractal struct {
	Name    string
	Src     Field
	Xfm     *g2d.Aff3
	Comb    OctaveCombiner
	OctSrc  Field
	Scale   float64
	Weights []float64
}

func NewVariableFractal

func NewVariableFractal(src Field, xfm *g2d.Aff3, comb OctaveCombiner, octsrc Field, scale float64) *VariableFractal

NewFractal returns a new Fractal instance.

func (*VariableFractal) Eval2

func (f *VariableFractal) Eval2(x, y float64) float64

Eval2 implements the Field interface.

type VectorColor

type VectorColor struct {
	Name string
	Src  ColorField
}

VectorColor uses the three values from a color field to populate it.

func NewVectorColor

func NewVectorColor(src ColorField) *VectorColor

func (*VectorColor) Eval2

func (v *VectorColor) Eval2(x, y float64) []float64

Eval2 implements the VectorField interface.

type VectorField

type VectorField interface {
	Eval2(x, y float64) []float64
}

VectorField defines an evaluation method that given an x and y value, returns a slice of values in the range [-1,1].

type VectorFields

type VectorFields struct {
	Name string
	Srcs []Field
}

VectorFields produces a vector field from a slice of fields

func NewVectorFields

func NewVectorFields(srcs ...Field) *VectorFields

func (*VectorFields) Eval2

func (v *VectorFields) Eval2(x, y float64) []float64

Eval2 implements the VectorField interface.

type Warp

type Warp struct {
	Name string
	Src  Field
	Func WarpFunc
}

Warp applies a deformation to the values passed into the Eval2 function.

Example (Drain)
package main

import (
	"fmt"
	"github.com/jphsd/graphics2d/image"
	"github.com/jphsd/texture"
	"math"
)

func main() {
	f := texture.NewSquares(40)

	rwf := texture.NewDrainWF([]float64{300, 300}, math.Pi, 250)

	f2 := texture.NewWarp(f, rwf)

	img := texture.NewTextureGray16(600, 600, f2, 0, 0, 1, 1, false)
	image.SaveImage(img, "ExampleWarp_drain")
	fmt.Printf("Generated ExampleWarp_drain")
}
Output:
Generated ExampleWarp_drain
Example (Pinch)
package main

import (
	"fmt"
	"github.com/jphsd/graphics2d/image"
	"github.com/jphsd/texture"
)

func main() {
	f := texture.NewSquares(40)

	rwf := texture.NewPinchXWF([]float64{300, 300}, 0.3, 0.002, 2)

	f2 := texture.NewWarp(f, rwf)

	img := texture.NewTextureGray16(600, 600, f2, 0, 0, 1, 1, false)
	image.SaveImage(img, "ExampleWarp_pinch")
	fmt.Printf("Generated ExampleWarp_pinch")
}
Output:
Generated ExampleWarp_pinch
Example (Radial)
package main

import (
	"fmt"
	"github.com/jphsd/graphics2d/image"
	"github.com/jphsd/texture"
)

func main() {
	f := texture.NewSquares(40)

	rwf := texture.NewRadialWF([]float64{300, 300}, 1, 1)

	f2 := texture.NewWarp(f, rwf)

	img := texture.NewTextureGray16(600, 600, f2, 0, 0, 1, 1, false)
	image.SaveImage(img, "ExampleWarp_radial")
	fmt.Printf("Generated ExampleWarp_radial")
}
Output:
Generated ExampleWarp_radial
Example (Radialnl1)
package main

import (
	"fmt"
	"github.com/jphsd/graphics2d/image"
	"github.com/jphsd/texture"
)

func main() {
	f := texture.NewSquares(40)

	rwf := texture.NewRadialNLWF([]float64{300, 300}, texture.NewNLExponential(3), 300)

	f2 := texture.NewWarp(f, rwf)

	img := texture.NewTextureGray16(600, 600, f2, 0, 0, 1, 1, false)
	image.SaveImage(img, "ExampleWarp_radialnl1")
	fmt.Printf("Generated ExampleWarp_radialnl1")
}
Output:
Generated ExampleWarp_radialnl1
Example (Radialnl2)
package main

import (
	"fmt"
	"github.com/jphsd/graphics2d/image"
	"github.com/jphsd/texture"
)

func main() {
	f := texture.NewSquares(40)

	rwf := texture.NewRadialNLWF([]float64{300, 300}, texture.NewNLLogarithmic(3), 300)

	f2 := texture.NewWarp(f, rwf)

	img := texture.NewTextureGray16(600, 600, f2, 0, 0, 1, 1, false)
	image.SaveImage(img, "ExampleWarp_radialnl2")
	fmt.Printf("Generated ExampleWarp_radialnl2")
}
Output:
Generated ExampleWarp_radialnl2
Example (Radialripple)
package main

import (
	"fmt"
	"github.com/jphsd/graphics2d/image"
	"github.com/jphsd/texture"
)

func main() {
	f := texture.NewSquares(40)

	rwf := texture.NewRadialRippleWF([]float64{300, 300}, 100, 10, 0)

	f2 := texture.NewWarp(f, rwf)

	img := texture.NewTextureGray16(600, 600, f2, 0, 0, 1, 1, false)
	image.SaveImage(img, "ExampleWarp_radialripple")
	fmt.Printf("Generated ExampleWarp_radialripple")
}
Output:
Generated ExampleWarp_radialripple
Example (Radialwriggle)
package main

import (
	"fmt"
	"github.com/jphsd/graphics2d/image"
	"github.com/jphsd/texture"
)

func main() {
	f := texture.NewSquares(40)

	rwf := texture.NewRadialWiggleWF([]float64{300, 300}, 100, 0.1, 0)

	f2 := texture.NewWarp(f, rwf)

	img := texture.NewTextureGray16(600, 600, f2, 0, 0, 1, 1, false)
	image.SaveImage(img, "ExampleWarp_radialwriggle")
	fmt.Printf("Generated ExampleWarp_radialwriggle")
}
Output:
Generated ExampleWarp_radialwriggle
Example (Ripple)
package main

import (
	"fmt"
	"github.com/jphsd/graphics2d/image"
	"github.com/jphsd/texture"
)

func main() {
	f := texture.NewSquares(40)

	rwf := texture.NewRippleXWF(100, 20, 12.5)

	f2 := texture.NewWarp(f, rwf)

	img := texture.NewTextureGray16(600, 600, f2, 0, 0, 1, 1, false)
	image.SaveImage(img, "ExampleWarp_ripple")
	fmt.Printf("Generated ExampleWarp_ripple")
}
Output:
Generated ExampleWarp_ripple
Example (Swirl)
package main

import (
	"fmt"
	"github.com/jphsd/graphics2d/image"
	"github.com/jphsd/texture"
)

func main() {
	f := texture.NewSquares(40)

	rwf := texture.NewSwirlWF([]float64{300, 300}, -0.05)

	f2 := texture.NewWarp(f, rwf)

	img := texture.NewTextureGray16(600, 600, f2, 0, 0, 1, 1, false)
	image.SaveImage(img, "ExampleWarp_swirl")
	fmt.Printf("Generated ExampleWarp_swirl")
}
Output:
Generated ExampleWarp_swirl

func NewWarp

func NewWarp(src Field, wf WarpFunc) *Warp

func (*Warp) Eval2

func (w *Warp) Eval2(x, y float64) float64

Eval2 implements the Field interface.

type WarpCF

type WarpCF struct {
	Name string
	Src  ColorField
	Func WarpFunc
}

WarpCF applies a deformation to the values passed into the Eval2 function.

func NewWarpCF

func NewWarpCF(src ColorField, wf WarpFunc) *WarpCF

func (*WarpCF) Eval2

func (w *WarpCF) Eval2(x, y float64) color.Color

Eval2 implements the ColorField interface.

type WarpFunc

type WarpFunc interface {
	Eval(x, y float64) (float64, float64)
}

type WarpVF

type WarpVF struct {
	Name string
	Src  VectorField
	Func WarpFunc
}

WarpVF applies a deformation to the values passed into the Eval2 function.

func NewWarpVF

func NewWarpVF(src VectorField, wf WarpFunc) *WarpVF

func (*WarpVF) Eval2

func (w *WarpVF) Eval2(x, y float64) []float64

Eval2 implements the VectorField interface.

type Wave

type Wave interface {
	Eval(v float64) float64
	Lambda() float64
}

type Weighted

type Weighted struct {
	Name    string
	Src     VectorField
	Weights []float64
}

Weighted converts a VectorField to a field by selecting one of its components.

func NewWeighted

func NewWeighted(src VectorField, w []float64) *Weighted

func (*Weighted) Eval2

func (w *Weighted) Eval2(x, y float64) float64

Eval2 implements the Field interface.

type WeightedCombiner

type WeightedCombiner struct {
	Name string
	Src1 Field
	Src2 Field
	A, B float64
}

WeightedfCombiner combines two fields based on the supplied values.

func NewWeightedCombiner

func NewWeightedCombiner(src1, src2 Field, a, b float64) *WeightedCombiner

func (*WeightedCombiner) Eval2

func (c *WeightedCombiner) Eval2(x, y float64) float64

Eval2 implements the Field interface.

type WindowedCombiner

type WindowedCombiner struct {
	Name string
	Src1 Field
	Src2 Field
	A, B float64
}

WindowedfCombiner combines two fields based on the window values.

func NewWindowedCombiner

func NewWindowedCombiner(src1, src2 Field, a, b float64) *WindowedCombiner

func (*WindowedCombiner) Eval2

func (c *WindowedCombiner) Eval2(x, y float64) float64

Eval2 implements the Field interface.

type WorleyField

type WorleyField struct {
	Name   string
	Points [][]float64
	A      []float64
	B      []float64
	F      func(float64) float64
	Scale  float64
	Offset float64
	// contains filtered or unexported fields
}

WorleyField implements the ideas from Worley's 1996 paper, A Cellular Texture Basis Function. In Worley's paper, the D() is the Euclidean distance function, F() is the identity function, all A are 1 and B determines the weights based on the distance from the point being queried.

func NewWorleyField

func NewWorleyField(points [][]float64, a, b []float64,
	d func([]float64, []float64) float64, f func(float64) float64,
	scale, offset float64) *WorleyField

func (*WorleyField) Eval2

func (pf *WorleyField) Eval2(x, y float64) float64

Eval2 implements the Field interface.

Directories

Path Synopsis
Package color contains types and functions for color management.
Package color contains types and functions for color management.
Package random contains functions, MakeXXX, that can be used to create a random texture tree.
Package random contains functions, MakeXXX, that can be used to create a random texture tree.
Package surface contains functions that populate images with lit textured surfaces.
Package surface contains functions that populate images with lit textured surfaces.

Jump to

Keyboard shortcuts

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