xi

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2021 License: Zlib Imports: 7 Imported by: 0

README

Ξ

Package xi provides function registration and implementations for xirho.

The following function types (variations) are implemented here:

  • Affine (the "triangles" in Apophysis)
  • Bipolar
  • Blur
  • Bubble
  • CElliptic (similar to elliptic)
  • ColorSpeed (like color and color symmetry in Apophysis)
  • Curl
  • Cylinder
  • Disc
  • Exblur
  • Exp
  • Farblur
  • Flatten
  • Foci
  • Gaussblur
  • Heat
  • Hole
  • JuliaN
  • LazySusan
  • Log
  • Mobius (a 3D version, like the mobiq plugin)
  • Perspective (like in the Apophysis render settings)
  • Polar
  • Rod
  • Scale (like linear or linear3D)
  • Scry
  • Spherical
  • Splits (the 3D version)
  • Sum (roughly implements the behavior of multiple variations in Apophysis)
  • Then (turns any function into a pre- or post- variant, and more general besides)

Adding new functions

Xi is designed so that external packages may add any number of functions during initialization. For example, in a package providing function types named "madoka" and "homura", one could do:

func init() {
    xi.Register("madoka", func() xirho.F { return Madoka{} })
    xi.Register("homura", newHomura)
}

Then madoka and homura, including any of their parameters, will be marshaled and unmarshaled automatically by package encoding. User interfaces will automatically have access to madoka and homura and their parameters through the same mechanisms by which they use any other function types.

Doing this also opens the option of creating Go plugins to distribute functions types easily. If the package providing madoka and homura is called anime, then one could add a file called e.g. plugin.go along these lines:

// +build ignore

package main

import _ "example.org/anime"

Then go build -buildmode=plugin plugin.go will create a Go plugin that a renderer program could load dynamically and automatically have madoka and homura. Note that Go does not implement -buildmode=plugin on Windows.

If xi is the best place for a new function, e.g. because it is very common in Apophysis, then make sure to follow the following steps:

  • Create the function type with Calc and Prep methods.
  • Register any factories in a func init() using must. There must be at least one factory, to ensure that the type implements xirho.Func.
  • Add it to this README, in the list near the top.
  • Create Flame parsers in package xirho/encoding/flame and add it to the README there.

Documentation

Overview

Package xi provides function registration and implementations for xirho.

External packages adding new function types only need to Register a factory here to automatically work with xirho serialization and user interfaces. Conversely, user interfaces will be primarily interested in the New, NameOf, and Names functions, as most of the rest of the work is done in package fapi.

Lastly, some users may want to use the function implementation types directly, either to decode systems serialized in another format (e.g. package encoding/flame) or to build a system by hand. As a general rule, if a function type has any parameters, it implements xirho.Func as a pointer, and if it has none, then it implements it as a (size zero) value.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NameOf

func NameOf(f xirho.Func) (name string, ok bool)

NameOf returns the name of a registered function. ok is false if there is no such function.

func Names

func Names(unique bool) []string

Names returns a list of all registered function names. If unique is true, then only the first name registered for each underlying type is used. The names are returned in lexicographically increasing order.

func New

func New(name string) xirho.Func

New creates a new function using a registered name. The result is nil if there is no function registered with the given name.

func Register

func Register(name string, factory func() xirho.Func) error

Register registers a function type by a factory which produces it. An error is returned if there is already a function with the given name. If the same underlying type is registered multiple times, the name passed in the first associated call to Register is used by NameOf.

Types

type Affine

type Affine struct {
	Ax xirho.Affine `xirho:"transform"`
}

Affine performs an affine transform.

func (*Affine) Calc

func (v *Affine) Calc(in xirho.Pt, rng *xirho.RNG) xirho.Pt

func (*Affine) Prep

func (v *Affine) Prep()

type Bipolar

type Bipolar struct {
	Shift xirho.Angle `xirho:"shift"`
}

