gaul

package module
v0.0.0-...-730de84 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2024 License: Apache-2.0 Imports: 17 Imported by: 18

README

Generative Art Utility Library (gaul)

Gaul is a generative art library. It was originally part of Sketchy, but I separated the non-gui parts and put them in gaul. The main reason for this is to make it easy to containerize generative art applications.

Documentation

Index

Constants

View Source
const (
	BackgroundColorType = iota
	OutlineColorType
	TextColorType
	FillColorType
)
View Source
const (
	LUTSize   = 1 << 16
	LUTMask   = LUTSize - 1
	LUTFactor = LUTSize / Tau
)
View Source
const (
	Pi    = math.Pi
	Tau   = 2 * math.Pi
	Sqrt2 = math.Sqrt2
	Sqrt3 = 1.7320508075688772
	Smol  = 1e-9
	Phi   = 1.618033988749895
)

Variables

View Source
var (
	ErrInvalidSides = errors.New("invalid number of sides")
)

Functions

func Clamp

func Clamp(a float64, b float64, c float64) float64

Clamp restricts a value to a given range

func Deg2Rad

func Deg2Rad(f float64) float64

Deg2Rad converts from degrees to radians

func Distance

func Distance(p Point, q Point) float64

Distance between two points

func Equalf

func Equalf(a, b float64) bool

func FloatString

func FloatString(f float64, prec int) string

func Gcd

func Gcd(a int, b int) int

Gcd calculates the greatest common divisor

func GetTimestampString

func GetTimestampString() string

GetTimestampString creates a string based on the current time for use in filenames

func Lerp

func Lerp(a float64, b float64, i float64) float64

Lerp calculates the linear interpolation between two values

func Linspace

func Linspace(i float64, j float64, n int, b bool) []float64

Linspace creates a slice of linearly distributed values in a range

func Map

func Map(a float64, b float64, c float64, d float64, i float64) float64

Map calculates the linear interpolation from one range to another

func NamedColor

func NamedColor(name string) color.Color

func NoTinyVals

func NoTinyVals(a float64) float64

NoTinyVals sets values very close to zero to zero

func Rad2Deg

func Rad2Deg(f float64) float64

Rad2Deg converts from radians to degrees

func Shuffle

func Shuffle(p *[]Point)

Shuffle a slice of points

func Smoothstep

func Smoothstep(t float64) float64

func SquaredDistance

func SquaredDistance(p Point, q Point) float64

SquaredDistance is the square of the distance between two points

func StringToColor

func StringToColor(colorString string) color.Color

Types

type Affine2D

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

Affine2D is a type for dealing with affine transformations in 2D using homogeneous coordinates

func Add

func Add(p, q *Affine2D) *Affine2D

Add calculates the new Affine2D corresponding to adding p and q

func Mult

func Mult(p, q *Affine2D) *Affine2D

Mult calculates the new Affine2D corresponding to multiplying p and q

func NewAffine2D

func NewAffine2D() *Affine2D

NewAffine2D returns an identity affine transformation (no rotation, scaling, shearing, or translation)

func NewAffine2DWithRotation

func NewAffine2DWithRotation(angle float64) *Affine2D

NewAffine2DWithRotation returns an affine transformation with rotation configured

func NewAffine2DWithScale

func NewAffine2DWithScale(sx, sy float64) *Affine2D

NewAffine2DWithScale returns an affine transformation with scaling configured

func NewAffine2DWithShear

func NewAffine2DWithShear(sx, sy float64) *Affine2D

NewAffine2DWithShear returns an affine transformation with shearing configured

func NewAffine2DWithTranslation

func NewAffine2DWithTranslation(tx, ty float64) *Affine2D

NewAffine2DWithTranslation returns an affine transformation with translation configured

func (*Affine2D) MultVec

func (a *Affine2D) MultVec(v Vec2) Vec2

MultVec returns a new vector which is the result of applying the affine transformation

func (*Affine2D) RotateAboutPoint

func (a *Affine2D) RotateAboutPoint(vec Vec2, angle float64, point Point) Vec2

RotateAboutPoint rotates a vector around a point instead of the origin

func (*Affine2D) RotateCurveAboutPoint

func (a *Affine2D) RotateCurveAboutPoint(curve Curve, angle float64, rotationPoint Point) Curve

RotateCurveAboutPoint rotates a curve around a point instead of the origin

func (*Affine2D) RotateLineAboutPoint

func (a *Affine2D) RotateLineAboutPoint(line Line, angle float64, rotationPoint Point) Line

RotateLineAboutPoint rotates a line around a point instead of the origin

func (*Affine2D) RotatePointAboutPoint

func (a *Affine2D) RotatePointAboutPoint(point Point, angle float64, rotationPoint Point) Point

