gograph

package module
v0.0.0-...-caddaac Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2020 License: GPL-2.0 Imports: 8 Imported by: 1

Documentation

Index

Constants

View Source
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
)
View Source
const (
	MaxIterations   = 200
	DifferentiateDx = 0.01
)

Variables

View Source
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,
	}
)
View Source
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 BlendColor

func BlendColor(old, new color.Color) color.Color

func Eval

func Eval(expr string) (interface{}, error)

func IntegrateFunction

func IntegrateFunction(f Function, a, b float64) float64

func IsFunction

func IsFunction(dep, indep string, vars0, vars1 []string, tokens0, tokens1 []govaluate.ExpressionToken) (bool, bool)

func Mandelbrot

func Mandelbrot(c *Coord) interface{}

func MinInt

func MinInt(a, b int) int

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.

func NewArea

func NewArea(x0, y0, x1, y1 float64) (*Area, error)

func (*Area) Center

func (a *Area) Center() *Coord

func (*Area) CenterX

func (a *Area) CenterX() float64

func (*Area) CenterY

func (a *Area) CenterY() float64

func (*Area) Contains

func (a *Area) Contains(c *Coord) bool

func (*Area) Height

func (a *Area) Height() float64

func (*Area) Size

func (a *Area) Size() *Coord

func (*Area) Width

func (a *Area) Width() float64

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 NewCoord

func NewCoord(x, y float64) *Coord

func NewCoordFromPolar

func NewCoordFromPolar(r, theta float64) *Coord

func (*Coord) Add

func (c *Coord) Add(other *Coord) *Coord

func (*Coord) Dist

func (c *Coord) Dist(other *Coord) float64

func (*Coord) DistOrigin

func (c *Coord) DistOrigin() float64

func (*Coord) Div

func (c *Coord) Div(div float64) *Coord

func (*Coord) Equals

func (c *Coord) Equals(other *Coord) bool

func (*Coord) IsValid

func (c *Coord) IsValid() bool

func (*Coord) Mult

func (c *Coord) Mult(mult float64) *Coord

func (*Coord) Polar

func (c *Coord) Polar() (r, theta float64)

func (*Coord) Rotate

func (c *Coord) Rotate(theta float64) *Coord

func (*Coord) RotateAround

func (c *Coord) RotateAround(theta float64, other *Coord) *Coord

func (*Coord) Sub

func (c *Coord) Sub(other *Coord) *Coord

func (*Coord) WithinDist

func (c *Coord) WithinDist(other *Coord, dist float64) bool

type DifferentialFunction

type DifferentialFunction func(c *Coord) float64

A function that takes in a coordinate and returns the derivate of a function at that point

type Function

type Function func(x float64) float64

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 AntiDifferentiateFunction

func AntiDifferentiateFunction(f Function, a float64) Function

func DifferentiateFunction

func DifferentiateFunction(f Function) Function

func OffsetFunction

func OffsetFunction(f Function, off *Coord) Function

func ScaleFunction

func ScaleFunction(f Function, scale float64) Function

func ScaleFunctionPerAxis

func ScaleFunctionPerAxis(f Function, scale_x, scale_y float64) Function

func (Function) ToRelation

func (f Function) ToRelation() Relation

type Graph

type Graph struct {
	Bounds *Area
	Image  *image.RGBA

	BackgroundColor, RelationColor, AxisColor, GridColor color.Color
}

func NewGraph

func NewGraph(bounds *Area, scale float64) (*Graph, error)

func NewGraphWithColors

func NewGraphWithColors(bounds *Area, scale float64, bg_col, rel_col, axis_col, grid_col color.Color) (*Graph, error)

func (*Graph) ApplyComplexRelation

func (g *Graph) ApplyComplexRelation(rel ComplexRelation)

func (*Graph) ApplyComplexRelationInChunk

func (g *Graph) ApplyComplexRelationInChunk(rel ComplexRelation, dst *image.RGBA, r *image.Rectangle, ch chan struct{})

func (*Graph) AtCoord

func (g *Graph) AtCoord(c *Coord) color.Color

func (*Graph) AtPixel

func (g *Graph) AtPixel(pt image.Point) color.Color

func (*Graph) CoordToPixel

func (g *Graph) CoordToPixel(c *Coord) image.Point

func (*Graph) DrawAxes

func (g *Graph) DrawAxes()

func (*Graph) DrawDifferentialFunction

func (g *Graph) DrawDifferentialFunction(d DifferentialFunction, start *Coord)

func (*Graph) DrawDifferentialFunctionInDirection

func (g *Graph) DrawDifferentialFunctionInDirection(d DifferentialFunction, start *Coord, dx float64, col color.Color, ch chan struct{})

func (*Graph) DrawDifferentialFunctionWithColor

func (g *Graph) DrawDifferentialFunctionWithColor(d DifferentialFunction, start *Coord, col color.Color)

func (*Graph) DrawFunction

func (g *Graph) DrawFunction(f Function)

func (*Graph) DrawFunctionInRange

func (g *Graph) DrawFunctionInRange(f Function, start, end int, col color.Color, ch chan struct{})

func (*Graph) DrawFunctionWithColor

func (g *Graph) DrawFunctionWithColor(f Function, col color.Color)

func (*Graph) DrawGrid

func (g *Graph) DrawGrid()

func (*Graph) DrawLine

func (g *Graph) DrawLine(c0, c1 *Coord, col color.Color)

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 (g *Graph) DrawRelation(rel Relation)

func (*Graph) DrawRelationInChunk

func (g *Graph) DrawRelationInChunk(rel Relation, r *image.Rectangle, col color.Color, ch chan struct{})

func (*Graph) DrawRelationWithColor

func (g *Graph) DrawRelationWithColor(rel Relation, col color.Color)

func (*Graph) ImageHeight

func (g *Graph) ImageHeight() int

func (*Graph) ImageWidth

func (g *Graph) ImageWidth() int

func (*Graph) PixelToCoord

func (g *Graph) PixelToCoord(pt image.Point) *Coord

func (*Graph) SavePNG

func (g *Graph) SavePNG(w io.Writer) error

func (*Graph) SetCoord

func (g *Graph) SetCoord(c *Coord, col color.Color)

func (*Graph) SetPixel

func (g *Graph) SetPixel(pt image.Point, col color.Color)

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

type PolarFunction func(theta float64) float64

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 RGBA16

type RGBA16 struct {
	R, G, B, A uint16
}

func (RGBA16) RGBA

func (c RGBA16) RGBA() (r, g, b, a uint32)

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.

func Circle

func Circle(r float64) Relation

func CircleAt

func CircleAt(r float64, center *Coord) Relation

func Ellipse

func Ellipse(a, b float64) Relation

func EllipseAt

func EllipseAt(a, b float64, center *Coord) Relation

func InvertRelation

func InvertRelation(rel Relation) Relation

func OffsetRelation

func OffsetRelation(rel Relation, off *Coord) Relation

func RotateRelation

func RotateRelation(rel Relation, theta float64) Relation

func RotateRelationAround

func RotateRelationAround(rel Relation, theta float64, coord *Coord) Relation

func ScaleRelation

func ScaleRelation(rel Relation, scale float64) Relation

func ScaleRelationAround

func ScaleRelationAround(rel Relation, scale float64, coord *Coord) Relation

func ScaleRelationPerAxis

func ScaleRelationPerAxis(rel Relation, scale_x, scale_y float64) Relation

func ScaleRelationPerAxisAround

func ScaleRelationPerAxisAround(rel Relation, scale_x, scale_y float64, coord *Coord) Relation

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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