Bipolar does bipolar

func (*Bipolar) Calc

func (v *Bipolar) Calc(in xirho.Pt, rng *xirho.RNG) xirho.Pt

func (*Bipolar) Prep

func (v *Bipolar) Prep()

type Blur

type Blur struct{}

Blur produces a noisy solid circle with unit radius.

func (Blur) Calc

func (Blur) Calc(in xirho.Pt, rng *xirho.RNG) xirho.Pt

func (Blur) Prep

func (Blur) Prep()

type Bubble

type Bubble struct{}

Bubble maps the plane to a sphere.

func (Bubble) Calc

func (Bubble) Calc(in xirho.Pt, rng *xirho.RNG) xirho.Pt

func (Bubble) Prep

func (Bubble) Prep()

type CElliptic

type CElliptic struct{}

CElliptic is a simpler, conformal modification of elliptic.

func (CElliptic) Calc

func (CElliptic) Calc(in xirho.Pt, rng *xirho.RNG) xirho.Pt

func (CElliptic) Prep

func (CElliptic) Prep()

type ColorSpeed

type ColorSpeed struct {
	// Color is the color coordinate toward which inputs move.
	Color xirho.Real `xirho:"color,0,1"`
	// Speed is the smoothing rate. A value of 0 means the output color always
	// equals Color; a value of 1 means the output color always equals the
	// input color.
	Speed xirho.Real `xirho:"speed,0,1"`
}

ColorSpeed performs exponential smoothing on the input color coordinate toward a chosen color.

func (*ColorSpeed) Calc

func (f *ColorSpeed) Calc(in xirho.Pt, rng *xirho.RNG) xirho.Pt

func (*ColorSpeed) Prep

func (f *ColorSpeed) Prep()

type Curl

type Curl struct {
	C1 xirho.Real `xirho:"c1"`
	C2 xirho.Real `xirho:"c2"`
}

Curl does curl

func (*Curl) Calc

func (v *Curl) Calc(in xirho.Pt, rng *xirho.RNG) xirho.Pt

func (*Curl) Prep

func (v *Curl) Prep()

type Cylinder

type Cylinder struct{}

Cylinder creates a cylinder with circular cross-sections of radius 1 in the x/z plane.

func (Cylinder) Calc

func (Cylinder) Calc(in xirho.Pt, rng *xirho.RNG) xirho.Pt

func (Cylinder) Prep

func (Cylinder) Prep()

type Disc

type Disc struct{}

Disc does disc.

func (Disc) Calc

func (Disc) Calc(in xirho.Pt, rng *xirho.RNG) xirho.Pt

func (Disc) Prep

func (Disc) Prep()

type Exblur

type Exblur struct {
	Str    xirho.Real `xirho:"strength"`
	Dist   xirho.Real `xirho:"dist"`
	Origin xirho.Vec3 `xirho:"origin"`
}

Exblur applies a radial blur with strength depending on distance from a point. Exblur is intended to be used following other functions in a Then.

func (*Exblur) Calc

func (v *Exblur) Calc(in xirho.Pt, rng *xirho.RNG) xirho.Pt

func (*Exblur) Prep

func (v *Exblur) Prep()

type Exp

type Exp struct {
	Base xirho.Complex `xirho:"base"`
	// contains filtered or unexported fields
}

Exp performs the complex exponential in a fixed base.

func (*Exp) Calc

func (v *Exp) Calc(in xirho.Pt, rng *xirho.RNG) xirho.Pt

func (*Exp) Prep

func (v *Exp) Prep()

type Farblur

type Farblur struct {
	Origin xirho.Vec3   `xirho:"origin"`
	Ax     xirho.Affine `xirho:"affine"`
	Dist   xirho.Real   `xirho:"dist"`
}

Farblur applies an affine-transformed Gaussian blur with strength varying according to distance from a point. Farblur is intended to be used following other functions in a Then.