RotatePointAboutPoint rotates a point around a point instead of the origin

func (*Affine2D) SetRotation

func (a *Affine2D) SetRotation(angle float64)

SetRotation sets the rotation for the transformation

func (*Affine2D) SetRotationDegrees

func (a *Affine2D) SetRotationDegrees(angle float64)

SetRotationDegrees sets the rotation of the transformation

func (*Affine2D) SetScale

func (a *Affine2D) SetScale(sx, sy float64)

SetScale sets the scale factor for the x and y directions

func (*Affine2D) SetShearAngle

func (a *Affine2D) SetShearAngle(ax, ay float64)

SetShearAngle sets the shear factor in the x and y directions

func (*Affine2D) SetShearAngleDegrees

func (a *Affine2D) SetShearAngleDegrees(ax, ay float64)

SetShearAngleDegrees sets the shear factor in the x and y directions

func (*Affine2D) SetShearFactor

func (a *Affine2D) SetShearFactor(sx, sy float64)

SetShearFactor sets the shear factor in the x and y directions

func (*Affine2D) SetTranslation

func (a *Affine2D) SetTranslation(tx, ty float64)

SetTranslation sets the translation for the x and y directions

func (*Affine2D) Transform

func (a *Affine2D) Transform(v Vec2) Vec2

Transform applies the affine transformation to a vector

func (*Affine2D) TransformCurve

func (a *Affine2D) TransformCurve(c Curve) Curve

TransformCurve applies the affine transformation to a curve

func (*Affine2D) TransformLine

func (a *Affine2D) TransformLine(l Line) Line

TransformLine applies the affine transformation to a line

func (*Affine2D) TransformPoint

func (a *Affine2D) TransformPoint(p Point) Point

TransformPoint applies the affine transformation to a point

type Circle

type Circle struct {
	Center Point
	Radius float64
}

A Circle represented by a center point and radius

func (Circle) Boundary

func (c Circle) Boundary() Rect

Boundary returns the smallest rect that contains all points on the circle

func (Circle) ContainsPoint

func (c Circle) ContainsPoint(p Point) bool

ContainsPoint determines if a point lies inside the circle, including the boundary

func (Circle) Copy

func (c Circle) Copy() Circle

Copy returns a new circle with the same center and radius

func (Circle) Draw

func (c Circle) Draw(ctx *canvas.Context)

Draw draws the circle given a canvas context

func (Circle) PointOnEdge

func (c Circle) PointOnEdge(p Point) bool

PointOnEdge determines if a point lies on the boundary of a circle

func (Circle) ToCurve

func (c Circle) ToCurve(resolution int) Curve

ToCurve calculates a curve that approximates the circle with a given resolution (number of sides)

type ColorConfig

type ColorConfig struct {
	Background color.Color
	Outline    color.Color
	Text       color.Color
	Fill       color.Color
	Gradient   SimpleGradient
}

func (*ColorConfig) Set

func (cc *ColorConfig) Set(hexString string, colorType ColorType, defaultString string)

type ColorType

type ColorType int

type CubicSpline

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

CubicSpline represents a cubic spline

func NewCubicSpline

func NewCubicSpline(points []Point) CubicSpline

NewCubicSpline creates a cubic spline from a set of points

func NewCubicSplineWithResolution

func NewCubicSplineWithResolution(points []Point, res int) CubicSpline

NewCubicSplineWithResolution creates a cubic spline from a set of points with a specific resolution

func NewRegularCubicSpline

func NewRegularCubicSpline(points []Point) CubicSpline

func (CubicSpline) At

func (cs CubicSpline) At(x float64) float64

At evaluates the spline at a given x value

func (CubicSpline) ToCurve

func (cs CubicSpline) ToCurve() Curve

ToCurve converts the spline to a curve

type Curve

type Curve struct {
	Points []Point
	Closed bool
}

Curve A curve is a list of points, may be closed

func Chaikin

func Chaikin(c Curve, q float64, n int) Curve

Chaikin senerates a Chaikin curve given a set of control points, a cutoff ratio, and the number of steps to use in the calculation.

func CubicBezier

func CubicBezier(p, q, c1, c2 Point) Curve

CubicBezier generates a cubic Bézier curve between two points given two control points

func CubicBezierWithResolution

func CubicBezierWithResolution(p, q, c1, c2 Point, resolution int) Curve

CubicBezierWithResolution generates a cubic Bézier curve with a specific resolution

func GenLissajous

func GenLissajous(l Lissajous, n int, offset Point, s float64) Curve

GenLissajous generates a Lissajous curve given parameters, a number of points to use (i.e. resolution), and an offset and scale (typically to convert to screen coordinates)

func PulsarPlot

func PulsarPlot(curves []Curve) []Curve

PulsarPlot transforms a slice of curves into a slice of curves representing the segments that make up a pulsar plot

