Documentation ¶
Index ¶
- Constants
- Variables
- func BlendColor(old, new color.Color) color.Color
- func Eval(expr string) (interface{}, error)
- func IntegrateFunction(f Function, a, b float64) float64
- func IsFunction(dep, indep string, vars0, vars1 []string, ...) (bool, bool)
- func Mandelbrot(c *Coord) interface{}
- func MinInt(a, b int) int
- func UnitCircle(c *Coord) interface{}
- type Area
- type ComplexRelation
- type Coord
- func (c *Coord) Add(other *Coord) *Coord
- func (c *Coord) Dist(other *Coord) float64
- func (c *Coord) DistOrigin() float64
- func (c *Coord) Div(div float64) *Coord
- func (c *Coord) Equals(other *Coord) bool
- func (c *Coord) IsValid() bool
- func (c *Coord) Mult(mult float64) *Coord
- func (c *Coord) Polar() (r, theta float64)
- func (c *Coord) Rotate(theta float64) *Coord
- func (c *Coord) RotateAround(theta float64, other *Coord) *Coord
- func (c *Coord) Sub(other *Coord) *Coord
- func (c *Coord) WithinDist(other *Coord, dist float64) bool
- type DifferentialFunction
- type Function
- type Graph
- func (g *Graph) ApplyComplexRelation(rel ComplexRelation)
- func (g *Graph) ApplyComplexRelationInChunk(rel ComplexRelation, dst *image.RGBA, r *image.Rectangle, ch chan struct{})
- func (g *Graph) AtCoord(c *Coord) color.Color
- func (g *Graph) AtPixel(pt image.Point) color.Color
- func (g *Graph) CoordToPixel(c *Coord) image.Point
- func (g *Graph) DrawAxes()
- func (g *Graph) DrawDifferentialFunction(d DifferentialFunction, start *Coord)
- func (g *Graph) DrawDifferentialFunctionInDirection(d DifferentialFunction, start *Coord, dx float64, col color.Color, ...)
- func (g *Graph) DrawDifferentialFunctionWithColor(d DifferentialFunction, start *Coord, col color.Color)
- func (g *Graph) DrawFunction(f Function)
- func (g *Graph) DrawFunctionInRange(f Function, start, end int, col color.Color, ch chan struct{})
- func (g *Graph) DrawFunctionWithColor(f Function, col color.Color)
- func (g *Graph) DrawGrid()
- func (g *Graph) DrawLine(c0, c1 *Coord, col color.Color)
- func (g *Graph) DrawPolarFunction(f PolarFunction)
- func (g *Graph) DrawPolarFunctionInRange(f PolarFunction, start, end float64, col color.Color, ch chan struct{})
- func (g *Graph) DrawPolarFunctionWithColor(f PolarFunction, col color.Color)
- func (g *Graph) DrawRelation(rel Relation)
- func (g *Graph) DrawRelationInChunk(rel Relation, r *image.Rectangle, col color.Color, ch chan struct{})
- func (g *Graph) DrawRelationWithColor(rel Relation, col color.Color)
- func (g *Graph) ImageHeight() int
- func (g *Graph) ImageWidth() int
- func (g *Graph) PixelToCoord(pt image.Point) *Coord
- func (g *Graph) SavePNG(w io.Writer) error
- func (g *Graph) SetCoord(c *Coord, col color.Color)
- func (g *Graph) SetPixel(pt image.Point, col color.Color)
- type InvalidAreaError
- type InvalidScaleError
- type NoEqualityError
- type PolarFunction
- type RGBA16
- type Relation
- func Circle(r float64) Relation
- func CircleAt(r float64, center *Coord) Relation
- func Ellipse(a, b float64) Relation
- func EllipseAt(a, b float64, center *Coord) Relation
- func InvertRelation(rel Relation) Relation
- func OffsetRelation(rel Relation, off *Coord) Relation
- func RotateRelation(rel Relation, theta float64) Relation
- func RotateRelationAround(rel Relation, theta float64, coord *Coord) Relation
- func ScaleRelation(rel Relation, scale float64) Relation
- func ScaleRelationAround(rel Relation, scale float64, coord *Coord) Relation
- func ScaleRelationPerAxis(rel Relation, scale_x, scale_y float64) Relation
- func ScaleRelationPerAxisAround(rel Relation, scale_x, scale_y float64, coord *Coord) Relation
Constants ¶
const ( /* The maximum chunk size that goroutines will use for drawing relations and functions */ ChunkSize = 64 /* The maximum angle size that goroutines will use for drawing polar functions */ AngleSize = math.Pi / 4 /* The angle step that goroutines will increment the angle by when drawing polar functions */ AngleStep = AngleSize / 100 )
const ( MaxIterations = 200 DifferentiateDx = 0.01 )
Variables ¶
var ( Functions = map[string]govaluate.ExpressionFunction{ "abs": func(args ...interface{}) (interface{}, error) { return math.Abs(args[0].(float64)), nil }, "acos": func(args ...interface{}) (interface{}, error) { return math.Acos(args[0].(float64)), nil }, "acosh": func(args ...interface{}) (interface{}, error) { return math.Acosh(args[0].(float64)), nil }, "asin": func(args ...interface{}) (interface{}, error) { return math.Asin(args[0].(float64)), nil }, "asinh": func(args ...interface{}) (interface{}, error) { return math.Asinh(args[0].(float64)), nil }, "atan": func(args ...interface{}) (interface{}, error) { return math.Atan(args[0].(float64)), nil }, "atan2": func(args ...interface{}) (interface{}, error) { return math.Atan2(args[0].(float64), args[1].(float64)), nil }, "atanh": func(args ...interface{}) (interface{}, error) { return math.Atanh(args[0].(float64)), nil }, "ceil": func(args ...interface{}) (interface{}, error) { return math.Ceil(args[0].(float64)), nil }, "cos": func(args ...interface{}) (interface{}, error) { return math.Cos(args[0].(float64)), nil }, "cosh": func(args ...interface{}) (interface{}, error) { return math.Cosh(args[0].(float64)), nil }, "exp": func(args ...interface{}) (interface{}, error) { return math.Exp(args[0].(float64)), nil }, "floor": func(args ...interface{}) (interface{}, error) { return math.Floor(args[0].(float64)), nil }, "gamma": func(args ...interface{}) (interface{}, error) { return math.Gamma(args[0].(float64)), nil }, "ln": func(args ...interface{}) (interface{}, error) { return math.Log(args[0].(float64)), nil }, "log": func(args ...interface{}) (interface{}, error) { return math.Log10(args[0].(float64)), nil }, "sin": func(args ...interface{}) (interface{}, error) { return math.Sin(args[0].(float64)), nil }, "sinh": func(args ...interface{}) (interface{}, error) { return math.Sinh(args[0].(float64)), nil }, "sqrt": func(args ...interface{}) (interface{}, error) { return math.Sqrt(args[0].(float64)), nil }, "tan": func(args ...interface{}) (interface{}, error) { return math.Tan(args[0].(float64)), nil }, "tanh": func(args ...interface{}) (interface{}, error) { return math.Tanh(args[0].(float64)), nil }, } Constants = map[string]interface{}{ "pi": math.Pi, "tau": 2 * math.Pi, "e": math.E, "phi": math.Phi, } )
var ( /* The default graph background color */ DefaultBackgroundColor = color.RGBA{0xFF, 0xFF, 0xFF, 0xFF} /* The default graph axis color */ DefaultAxisColor = color.RGBA{0xFF, 0x00, 0x00, 0xFF} /* The default graph grid color */ DefaultGridColor = color.RGBA{0xE0, 0xE0, 0xE0, 0xFF} /* The default graph relation color */ DefaultRelationColor = color.RGBA{0x00, 0x00, 0x00, 0xFF} )
Functions ¶
func IntegrateFunction ¶
func IsFunction ¶
func Mandelbrot ¶
func Mandelbrot(c *Coord) interface{}
func UnitCircle ¶
func UnitCircle(c *Coord) interface{}
Types ¶
type Area ¶
type Area struct {
Pos0, Pos1 *Coord
}
An area in coordinate space. To work nicely, Pos0 must be above and to the left (lower x value and higher y value) of Pos1.
type ComplexRelation ¶
type ComplexRelation func(z complex128) complex128
A function that takes is a complex number and returns a complex number. This is used to treat a graph as the complex plane and then move the coordinates that correspond to the input to the return value of the ComplexRelation.
type Coord ¶
type Coord struct {
X, Y float64
}
A coordinate on a graph
func NewCoordFromPolar ¶
func (*Coord) DistOrigin ¶
type DifferentialFunction ¶
A function that takes in a coordinate and returns the derivate of a function at that point
type Function ¶
A function that takes in an x value and returns a y value. This is what you want for relations of the form "y == f(x)" as it will be drawn faster and more accurately than using the Relation version.
func DifferentiateFunction ¶
func OffsetFunction ¶
func ScaleFunction ¶
func ScaleFunctionPerAxis ¶
func (Function) ToRelation ¶
type Graph ¶
type Graph struct { Bounds *Area Image *image.RGBA BackgroundColor, RelationColor, AxisColor, GridColor color.Color }
func NewGraphWithColors ¶
func (*Graph) ApplyComplexRelation ¶
func (g *Graph) ApplyComplexRelation(rel ComplexRelation)
func (*Graph) ApplyComplexRelationInChunk ¶
func (*Graph) DrawDifferentialFunction ¶
func (g *Graph) DrawDifferentialFunction(d DifferentialFunction, start *Coord)
func (*Graph) DrawDifferentialFunctionInDirection ¶
func (*Graph) DrawDifferentialFunctionWithColor ¶
func (g *Graph) DrawDifferentialFunctionWithColor(d DifferentialFunction, start *Coord, col color.Color)
func (*Graph) DrawFunction ¶
func (*Graph) DrawFunctionInRange ¶
func (*Graph) DrawFunctionWithColor ¶
func (*Graph) DrawPolarFunction ¶
func (g *Graph) DrawPolarFunction(f PolarFunction)
func (*Graph) DrawPolarFunctionInRange ¶
func (g *Graph) DrawPolarFunctionInRange(f PolarFunction, start, end float64, col color.Color, ch chan struct{})
func (*Graph) DrawPolarFunctionWithColor ¶
func (g *Graph) DrawPolarFunctionWithColor(f PolarFunction, col color.Color)
func (*Graph) DrawRelation ¶
func (*Graph) DrawRelationInChunk ¶
func (*Graph) DrawRelationWithColor ¶
func (*Graph) ImageHeight ¶
func (*Graph) ImageWidth ¶
type InvalidAreaError ¶
type InvalidAreaError struct{}
func (InvalidAreaError) Error ¶
func (e InvalidAreaError) Error() string
type InvalidScaleError ¶
type InvalidScaleError struct{}
func (InvalidScaleError) Error ¶
func (e InvalidScaleError) Error() string
type NoEqualityError ¶
type NoEqualityError struct{}
func (NoEqualityError) Error ¶
func (e NoEqualityError) Error() string
type PolarFunction ¶
A function that takes in a theta value and returns a radius value. This is what you want for relations of the form "r == f(theta)" as it will be drawn faster and more accurately than using the Relation version.
func (PolarFunction) ToRelation ¶
func (f PolarFunction) ToRelation() Relation
type Relation ¶
type Relation func(c *Coord) interface{}
A function that takes in a coordinate and outputs one of the following types:
A bool to indicate that the coordinate should filled in. This is what you want for relations that are of a similar form as "f(x, y) <= g(x, y)".
A float64 that indicates the return of a function that needs to equal zero to be drawn. This is what you want for relations that are of a similar form as "f(x, y) == g(x, y)" but slightly modified to look like "f(x, y) - g(x, y) == 0". This is because very rarely will any coordinate the relation is called with be exactly what you need to make it true, and so the DrawRelation function compares the signs of the returned values of the surrounding coordinates and if there is a difference in the signs of said values, and the relation is continuous, then we know that the returned value would equal zero somewhere between those coordinates.
An error that indicates the current chunk should stop being drawn immediately.