func (*Farblur) Calc

func (v *Farblur) Calc(in xirho.Pt, rng *xirho.RNG) xirho.Pt

func (*Farblur) Prep

func (v *Farblur) Prep()

type Flatten

type Flatten struct{}

Flatten zeros the Z coordinate of the input.

func (Flatten) Calc

func (Flatten) Calc(in xirho.Pt, rng *xirho.RNG) xirho.Pt

func (Flatten) Prep

func (Flatten) Prep()

type Foci

type Foci struct{}

Foci does foci

func (Foci) Calc

func (Foci) Calc(in xirho.Pt, rng *xirho.RNG) xirho.Pt

func (Foci) Prep

func (Foci) Prep()

type Gaussblur

type Gaussblur struct{}

Gaussblur creates a spherical Gaussian blur.

func (Gaussblur) Calc

func (Gaussblur) Calc(in xirho.Pt, rng *xirho.RNG) xirho.Pt

func (Gaussblur) Prep

func (Gaussblur) Prep()

type Heat

type Heat struct {
	ThetaT xirho.Real  `xirho:"planar wave period"`
	ThetaP xirho.Angle `xirho:"planar wave phase"`
	ThetaA xirho.Real  `xirho:"planar wave amp"`

	PhiT xirho.Real  `xirho:"axial wave period"`
	PhiP xirho.Angle `xirho:"axial wave phase"`
	PhiA xirho.Real  `xirho:"axial wave amp"`

	RT xirho.Real  `xirho:"radial wave period"`
	RP xirho.Angle `xirho:"radial wave phase"`
	RA xirho.Real  `xirho:"radial wave amp"`
}

Heat applies transverse and radial waves.

func (*Heat) Calc

func (v *Heat) Calc(in xirho.Pt, rng *xirho.RNG) xirho.Pt

func (*Heat) Prep

func (v *Heat) Prep()

type Hole

type Hole struct {
	Amount xirho.Real `xirho:"amount"`
	Origin xirho.Vec3 `xirho:"origin"`
}

Hole translates points radially away from a point.

func (*Hole) Calc

func (v *Hole) Calc(in xirho.Pt, rng *xirho.RNG) xirho.Pt

func (*Hole) Prep

func (v *Hole) Prep()

type JuliaN

type JuliaN struct {
	Power xirho.Int  `xirho:"power"`
	Dist  xirho.Real `xirho:"dist"`
}

JuliaN does julian

func (*JuliaN) Calc

func (f *JuliaN) Calc(in xirho.Pt, rng *xirho.RNG) xirho.Pt

func (*JuliaN) Prep

func (f *JuliaN) Prep()

type LazySusan

type LazySusan struct {
	Inside  xirho.Affine `xirho:"inside"`
	Outside xirho.Affine `xirho:"outside"`
	Center  xirho.Vec3   `xirho:"center"`
	Radius  xirho.Real   `xirho:"radius"`
	Spread  xirho.Real   `xirho:"spread"`
	TwistZ  xirho.Real   `xirho:"twistZ"`
}

LazySusan transforms points by different affine transforms depending on whether the input is inside a selection sphere.

func (*LazySusan) Calc

func (v *LazySusan) Calc(in xirho.Pt, rng *xirho.RNG) xirho.Pt

func (*LazySusan) Prep

func (v *LazySusan) Prep()

type Log

type Log struct {
	Base xirho.Complex `xirho:"base"`
	// contains filtered or unexported fields
}

Log computes the complex logarithm of the input point treated as x+iy.

func (*Log) Calc

func (v *Log) Calc(in xirho.Pt, rng *xirho.RNG) xirho.Pt

func (*Log) Prep

func (v *Log) Prep()

type Mobius