func QuadBezier

func QuadBezier(p, q, c Point) Curve

QuadBezier generates a quadratic Bézier curve between two points given a control point

func QuadBezierWithResolution

func QuadBezierWithResolution(p, q, c Point, resolution int) Curve

QuadBezierWithResolution generates a quadratic Bézier curve with a specific resolution

func QuarticBezier

func QuarticBezier(p, q, c1, c2, c3 Point) Curve

QuarticBezier generates a quartic Bézier curve between two points given three control points

func QuarticBezierWithResolution

func QuarticBezierWithResolution(p, q, c1, c2, c3 Point, resolution int) Curve

QuarticBezierWithResolution generates a quartic Bézier curve with a specific resolution

func QuarticBezierWithTriangleControl

func QuarticBezierWithTriangleControl(p, q Point, tri Triangle) Curve

func (*Curve) AddPoint

func (c *Curve) AddPoint(x, y float64)

AddPoint appends a point to the curve

func (*Curve) Boundary

func (c *Curve) Boundary() Rect

Boundary returns the smallest rect that contains all the points in the curve

func (*Curve) Centroid

func (c *Curve) Centroid() Point

Centroid returns the centroid for the curve

func (*Curve) Copy

func (c *Curve) Copy() Curve

Copy returns a new line with the same points and closed property

func (*Curve) Draw

func (c *Curve) Draw(ctx *canvas.Context)

Draw draws the curve given a canvas context

func (*Curve) Last

func (c *Curve) Last() Point

Last returns the last point in a curve

func (*Curve) LastLine

func (c *Curve) LastLine() Line

LastLine returns the last line in a curve

func (*Curve) Length

func (c *Curve) Length() float64

Length Calculates the length of the line segments of a curve

func (*Curve) Lerp

func (c *Curve) Lerp(percentage float64) Point

Lerp calculates a point a given percentage along a curve

func (*Curve) LineAt

func (c *Curve) LineAt(percentage float64) (Line, float64)

LineAt returns the line segment in a curve that is closest to the given percentage along the curve's length

func (*Curve) PerpendicularAt

func (c *Curve) PerpendicularAt(percentage float64, length float64) Line

PerpendicularAt calculates a line that is perpendicular to the curve at a given percentage along the curve's length

func (*Curve) Reverse

func (c *Curve) Reverse()

func (*Curve) Rotate

func (c *Curve) Rotate(a float64)

Rotate calculates a new curve for which each point is rotated by the given angle

func (*Curve) Scale

func (c *Curve) Scale(x, y float64)

Scale calculates a new curve for which each point is scaled by the give amount

func (*Curve) Shear

func (c *Curve) Shear(x, y float64)

Shear calculates a new curve for which each point is sheared by the given amount

func (*Curve) Stitch

func (c *Curve) Stitch(d *Curve)

func (*Curve) Translate

func (c *Curve) Translate(x, y float64)

Translate calculates a new curve for which each point is translated by the given amount

type Gradient

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

func NewGradientFromNamed

func NewGradientFromNamed(names []string) Gradient

func (*Gradient) AddStop

func (g *Gradient) AddStop(colorString string)

func (*Gradient) Color

func (g *Gradient) Color(percentage float64) color.Color

func (*Gradient) LinearPalette

func (g *Gradient) LinearPalette(num int) []color.Color

func (*Gradient) LinearPaletteStrings

func (g *Gradient) LinearPaletteStrings(num int) []string

func (*Gradient) NumStops

func (g *Gradient) NumStops() int

type IndexPoint

type IndexPoint struct {
	Index int
	Point
}

An IndexPoint is a wrapper around a point with an extra int identifier, useful when used with trees and heaps

func (IndexPoint) ToPoint

func (p IndexPoint) ToPoint() Point

type InteriorAngle

type InteriorAngle int
const (
	CAB InteriorAngle = iota
	ABC
	BCA
)

type KDTree

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

func NewKDTree

func NewKDTree(r Rect) *KDTree

func NewKDTreeWithPoint

func NewKDTreeWithPoint(p IndexPoint, r Rect) *KDTree

func (*KDTree) Clear

func (k *KDTree) Clear()

func (*KDTree) Draw

func (k *KDTree) Draw(ctx *canvas.Context)

func (*KDTree) DrawWithPoints

func (k *KDTree) DrawWithPoints(s float64, ctx *canvas.Context)

func (*KDTree) Insert

func (k *KDTree) Insert(p IndexPoint)

func (*KDTree) IsLeaf

func (k *KDTree) IsLeaf() bool

func (*KDTree) NearestNeighbors

func (k *KDTree) NearestNeighbors(point IndexPoint, s int) []IndexPoint

func (*KDTree) Query

func (k *KDTree) Query(r Rect) []Point

