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:
- Field (F) which maintains a field of float64, in the range [-1,1]
- VectorField (VF) which maintains a field of slice of float64, typically a triplet
- 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.
- Binary grid based binary noise
- BlinnField metaballs. See Blinn82
- BlockNoise rectangular block noise
- WorleyField cellular basis functions. See Worley96
4.8 Third Party Generators (F) ¶
- OpenSimplex open simplex noise
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
- AbsFilter applies math.Abs so the value will be in [0,1]
- CeilFilter limits the value to [-1,C]
- ClipFilter limits the value to [-1,1]
- Convolution calculates value by applying a kernel to the source
- FloorFilter limits the value to [C,1]
- FoldFilter 'folds' a value outside of [-1,1] back in on itself
- InvertFilter applies 0 - value
- Morphological Erode, Dilate, EdgeIn, EdgeOut, Edge, Close, Open, TopHat, BottomHat
- NLFilter applies a NonLinear to value
- OffsScaleFilter applies A * (B + value)
- QuantizeFilter quantizes the value
- RandQuantFilter like QuantizeFilter but the values are scrambled
- RemapFilter maps the value to the new domain [A,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) ¶
- MulCombiner src1 * src2
- AddCombiner src1 + src2
- SubCombiner src1 - src2
- MinCombiner min(src1, src2)
- MaxCombiner max(src1, src2)
- AvgCombiner (src1 + src2) / 2
- DiffCombiner (1 - t) * src1 + t * src2, where t = (2 + src1 - src2) / 4
- WindowedCombiner if src1 < A or src1 > B, src1, otherwise src2
- WeightedCombiner src1 * A + src2 * B
- Blend (1 - t) * src1 + t * src2, where t = (1 + src3) / 2
- StochasticBlend src2 if random float < src3, src1 otherwise
- JitterBlend as for Blend but with jitter added to t
- SubstituteCombiner src1 if src3 < A or src3 > B, otherwise src2
- ShapeCombiner src1 if location inside of shape, src2 otherwise
- ThresholdCombiner src1 if less than threshold A, src2 otherwise
6.2 Vector Combiners (VF) ¶
- ShapeCombinerVF src1 if location inside of shape, src2 otherwise
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.
- Fractal standard fractal
- VariableFractal fractal with octaves derived from a source field
Two OctaveCombiner are provided
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:
- NLWave multiple wave shapes with varying wave lengths
- DCWave one wave shape for the rising edge and one for the falling edge
- ACWave a wave shape per quadrant
- 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.
- TextureGray16 takes a value field
- TextureRGBA takes a color field
- TextureRGBA64 takes a color field
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.
- NewLinearGray16
- NewRadialGray16
- NewEllipticalGray16
- NewConicGray16
- NewLinearRGBA
- NewRadialRGBA
- NewEllipticalRGBA
- NewConicRGBA
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 ¶
- Variables
- func ColorRGBABiLerp(u, v float64, colors []color.Color) color.RGBA
- func Cubic(t float64, p []float64) float64
- func Linear(t float64, p []float64) float64
- func MapValueToLambda(v, lambda float64) (int, float64)
- func Nearest(t float64, p []float64) float64
- func NewConicRGBA(w, h int, c []float64, th float64, c1, c2 color.Color, wf *NonLinear) *image.Colorizer
- func NewEllipticalRGBA(w, h int, c []float64, rx, ry, th float64, c1, c2 color.Color, wf *NonLinear, ...) *image.Colorizer
- func NewLinearRGBA(w, h int, p1, p2 []float64, c1, c2 color.Color, wf *NonLinear, ...) *image.Colorizer
- func NewRadialRGBA(w, h int, c []float64, r float64, c1, c2 color.Color, wf *NonLinear, ...) *image.Colorizer
- func P3(t float64, p []float64) float64
- func P5(t float64, p []float64) float64
- func SaveJSON(v any, name string) error
- func X3Support(sx, sy float64) [][]float64
- func Z4Support(sx, sy float64) [][]float64
- func Z8Support(sx, sy float64) [][]float64
- type ACWave
- type AbsFilter
- type AddCombiner
- type AvgCombiner
- type Binary
- type Blend
- type BlinnField
- type BlockNoise
- type BottomHat
- type Cache
- type CeilFilter
- type ClipFilter
- type Close
- type ColorBlend
- type ColorConv
- type ColorField
- type ColorFields
- type ColorGray
- type ColorSelect
- type ColorSinCos
- type ColorSubstitute
- type ColorToGray
- type ColorVector
- type Component
- type ConicGradient
- type Convolution
- type DCWave
- type DiffCombiner
- type Dilate
- type Direction
- type Displace
- type Displace2
- type Displace2CF
- type Displace2VF
- type DisplaceCF
- type DisplaceVF
- type Distort
- type DrainWF
- type Edge
- type EdgeIn
- type EdgeOut
- type Erode
- type FBM
- type Field
- type FloorFilter
- type FoldFilter
- type Fractal
- type Hexagons
- type IFS
- type IFSCombiner
- type Image
- type Interp
- type InvertFilter
- type InvertWave
- type JitterBlend
- type LerpType
- type LinearGradient
- type MF
- type Magnitude
- type MaxCombiner
- type MinCombiner
- type MulCombiner
- type NLFilter
- type NLWave
- type NonLinear
- func NewNLCatenary() *NonLinear
- func NewNLCircle1() *NonLinear
- func NewNLCircle2() *NonLinear
- func NewNLCube() *NonLinear
- func NewNLExponential(v float64) *NonLinear
- func NewNLGauss(v float64) *NonLinear
- func NewNLLinear() *NonLinear
- func NewNLLogarithmic(v float64) *NonLinear
- func NewNLLogistic(u, v float64) *NonLinear
- func NewNLP3() *NonLinear
- func NewNLP5() *NonLinear
- func NewNLSin() *NonLinear
- func NewNLSin1() *NonLinear
- func NewNLSin2() *NonLinear
- func NewNLSquare() *NonLinear
- type Normal
- type OctaveCombiner
- type OffsScaleFilter
- type Open
- type PatternWave
- type Perlin
- type PinchXWF
- type Pixelate
- type PixelateCF
- type PixelateVF
- type QuantizeFilter
- type RadialGradient
- type RadialNLWF
- type RadialRippleWF
- type RadialWF
- type RadialWiggleWF
- type RandQuantFilter
- type Reflect
- type ReflectCF
- type ReflectVF
- type RemapFilter
- type RippleXWF
- type Select
- type Shape
- type ShapeCombiner
- type ShapeCombinerCF
- type ShapeCombinerVF
- type ShapeStyle
- type Squares
- type StochasticBlend
- type StochasticTiler
- type StochasticTilerCF
- type StochasticTilerVF
- type Strip
- type StripCF
- type StripVF
- type SubCombiner
- type SubstituteCombiner
- type SwirlWF
- type TextureGray16
- func NewConicGray16(w, h int, c []float64, th float64, wf *NonLinear) *TextureGray16
- func NewEllipticalGray16(w, h int, c []float64, rx, ry, th float64, wf *NonLinear, mirror, once bool) *TextureGray16
- func NewLinearGray16(w, h int, p1, p2 []float64, wf *NonLinear, mirror, once bool) *TextureGray16
- func NewRadialGray16(w, h int, c []float64, r float64, wf *NonLinear, mirror, once bool) *TextureGray16
- func NewTextureGray16(width, height int, src Field, ox, oy, dx, dy float64, cache bool) *TextureGray16
- type TextureRGBA
- type TextureRGBA64
- type ThresholdCombiner
- type ThresholdFilter
- type Tiler
- type TilerCF
- type TilerVF
- type TopHat
- type Transform
- type TransformCF
- type TransformVF
- type Triangles
- type Uniform
- type UniformCF
- type UniformVF
- type UnitVector
- type VariableFractal
- type VectorColor
- type VectorField
- type VectorFields
- type Warp
- type WarpCF
- type WarpFunc
- type WarpVF
- type Wave
- type Weighted
- type WeightedCombiner
- type WindowedCombiner
- type WorleyField
Examples ¶
- Package (Decay)
- Package (Flames)
- Blend
- ConicGradient
- Displace
- Distort
- Fractal (Fbm)
- Fractal (Mf)
- Hexagons
- LinearGradient (Circular)
- LinearGradient (Saw)
- LinearGradient (Sine)
- LinearGradient (Triangle)
- MaxCombiner
- MulCombiner
- Perlin
- RadialGradient (Circular)
- RadialGradient (Saw)
- RadialGradient (Sine)
- RadialGradient (Triangle)
- Reflect
- Shape
- ShapeCombiner
- Squares
- Tiler
- Transform
- Triangles
- Warp (Drain)
- Warp (Pinch)
- Warp (Radial)
- Warp (Radialnl1)
- Warp (Radialnl2)
- Warp (Radialripple)
- Warp (Radialwriggle)
- Warp (Ripple)
- Warp (Swirl)
Constants ¶
This section is empty.
Variables ¶
var DefaultNormal = &UniformVF{"UniformVF", []float64{0, 0, 1}}
DefaultNormal describes the unit normal point straight up from the XY plane.
Functions ¶
func ColorRGBABiLerp ¶
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 ¶
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 ¶
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 Nearest ¶
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 NewEllipticalRGBA ¶
func NewLinearRGBA ¶
func NewRadialRGBA ¶
func P3 ¶
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
Types ¶
type ACWave ¶
type AddCombiner ¶
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 ¶
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 Blend ¶
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
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 (*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 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.
type CeilFilter ¶
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 ¶
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 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
type ColorField ¶
ColorField defines an evaluation method that given an x and y value, returns a Color.
type ColorFields ¶
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
type ColorGray ¶
ColorGray contains the field to use in the color evaluation and produces a grayscale color.
func NewColorGray ¶
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 ¶
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
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
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
type Component ¶
type Component struct {
Name string
Value Field
Vector VectorField
Color ColorField
}
Component composes a value, vector and color field.
func NewComponent ¶
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 ¶
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 ¶
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 DiffCombiner ¶
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 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
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 ¶
NewDisplace creates a new Displace instance using the same transform for both x and y displacements.
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.
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.
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.
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 ¶
NewDistort creates a new Distort instance.
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 ¶
type FBM ¶
FBM holds the precomputed weights for an fBM.
type Field ¶
Field defines an evaluation method that given an x and y value, returns a value in the range [-1,1].
type FloorFilter ¶
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 ¶
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 ¶
NewFractal returns a new Fractal instance.
type Hexagons ¶
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 ¶
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.
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 ¶
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.
type InvertFilter ¶
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 ¶
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 ¶
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 LinearGradient ¶
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 ¶
MF holds the precomputed weights and offset for an multifractal.
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
type MaxCombiner ¶
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 ¶
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 ¶
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 NLWave ¶
type NonLinear ¶
func NewNLCatenary ¶
func NewNLCatenary() *NonLinear
func NewNLCircle1 ¶
func NewNLCircle1() *NonLinear
func NewNLCircle2 ¶
func NewNLCircle2() *NonLinear
func NewNLExponential ¶
func NewNLGauss ¶
func NewNLLinear ¶
func NewNLLinear() *NonLinear
func NewNLLogarithmic ¶
func NewNLLogistic ¶
func NewNLSquare ¶
func NewNLSquare() *NonLinear
type Normal ¶
Normal provides a VectorField calculated from a Field using the finite difference method.
type OctaveCombiner ¶
type OffsScaleFilter ¶
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 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 ¶
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
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 ¶
type Pixelate ¶
Pixelate provides pixelation for a field.
func NewPixelate ¶
NewPixelate creates a new Pixelate with the specified resolution.
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.
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 ¶
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 ¶
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
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
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 ¶
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
type RandQuantFilter ¶
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 ¶
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 ¶
NewReflect creates a new Reflection placing the mirror along lp1, lp2.
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.
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.
type RemapFilter ¶
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 ¶
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 ¶
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.
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
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
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 ¶
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 ¶
type StochasticBlend ¶
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
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 StripCF ¶
type StripCF struct {
Name string
Src ColorField
Value float64
}
func NewStripCF ¶
func NewStripCF(src ColorField, y float64) *StripCF
type StripVF ¶
type StripVF struct {
Name string
Src VectorField
Value float64
}
func NewStripVF ¶
func NewStripVF(src VectorField, y float64) *StripVF
type SubCombiner ¶
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 ¶
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 ¶
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 NewLinearGray16 ¶
func NewLinearGray16(w, h int, p1, p2 []float64, wf *NonLinear, mirror, once bool) *TextureGray16
func NewRadialGray16 ¶
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.
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.
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.
type ThresholdCombiner ¶
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 ¶
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 ¶
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
type TilerCF ¶
type TilerCF struct {
Name string
Src ColorField
Domain []float64
}
func NewTilerCF ¶
func NewTilerCF(src ColorField, dom []float64) *TilerCF
type TilerVF ¶
type TilerVF struct {
Name string
Src VectorField
Domain []float64
}
func NewTilerVF ¶
func NewTilerVF(src VectorField, dom []float64) *TilerVF
type Transform ¶
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
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
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 ¶
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 ¶
type Uniform ¶
func NewUniform ¶
type UniformCF ¶
func NewUniformCF ¶
type UniformVF ¶
func NewUniformVF ¶
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 ¶
VectorField defines an evaluation method that given an x and y value, returns a slice of values in the range [-1,1].
type VectorFields ¶
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 ¶
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
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
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
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
type WeightedCombiner ¶
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 ¶
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 (*WorleyField) Eval2 ¶
func (pf *WorleyField) Eval2(x, y float64) float64
Eval2 implements the Field interface.
Source Files
¶
- binary.go
- blocks.go
- cache.go
- check.go
- color.go
- combine.go
- component.go
- convolution.go
- displace.go
- distort.go
- doc.go
- field.go
- filter.go
- fractal.go
- gradient.go
- ifs.go
- image.go
- json.go
- morphological.go
- nonlinear.go
- perlin.go
- pixelate.go
- points.go
- reflect.go
- shape.go
- strip.go
- texture.go
- thresh.go
- tile.go
- transform.go
- uniform.go
- utils.go
- value.go
- vector.go
- warp.go
- wave.go
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. |