type Mobius struct {
	Ar   xirho.Real `xirho:"A.scalar"`
	Avec xirho.Vec3 `xirho:"A.vector"`
	Br   xirho.Real `xirho:"B.scalar"`
	Bvec xirho.Vec3 `xirho:"B.vector"`
	Cr   xirho.Real `xirho:"C.scalar"`
	Cvec xirho.Vec3 `xirho:"C.vector"`
	Dr   xirho.Real `xirho:"D.scalar"`
	Dvec xirho.Vec3 `xirho:"D.vector"`

	InZero xirho.List `xirho:"input blank,r,i,j,k"`
}

Mobius implements Mobius transformations over quaternions.

func (*Mobius) Calc

func (v *Mobius) Calc(in xirho.Pt, rng *xirho.RNG) xirho.Pt

func (*Mobius) Prep

func (v *Mobius) Prep()

type Perspective

type Perspective struct {
	Distance xirho.Real `xirho:"distance"`
}

Perspective applies a perspective transform to the 3D spatial coordinates.

func (*Perspective) Calc

func (f *Perspective) Calc(in xirho.Pt, rng *xirho.RNG) xirho.Pt

func (*Perspective) Prep

func (f *Perspective) Prep()

type Polar

type Polar struct{}

Polar maps the x/y rectangular coordinates of the input to polar.

func (Polar) Calc

func (Polar) Calc(in xirho.Pt, rng *xirho.RNG) xirho.Pt

func (Polar) Prep

func (Polar) Prep()

type Rod

type Rod struct {
	Radius xirho.Real `xirho:"radius"`
}

Rod creates a solid cylinder of a given radius, with circular cross-sections in the x/z plane.

func (*Rod) Calc

func (v *Rod) Calc(in xirho.Pt, rng *xirho.RNG) xirho.Pt

func (*Rod) Prep

func (v *Rod) Prep()

type Scale

type Scale struct {
	Amount xirho.Real `xirho:"amount"`
}

Scale applies linear scaling.

func (*Scale) Calc

func (v *Scale) Calc(in xirho.Pt, rng *xirho.RNG) xirho.Pt

func (*Scale) Prep

func (v *Scale) Prep()

type Scry

type Scry struct {
	Radius xirho.Real `xirho:"radius"`
}

Scry maps space onto a sphere.

func (*Scry) Calc

func (v *Scry) Calc(in xirho.Pt, rng *xirho.RNG) xirho.Pt

func (*Scry) Prep

func (v *Scry) Prep()

type Spherical

type Spherical struct{}

Spherical calculates the conjugate of the complex reciprocal of the x and y of the input point treated as x+iy. The z and c coordinates are unchanged.

func (Spherical) Calc

func (Spherical) Calc(in xirho.Pt, rng *xirho.RNG) xirho.Pt

func (Spherical) Prep

func (Spherical) Prep()

type Splits

type Splits struct {
	X xirho.Real `xirho:"x"`
	Y xirho.Real `xirho:"y"`
	Z xirho.Real `xirho:"z"`
}

Splits spreads points away from the coordinate planes.

func (*Splits) Calc

func (v *Splits) Calc(in xirho.Pt, rng *xirho.RNG) xirho.Pt

func (*Splits) Prep

func (v *Splits) Prep()

type Sum

type Sum struct {
	Funcs xirho.FuncList `xirho:"funcs"`
	Color xirho.Func     `xirho:"color,optional"`
}

Sum performs a list of functions, summing the spatial coordinates. An additional function controls the color coordinate.

func (*Sum) Calc

func (f *Sum) Calc(in xirho.Pt, rng *xirho.RNG) (out xirho.Pt)

func (*Sum) Prep

func (f *Sum) Prep()

type Then

type Then struct {
	Funcs xirho.FuncList `xirho:"funcs"`
}

Then performs a list of functions performed in a set order, without plotting intermediate results.

func (*Then) Calc

func (f *Then) Calc(in xirho.Pt, rng *xirho.RNG) xirho.Pt

func (*Then) Prep

func (f *Then) Prep()

Jump to

Keyboard shortcuts

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