func (*KDTree) Search

func (k *KDTree) Search(p IndexPoint) *IndexPoint

func (*KDTree) Size

func (k *KDTree) Size() int

func (*KDTree) UpdateIndex

func (k *KDTree) UpdateIndex(p IndexPoint, index int) *IndexPoint

type LFSRLarge

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

LFSRLarge is a 64-bit Xorshift PRNG Benchmarks show this is faster than LFSRMedium and LFSRSmall, so you might as well use this one. Benchmarks also show this is 6-7x faster than the standard math/rand PRNG

func NewLFSRLarge

func NewLFSRLarge() LFSRLarge

func NewLFSRLargeWithSeed

func NewLFSRLargeWithSeed(seed uint64) LFSRLarge

func (*LFSRLarge) Float64

func (l *LFSRLarge) Float64() float64

func (*LFSRLarge) Next

func (l *LFSRLarge) Next() uint64

func (*LFSRLarge) Uint64

func (l *LFSRLarge) Uint64() uint64

func (*LFSRLarge) Uint64n

func (l *LFSRLarge) Uint64n(n uint64) uint64

type LFSRMedium

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

func NewLFSRMedium

func NewLFSRMedium() LFSRMedium

func NewLFSRMediumWithSeed

func NewLFSRMediumWithSeed(seed uint32) LFSRMedium

func (*LFSRMedium) Next

func (l *LFSRMedium) Next() uint32

type LFSRSmall

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

func NewLFSRSmall

func NewLFSRSmall() LFSRSmall

func NewLFSRSmallWithSeed

func NewLFSRSmallWithSeed(seed uint16) LFSRSmall

func (*LFSRSmall) Next

func (l *LFSRSmall) Next() uint16

type Line

type Line struct {
	P Point
	Q Point
}

Line is two points that form a line

func (Line) Angle

func (l Line) Angle() float64

Angle calculates the angle between the line and the x-axis

func (Line) Boundary

func (l Line) Boundary() Rect

Boundary returns the smallest rect that contains both points in the line

func (Line) Copy

func (l Line) Copy() Line

Copy returns a new line with the same points P and Q

func (Line) Draw

func (l Line) Draw(ctx *canvas.Context)

Draw draws the line given a canvas context

func (Line) Intersects

func (l Line) Intersects(k Line) bool

Intersects determines if two lines intersect each other

func (Line) InvertedSlope

func (l Line) InvertedSlope() float64

InvertedSlope calculates one over the slope of the line

func (Line) IsEqual

func (l Line) IsEqual(k Line) bool

IsEqual determines if two lines are equal to each other

func (Line) Length

func (l Line) Length() float64

Length Calculates the length of a line

func (Line) Lerp

func (l Line) Lerp(i float64) Point

Lerp is an interpolation between the two points of a line

func (Line) Midpoint

func (l Line) Midpoint() Point

Midpoint Calculates the midpoint of a line

func (Line) ParallelTo

func (l Line) ParallelTo(k Line) bool

ParallelTo determines if two lines are parallel

func (Line) PerpendicularAt

func (l Line) PerpendicularAt(percentage float64, length float64) Line

PerpendicularAt calculates a line at a given percentage along the line with a given length that is perpendicular to the original line

func (Line) PerpendicularBisector

func (l Line) PerpendicularBisector(length float64) Line

PerpendicularBisector calculates a line with a given length at the midpoint of the original line that is also perpendicular to the line

func (Line) Rotate

func (l Line) Rotate(a float64) Line

Rotate calculates a new line for which both points are rotated by the given angle

func (Line) Scale

func (l Line) Scale(x, y float64) Line

Scale calculates a new line for which both points are scaled by the given amount

func (Line) Shear

func (l Line) Shear(x, y float64) Line

Shear calculates a new line for which both points are sheared by the given amount

func (Line) Slope

func (l Line) Slope() float64

Slope computes the slope of the line

func (Line) String

func (l Line) String() string

Line functions String representation of a line, useful for debugging

func (Line) Translate

func (l Line) Translate(x, y float64) Line

Translate calculates a new line for which both points are translated by the given amount

type Lissajous

type Lissajous struct {
	Nx int
	Ny int
	Px float64
	Py float64
}

Lissajous represents the core parameters for a 2D Lissajous curve

type MetricPoint

type MetricPoint struct {
	Metric float64
	Index  int
	Point
}

A MetricPoint is a wrapper around a point with to extra identifiers, useful when used with trees and heaps

func (MetricPoint) ToIndexPoint

func (p MetricPoint) ToIndexPoint() IndexPoint

func (MetricPoint) ToPoint

func (p MetricPoint) ToPoint() Point

type Point

type Point struct {
	X float64
	Y float64
}

Point is a simple point in 2D space

func Midpoint

func Midpoint(p Point, q Point) Point

Midpoint Calculates the midpoint between two points

func PaduaPoints

func PaduaPoints(n int) []Point

PaduaPoints calculates Padua points for a certain class of Lissajous curves, where Nx = Ny +/- 1. The correspond to intersection points and some of the outside points on the curve See https://en.wikipedia.org/wiki/Padua_points for more details.

func (Point) Copy

func (p Point) Copy() Point

Copy returns a new point with the same x and y coordinates

func (Point) Draw

func (p Point) Draw(s float64, ctx *canvas.Context)

Draw draws the point as a circle with a given radius using a canvas context

func (Point) IsEqual

func (p Point) IsEqual(q Point) bool

IsEqual determines if two points are equal

func (Point) Lerp

func (p Point) Lerp(a Point, i float64) Point

Lerp is a linear interpolation between two points

func (Point) Reflect

func (p Point) Reflect() Point

Reflect calculates a new point that is reflected about both the x and y axes

func (Point) ReflectX

func (p Point) ReflectX() Point

ReflectX calculates a new point that is reflected about the x-axis

func (Point) ReflectY

func (p Point) ReflectY() Point

ReflectY calculates a new point that is reflected about the y-axis

func (Point) Rotate

func (p Point) Rotate(a float64) Point

Rotate calculates a new point rotated around the origin by a given angle

func (Point) Scale

func (p Point) Scale(x, y float64) Point

Scale multiplies point coordinates by a fixed value

func (Point) ScaleX

func (p Point) ScaleX(x float64) Point

ScaleX scales the x value of a point

func (Point) ScaleY

func (p Point) ScaleY(y float64) Point

ScaleY scales the y value of a point

func (Point) Shear

func (p Point) Shear(x, y float64) Point

Shear calculates a new point sheared given angles for the x and y directions

func (Point) ShearX

func (p Point) ShearX(a float64) Point

ShearX calculates a new point sheared in the x direction by a given angle

func (Point) ShearY

func (p Point) ShearY(a float64) Point

ShearY calculates a new point sheared in the x direction by a given angle

func (Point) String

func (p Point) String() string

Tuple representation of a point, useful for debugging

func (Point) ToIndexPoint

func (p Point) ToIndexPoint(index int) IndexPoint

func (Point) ToMetricPoint

func (p Point) ToMetricPoint(index int, metric float64) MetricPoint

func (Point) ToVec2

func (p Point) ToVec2() Vec2

ToVec2 translates the point to a Vec2 struct

func (Point) Translate

func (p Point) Translate(x, y float64) Point

Translate calculates a new point with coordinates translated by the given amounts

func (Point) TranslateX

func (p Point) TranslateX(x float64) Point

TranslateX calculates a new point with the x coordinated translated by the given amount

func (Point) TranslateY

func (p Point) TranslateY(y float64) Point

TranslateY calculates a new point with the y coordinated translated by the given amount

type PointHeap

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

PointHeap is a min/max heap for Points using inter-point distance as the metric

func NewMaxPointHeap

func NewMaxPointHeap() *PointHeap

func NewMinPointHeap

func NewMinPointHeap() *PointHeap

func (*PointHeap) Len

func (m *PointHeap) Len() int

func (*PointHeap) Peek

func (m *PointHeap) Peek() MetricPoint

func (*PointHeap) Pop

func (m *PointHeap) Pop() MetricPoint

func (*PointHeap) Push

func (m *PointHeap) Push(p MetricPoint)

func (*PointHeap) Report

func (m *PointHeap) Report() []MetricPoint

func (*PointHeap) ReportReversed

func (m *PointHeap) ReportReversed() []MetricPoint

type QuadTree

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

func NewQuadTree

func NewQuadTree(r Rect) *QuadTree

func NewQuadTreeWithCapacity

func NewQuadTreeWithCapacity(r Rect, c int) *QuadTree

func (*QuadTree) Clear

func (q *QuadTree) Clear()

func (*QuadTree) Draw

func (q *QuadTree) Draw(ctx *canvas.Context)

func (*QuadTree) DrawWithPoints

func (q *QuadTree) DrawWithPoints(s float64, ctx *canvas.Context)

func (*QuadTree) Insert

func (q *QuadTree) Insert(p IndexPoint) bool

func (*QuadTree) NearestNeighbors

func (q *QuadTree) NearestNeighbors(point IndexPoint, k int) []IndexPoint

func (*QuadTree) Query

func (q *QuadTree) Query(r Rect) []Point

func (*QuadTree) QueryCircle

func (q *QuadTree) QueryCircle(center Point, radius float64) []Point

func (*QuadTree) QueryCircleExcludeIndex

func (q *QuadTree) QueryCircleExcludeIndex(center Point, radius float64, index int) []Point

func (*QuadTree) QueryExcludeIndex

func (q *QuadTree) QueryExcludeIndex(r Rect, index int) []Point

func (*QuadTree) Search

func (q *QuadTree) Search(p IndexPoint) *IndexPoint

func (*QuadTree) Size

func (q *QuadTree) Size() int

func (*QuadTree) UpdateIndex

func (q *QuadTree) UpdateIndex(p IndexPoint, index int) *IndexPoint

type Rect

type Rect struct {
	X float64
	Y float64
	W float64
	H float64
}

Rect is a simple rectangle

func (Rect) Center

func (r Rect) Center() Point

Center returns a point at the center of the rectangle

func (Rect) Contains

func (r Rect) Contains(rect Rect) bool

Contains determines if the rectangle contains a given rectangle

func (Rect) ContainsPoint

func (r Rect) ContainsPoint(p Point) bool

ContainsPoint determines if a point lies within a rectangle

func (Rect) Copy

func (r Rect) Copy() Rect

Copy returns a new rectangle with the same corner, width, and height

func (Rect) Draw

func (r Rect) Draw(ctx *canvas.Context)

Draw draws the rectangle given a canvas context

func (Rect) GoldenSubdivision

func (r Rect) GoldenSubdivision() (Rect, Rect)

GoldenSubdivision returns two rectangles using the golden ratio to calculate where to split the rectangle

func (Rect) Intersects

func (r Rect) Intersects(rect Rect) bool

Intersects determines if the rectangle intersects the given rectangle

func (Rect) IsDisjoint

func (r Rect) IsDisjoint(rect Rect) bool

IsDisjoint determines if the rectangle is disjoint (no overlap) from a given rectangle

func (Rect) Overlaps

func (r Rect) Overlaps(rect Rect) bool

Overlaps determines if the rectangle overlaps the given rectangle

func (Rect) Subdivide

func (r Rect) Subdivide(perc float64) (Rect, Rect)

func (Rect) ToCurve

func (r Rect) ToCurve() Curve

ToCurve calculates a closed curve with points corresponding to the vertices of the rectangle

type RegularPolygon

type RegularPolygon struct {
	Sides    int
	Radius   float64
	Rotation float64 // in radians
	Center   Point
}

func NewRegularPolygon

func NewRegularPolygon(sides int, radius float64, center Point) (RegularPolygon, error)

func NewRegularPolygonWithSideLength

func NewRegularPolygonWithSideLength(sides int, sideLength float64, center Point) (RegularPolygon, error)

func (RegularPolygon) Apothem

func (p RegularPolygon) Apothem() float64

func (RegularPolygon) Area

func (p RegularPolygon) Area() float64

func (RegularPolygon) Draw

func (p RegularPolygon) Draw(ctx *canvas.Context)

func (RegularPolygon) Edges

func (p RegularPolygon) Edges() []Line

func (RegularPolygon) Lerp

func (p RegularPolygon) Lerp(t float64) Point

func (RegularPolygon) Perimeter

func (p RegularPolygon) Perimeter() float64

func (RegularPolygon) Points

func (p RegularPolygon) Points() []Point

func (RegularPolygon) SideLength

func (p RegularPolygon) SideLength() float64

func (RegularPolygon) ToCurve

func (p RegularPolygon) ToCurve() Curve

type Rng

type Rng struct {
	Prng  LFSRLarge
	Noise opensimplex.Noise
	// contains filtered or unexported fields
}

Rng is a random number generator with a system PRNG and simplex noise

func NewRng

func NewRng(i int64) Rng

NewRng returns a PRNG with a system and Noise generator

func (*Rng) Gaussian

func (r *Rng) Gaussian(mean float64, stdev float64) float64

func (*Rng) Noise1D

func (r *Rng) Noise1D(x float64) float64

Noise1D 1D Noise values in the range of [0, 1]

func (*Rng) Noise2D

func (r *Rng) Noise2D(x float64, y float64) float64

Noise2D generates 2D Noise values in the range of [0, 1]

func (*Rng) Noise3D

func (r *Rng) Noise3D(x float64, y float64, z float64) float64

Noise3D generates 3D Noise values in the range of [0, 1]

func (*Rng) NoisyRandomPoints

func (r *Rng) NoisyRandomPoints(num int, threshold float64, rect Rect) []Point

func (*Rng) SetNoiseLacunarity

func (r *Rng) SetNoiseLacunarity(l float64)

SetNoiseLacunarity sets how frequency scales with octaves

func (*Rng) SetNoiseOctaves

func (r *Rng) SetNoiseOctaves(i int)

SetNoiseOctaves sets the number of steps when calculating fractal Noise

func (*Rng) SetNoiseOffsetX

func (r *Rng) SetNoiseOffsetX(offset float64)

SetNoiseOffsetX offsets the x position in Noise calculations

func (*Rng) SetNoiseOffsetY

func (r *Rng) SetNoiseOffsetY(offset float64)

SetNoiseOffsetY offsets the y position in Noise calculations

func (*Rng) SetNoiseOffsetZ

func (r *Rng) SetNoiseOffsetZ(offset float64)

SetNoiseOffsetZ offsets the z position in Noise calculations

func (*Rng) SetNoisePersistence

func (r *Rng) SetNoisePersistence(p float64)

SetNoisePersistence sets how amplitude scales with octaves

func (*Rng) SetNoiseScaleX

func (r *Rng) SetNoiseScaleX(scale float64)

SetNoiseScaleX scales the x position in Noise calculations

func (*Rng) SetNoiseScaleY

func (r *Rng) SetNoiseScaleY(scale float64)

SetNoiseScaleY scales the y position in Noise calculations

func (*Rng) SetNoiseScaleZ

func (r *Rng) SetNoiseScaleZ(scale float64)

SetNoiseScaleZ scales the z position in Noise calculations

func (*Rng) SetSeed

func (r *Rng) SetSeed(seed int64)

func (*Rng) SignedNoise1D

func (r *Rng) SignedNoise1D(x float64) float64

SignedNoise1D generates 1D Noise values in the range of [-1, 1]

func (*Rng) SignedNoise2D

func (r *Rng) SignedNoise2D(x float64, y float64) float64

SignedNoise2D generates 2D Noise values in the range of [-1, 1]

func (*Rng) SignedNoise3D

func (r *Rng) SignedNoise3D(x float64, y float64, z float64) float64

SignedNoise3D generates 3D Noise values in the range of [-1, 1]

func (*Rng) UniformRandomPoints

func (r *Rng) UniformRandomPoints(num int, rect Rect) []Point

UniformRandomPoints generates a list of points whose coordinates follow a uniform random distribution within a rectangle

type SimpleGradient

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

func NewSimpleGradientFromNamed

func NewSimpleGradientFromNamed(c1, c2 string) SimpleGradient

func (*SimpleGradient) Color

func (sg *SimpleGradient) Color(percentage float64) color.Color

type SinePalette

type SinePalette struct {
	A, B, C, D Vec3
	Alpha      float64
}

func NewSinePalette

func NewSinePalette(c, d Vec3) SinePalette

func (*SinePalette) ColorAt

func (sp *SinePalette) ColorAt(t float64) color.Color

func (*SinePalette) Palette

func (sp *SinePalette) Palette(num int) []color.Color

func (*SinePalette) ToPng

func (sp *SinePalette) ToPng() (string, error)

type Triangle

type Triangle struct {
	A Point
	B Point
	C Point
}

A Triangle specified by vertices as points

func (Triangle) AB

func (t Triangle) AB() float64

AB returns the length of the side defined by vertices A and B also known as side "c" in typical notation

func (Triangle) AC

func (t Triangle) AC() float64

AC returns the length of the side defined by vertices A and C also known as side "b" in typical notation

func (Triangle) Angles

func (t Triangle) Angles() (float64, float64, float64)

Angles calculates the interior angles of the triangle

func (Triangle) Area

func (t Triangle) Area() float64

Area calculates the area of the triangle

func (Triangle) BC

func (t Triangle) BC() float64

BC returns the length of the side defined by vertices B and C also known as side "a" in typical notation

func (Triangle) BarycentricSubdivision

func (t Triangle) BarycentricSubdivision() []Triangle

BarycentricSubdivision returns a slice of triangles that are the result of subdividing the triangle into three smaller triangles using the centroid and each vertex as the new vertices

func (Triangle) BisectSubdivision

func (t Triangle) BisectSubdivision(angle InteriorAngle, percent float64) []Triangle

BisectSubdivision returns a slice of triangles that are the result of subdividing the triangle into two smaller triangles by bisecting one angle with a variable percent offset along the opposite side

func (Triangle) Boundary

func (t Triangle) Boundary() Rect

Boundary returns the smallest rect that contains all three vertices

func (Triangle) Centroid

func (t Triangle) Centroid() Point

Centroid calculates the centroid of the triangle

func (Triangle) Circumcenter

func (t Triangle) Circumcenter() Point

Circumcenter calculates the circumcenter of the triangle

func (Triangle) CircumcenterSubdivision

func (t Triangle) CircumcenterSubdivision() []Triangle

CircumcenterSubdivision returns a slice of triangles that are the result of subdividing the triangle into three smaller triangles using the circumcenter and each vertex as the new vertices

func (Triangle) Circumcircle

func (t Triangle) Circumcircle() Circle

Circumcircle returns the circumcircle of the triangle

func (Triangle) CircumcircleRadius

func (t Triangle) CircumcircleRadius() float64

CircumcircleRadius calculates the radius of the circumcircle

func (Triangle) Copy

func (t Triangle) Copy() Triangle

Copy returns a new triangle with the same vertices

func (Triangle) Draw

func (t Triangle) Draw(ctx *canvas.Context)

Draw draws the triangle given a canvas context

func (Triangle) Incenter

func (t Triangle) Incenter() Point

Incenter calculates the incenter of the triangle

func (Triangle) IncenterSubdivision

func (t Triangle) IncenterSubdivision() []Triangle

IncenterSubdivision returns a slice of triangles that are the result of subdividing the triangle into three smaller triangles using the incenter and each vertex as the new vertices

func (Triangle) Incircle

func (t Triangle) Incircle() Circle

Incircle returns the incircle of the triangle

func (Triangle) IncircleRadius

func (t Triangle) IncircleRadius() float64

IncircleRadius calculates the radius of the incircle

func (Triangle) MidAndThirdsSubdivision

func (t Triangle) MidAndThirdsSubdivision(angle InteriorAngle) []Triangle

func (Triangle) MidpointSubdivision

func (t Triangle) MidpointSubdivision() []Triangle

MidpointSubdivision returns a slice of triangles that are the result of subdividing the triangle into four smaller triangles using the midpoints of each side as the set of new vertices

func (Triangle) NinePointCenter

func (t Triangle) NinePointCenter() Point

NinePointCenter calculates the center point of the nine-point circle

func (Triangle) NinePointCircle

func (t Triangle) NinePointCircle() Circle

NinePointCircle returns the nine-point circle of the triangle

func (Triangle) NinePointRadius

func (t Triangle) NinePointRadius() float64

NinePointRadius calculates the radius of the nine-point circle

func (Triangle) Orthocenter

func (t Triangle) Orthocenter() Point

Orthocenter calculates the orthocenter of the triangle

func (Triangle) OrthocenterSubdivision

func (t Triangle) OrthocenterSubdivision() []Triangle

OrthocenterSubdivision returns a slice of triangles that are the result of subdividing the triangle into three smaller triangles using the orthocenter and each vertex as the new vertices

func (Triangle) Perimeter

func (t Triangle) Perimeter() float64

Perimeter calculates the perimeter of the triangle

func (Triangle) Reverse

func (t Triangle) Reverse() Triangle

func (Triangle) ToCurve

func (t Triangle) ToCurve() Curve

ToCurve calculates a closed curve with points corresponding to the vertices of the triangle

type TrigLUT

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

TrigLUT is a lookup table for sine and cosine. In my tests, it is about 9x faster than math.Sin and math.Cos. The margin of error is < 0.005%. This LUT is not suitable for tangents, however.

func NewTrigLUT

func NewTrigLUT() *TrigLUT

func (*TrigLUT) Cos

func (lut *TrigLUT) Cos(x float64) float64

func (*TrigLUT) Sin

func (lut *TrigLUT) Sin(x float64) float64

type Vec2

type Vec2 struct {
	X float64
	Y float64
}

func Vec2FromLine

func Vec2FromLine(l Line) Vec2

func Vec2FromPoint

func Vec2FromPoint(p Point) Vec2

Vec2FromPoint returns a vector from the origin to p

func Vec2FromPoints

func Vec2FromPoints(p, q Point) Vec2

Vec2FromPoints returns a vector from p to q

func (Vec2) Add

func (v Vec2) Add(u Vec2) Vec2

func (Vec2) Dot

func (v Vec2) Dot(u Vec2) float64

func (Vec2) Mag

func (v Vec2) Mag() float64

func (Vec2) Normalize

func (v Vec2) Normalize() Vec2

func (Vec2) Scale

func (v Vec2) Scale(s float64) Vec2

func (Vec2) Sub

func (v Vec2) Sub(u Vec2) Vec2

func (Vec2) ToPoint

func (v Vec2) ToPoint() Point

func (Vec2) ToString

func (v Vec2) ToString(prec int) string

func (Vec2) UnitNormal

func (v Vec2) UnitNormal() Vec2

type Vec3

type Vec3 struct {
	X float64
	Y float64
	Z float64
}

func (Vec3) Add

func (v Vec3) Add(u Vec3) Vec3

func (Vec3) Dot

func (v Vec3) Dot(u Vec3) float64

func (Vec3) Mag

func (v Vec3) Mag() float64

func (Vec3) Normalize

func (v Vec3) Normalize() Vec3

func (Vec3) Scale

func (v Vec3) Scale(s float64) Vec3

func (Vec3) Sub

func (v Vec3) Sub(u Vec3) Vec3

func (Vec3) ToString

func (v Vec3) ToString(prec int) string

Jump to

Keyboard shortcuts

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