GitHubはじめる

API リファレンスはソースコード内の Go ドキュメントコメントから生成されており、英語で記述されています。

package pixelfx

import "github.com/nsgo-dev/game/pkg/pixelfx"

概要

Package pixelfx is a Go port of pixelfx (https://github.com/patch-gg/pixelfx), a library of pixel art effects and animations, each a small procedural program: fire, explosions, magic, weather, UI, pickups, transitions, critters, and character moves acted out with wind-up, hit-stop and recovery. A game built on NSGo can play, recolor and mirror them at run time and export them as sprite sheets, with no JavaScript.

This package is pixelfx's core: the Frame an effect draws into (opaque color plus additive light, put together by Composite), the Painter it draws with (dots, lines, discs, rings, glows, sprites, pixel text, placed, mirrored and rotated for it), seeded randomness and noise (Rng, Hash, Noise), closed-form particles for loops (Cycle, Stream) and simulated ones (Particles, Bits, Lights, Blazes), and the acting system: a 3D skeleton drawn to pixels (Rig, Pose), its acts (Act, Perform) and chains of effects played as one move (Chain).

Effects live in one subpackage per category, such as pixelfx/fire, which registers its effects as "<category>/<name>" when imported, so a game links only the categories it imports. Play one with NewPlayer, draw it each frame into a Frame, and show the frame with Image and View, or render it to a sprite sheet with Render and Frames.Sheet, which sprite.LoadAtlas reads; the game pixelfx command does that from the command line.

The port follows pixelfx at commit 5294518ce7c72e48b6100a744596e0acf57f2826 with the same math in float64, in the same order, so it draws the same pixels: every category's tests compare its effects with pixelfx's own frames. The code is under pixelfx's MIT license (LICENSE, NOTICE.md).

目次

定数

const Gravity = 950

Gravity is the simulation's gravity, in px/s².

const SkinNone = "none"

SkinNone, as a Hit's Skin, clears the target's skin.

const Tau = math.Pi * 2

Tau is a full turn in radians.

変数

var (
	White = Hex("#ffffff")
	Black = Hex("#000000")
	Ink   = Hex("#0b0a10")
	Patch = Hex("#f53cd1")
)

Colors pixelfx's effects share.

var Backdrops = []string{"dark", "ground", "sky", "light", "black"}

Backdrops are the kinds Backdrop draws.

var DummyPal = palette(map[rune]string{
	'k': "#0e0c14", 'A': "#e4e6ec", 'B': "#b6b9c3", 'C': "#868995", 'D': "#5c5e6a", 'E': "#6e707c", 'F': "#4b4d58", 'G': "#34353f", 'J': "#2a2b33", 'm': "#f53cd1",
})

DummyPal holds the dummy's colors: a neutral shell that lets any effect's colors do the talking, near and far limbs, dark bands at the joints, a small mark.

var Ease = struct {
	Linear, InQuad, OutQuad, InOutQuad, InCubic, OutCubic, InOutCubic, InQuart, OutQuart, InExpo, OutExpo, InSine, OutSine, InOutSine, InBack, OutBack, OutElastic, OutBounce func(t float64) float64
}{
	Linear:  func(t float64) float64 { return t },
	InQuad:  func(t float64) float64 { return t * t },
	OutQuad: func(t float64) float64 { return 1 - (1-t)*(1-t) },
	InOutQuad: func(t float64) float64 {
		if t < 0.5 {
			return 2 * t * t
		}
		return 1 - math.Pow(-2*t+2, 2)/2
	},
	InCubic:  func(t float64) float64 { return t * t * t },
	OutCubic: func(t float64) float64 { return 1 - math.Pow(1-t, 3) },
	InOutCubic: func(t float64) float64 {
		if t < 0.5 {
			return 4 * t * t * t
		}
		return 1 - math.Pow(-2*t+2, 3)/2
	},
	InQuart:  func(t float64) float64 { return t * t * t * t },
	OutQuart: func(t float64) float64 { return 1 - math.Pow(1-t, 4) },
	InExpo: func(t float64) float64 {
		if t <= 0 {
			return 0
		}
		return math.Pow(2, 10*t-10)
	},
	OutExpo: func(t float64) float64 {
		if t >= 1 {
			return 1
		}
		return 1 - math.Pow(2, -10*t)
	},
	InSine:    func(t float64) float64 { return 1 - math.Cos((t*math.Pi)/2) },
	OutSine:   func(t float64) float64 { return math.Sin((t * math.Pi) / 2) },
	InOutSine: func(t float64) float64 { return -(math.Cos(math.Pi*t) - 1) / 2 },
	InBack:    func(t float64) float64 { return InBack(t, 1.70158) },
	OutBack:   func(t float64) float64 { return OutBack(t, 1.70158) },
	OutElastic: func(t float64) float64 {
		if t <= 0 {
			return 0
		}
		if t >= 1 {
			return 1
		}
		return math.Pow(2, -10*t)*math.Sin((t*10-0.75)*((2*pi)/3)) + 1
	},
	OutBounce: func(t float64) float64 {
		const n, d = 7.5625, 2.75
		if t < 1/d {
			return n * t * t
		}
		if t < 2/d {
			t -= 1.5 / d
			return n*t*t + 0.75
		}
		if t < 2.5/d {
			t -= 2.25 / d
			return n*t*t + 0.9375
		}
		t -= 2.625 / d
		return n*t*t + 0.984375
	},
}

Easing curves: input 0..1, output 0..1 (back and elastic overshoot).

var FireRamp = Ramp("#ffffff", "#fff3a6", "#ffe26b", "#ffc23d", "#ff8a2a", "#f2561d", "#c9281f", "#8a1f17", "#4a1712")

FireRamp runs from white-hot to smouldering, the ramp a Fire particle walks down.

var Fonts = map[string]*Font{
	"mini": {H: 5, Space: 2, Gap: 1, Glyphs: buildFont(miniGlyphs, 5)},
	"big":  {H: 7, Space: 3, Gap: 1, Glyphs: buildFont(bigGlyphs, 7)},
}

Fonts are pixelfx's two in-code pixel fonts, "mini" (3x5) and "big" (5x7).

var Hero = []string{
	"....kkkkk...",
	"..kkhhhhhk..",
	".khhhhhhhhk.",
	".khhhhhhhhhk",
	".khhssssshhk",
	".khsessesshk",
	".khsessesshk",
	"..ksssssssk.",
	"...kkSSSkk..",
	"..kttttttk..",
	".kttTttTttk.",
	".ksttTTttsk.",
	".kstttttttk.",
	"..kbbbbbbk..",
	"..kppkkppk..",
	"..kppk.kppk.",
	"..kppk.kppk.",
	"..koook.kook",
	"..kkkkk.kkkk",
}

Hero is the stock character at 12 x 19 px.

var Hero2 = []string{
	"...........kkk..........",
	"..........kAABk.........",
	".........kAAABJk........",
	".........kABBJJk........",
	".........kBBBJCDk.......",
	".........kBCJDDDk.......",
	".........kkJJJDk........",
	".......kkkkABBJCkk......",
	"......kAABCJBCCCkDk.....",
	"......kABBCJCCCmDkDk....",
	"......kBBCDDJCDDDkDk....",
	"......kABCDJDDDDDkk.....",
	".....kAABDkDDDDJkk......",
	".....kABCDkDDJJGkk......",
	".....kABCkJJJGGGkk......",
	"....kJJCDkFFFGGGk.......",
	"....kAJJDkJJJGGGk.......",
	"....kJCJJkABBJGGk.......",
	".....kJCCkBBCDJJJk......",
	".....kCCCJBBCDJJDk......",
	".....kCCCDJCCDkJDDk.....",
	"......kCDDJBCDkDDDk.....",
	".......kDJJJCDkDDDkk....",
	".......kJBCJCDkDDDkk....",
	".......kBDJBCDkCDDkk....",
	"........kJJBCDkCDDk.....",
	"........kBBBCDkCCDDk....",
	"........kBBBCDkCCDDk....",
	".........kBBCDkJDDDk....",
	"........kBJJJJkCJJJk....",
	"........kBBCCDkCCDDk....",
	"........kBBCDDkCDDk.....",
	"........kBBCDkCCDDk.....",
	"........kBCCDkCCDDk.....",
	"........kBCDDkCDDDk.....",
	".......kJBCJkkkDJkkkk...",
	".......kAJJAAAAkCCCCCk..",
	"........kkkkkkkkkkkkk...",
}

Hero2 is the same character at twice the size (24 x 38), standing easy: the rest pose of the rig, baked.

var HeroPal = palette(map[rune]string{
	'k': "#17121f", 'h': "#7a4128", 's': "#f3c49d", 'S': "#c98b6c", 'e': "#17121f",
	't': "#5f6f94", 'T': "#46536f", 'b': "#8a5a32", 'p': "#38334a", 'o': "#6a4030",
	'H': "#a35d34", 'w': "#ffffff", 'm': "#a3564a", 'g': "#e8c060", 'L': "#7f90b6", 'O': "#8f5a3f", 'P': "#4b4560",
	'c': "#f53cd1", 'C': "#ff8fe6", 'D': "#a31f8a",
})

HeroPal holds Hero's colors, and those of the larger character's extra detail and scarf.

var Pal = map[string][]string{
	"fire":     {"#1f0b10", "#4a1118", "#8c1d1c", "#cc3a1a", "#f2701f", "#ffae35", "#ffe27a", "#fff8d6"},
	"ember":    {"#1a0a0e", "#3d1012", "#701a14", "#a8301a", "#e0561e", "#ff8a2a", "#ffc46a"},
	"lava":     {"#14060a", "#380a10", "#6e1210", "#ac2410", "#e8501a", "#ff8c2a", "#ffd25a"},
	"smoke":    {"#0e0c12", "#1d1a22", "#2e2a35", "#433e4b", "#5c5664", "#7b7484", "#a39cab"},
	"dust":     {"#1c1610", "#33281c", "#4f3f2c", "#6e5a40", "#927a58", "#b89f78", "#dcc8a2"},
	"ice":      {"#0c1430", "#162c5c", "#1f4f94", "#2f7fcc", "#58b4ec", "#9bdcff", "#d8f4ff", "#ffffff"},
	"water":    {"#081830", "#0e2e5a", "#14508c", "#1c76bc", "#36a2e0", "#78ccf4", "#c4ecff", "#ffffff"},
	"electric": {"#0a0f2e", "#172a78", "#2550d0", "#3f8cff", "#7cc8ff", "#c8f0ff", "#ffffff"},
	"volt":     {"#24160a", "#5e3a0c", "#a8680f", "#e8a218", "#ffd23c", "#fff08a", "#ffffff"},
	"poison":   {"#0d1a0c", "#173a14", "#265e18", "#3f8a1e", "#6cb82a", "#a8e04a", "#e0ff8a"},
	"holy":     {"#2a1c08", "#5a3e10", "#9a6c18", "#d8a428", "#ffd84a", "#fff09a", "#fffbe6", "#ffffff"},
	"heal":     {"#08201a", "#0f3f2c", "#17663e", "#24924e", "#3ec466", "#7ee88a", "#c8ffc4", "#ffffff"},
	"arcane":   {"#140a26", "#2b1252", "#481c88", "#6b2cc0", "#9a48ec", "#c684ff", "#ecc8ff", "#ffffff"},
	"shadow":   {"#050308", "#0f0a18", "#1c1230", "#2c1a4a", "#432468", "#5e3290", "#8048b8", "#a970e0"},
	"blood":    {"#14040a", "#3a0a14", "#6a101c", "#a01824", "#d42a30", "#ff5a50", "#ff9a8a"},
	"earth":    {"#140e0a", "#2a1e14", "#47321e", "#69492a", "#8e6638", "#b88a52", "#dcb47c"},
	"stone":    {"#0e0e12", "#1c1c24", "#2c2c38", "#42424f", "#5c5c6b", "#7d7d8c", "#a4a4b2", "#d0d0da"},
	"gold":     {"#1e1206", "#4a2c08", "#86520c", "#c48412", "#f0b424", "#ffe066", "#fff6c4", "#ffffff"},
	"leaf":     {"#0c1a0e", "#163418", "#225224", "#357530", "#4f9a3a", "#7cc048", "#b4e070", "#e4ffb0"},
	"wood":     {"#160c06", "#2e1a0c", "#4a2c14", "#6a421e", "#8e5c2c", "#b47c40", "#d8a464"},
	"metal":    {"#0c0e14", "#1c2230", "#2e3648", "#4a5468", "#6e7a90", "#9aa6ba", "#d0d8e6", "#ffffff"},
	"bone":     {"#1a1814", "#3a352c", "#5e5648", "#8a806c", "#b8ad96", "#e4dcc8", "#fffaf0"},
	"neon":     {"#1a0516", "#3d0a33", "#701560", "#b0228f", "#f53cd1", "#ff86e6", "#ffd2f6", "#ffffff"},
	"cyber":    {"#041418", "#08303a", "#0c5260", "#108088", "#18b4b0", "#4ce8d8", "#b4fff0", "#ffffff"},
	"matrix":   {"#020a04", "#05200c", "#0a3c16", "#106624", "#1a9a34", "#3cd650", "#a4ffa8", "#e8ffe8"},
	"candy":    {"#ff4a5a", "#ff9a2a", "#ffe03c", "#5ad84a", "#3cc8ff", "#7a6cff", "#f53cd1"},
	"night":    {"#07060d", "#0c0a18", "#131026", "#1b1734", "#241f44", "#2f2956"},
}

Pal holds pixelfx's hue-shifted ramps as hex colors, dark to bright: shadows lean cool or deep, highlights lean warm or white. Effects take a palette option, so any of these (or your own) can recolor them.

var Ramps = func() map[string][]uint32 {
	out := make(map[string][]uint32, len(Pal))
	for k, v := range Pal {
		out[k] = Ramp(v...)
	}
	return out
}()

Ramps holds the ramps of Pal as colors.

var Ready = Pose{}.With(Crouch.Is(3), FX.Is(11), FY.Is(-21), BX.Is(9), BY.Is(-21), FFX.Is(7), FBX.Is(-7))

Ready is the stance acts start from. A pose only says what differs from standing easy (Stand), in screen terms, px from the feet, y negative up; Pose says what each key does.

var Skins = map[string]Skin{
	"flash":  {tpWhite, 1},
	"char":   {Hex("#1a0c0e"), 0.72},
	"ice":    {Hex("#a8e8ff"), 0.72},
	"shadow": {Hex("#3a1a70"), 0.5},
	"holy":   {Hex("#fff4c0"), 0.5},
	"red":    {Hex("#ff2040"), 0.45},
	"shock":  {Hex("#8fd6ff"), 0.6},
	"poison": {Hex("#58c43a"), 0.5},
}

Skins are the looks a hit can leave on the target, by name; "flash" is the white flash every hit gives.

var SmokeRamp = Ramp("#7b6f72", "#5d5660", "#433d48", "#2b2630", "#1a171e")

SmokeRamp runs from fresh smoke to thin, the ramp a Smoke particle walks down.

var Stand = Pose{}.With(Lean.Is(0), Crouch.Is(0), Yaw.Is(0), FX.Is(-3), FY.Is(-15), BX.Is(5), BY.Is(-15), FFX.Is(-2), FFY.Is(-4), FBX.Is(3), FBY.Is(-4))

Stand is standing easy, in screen terms: hands and feet are where they should end up, y negative is up.

var Weapons = map[string]*Weapon{
	"sword": {Two: -4.4, HasTwo: true, Draw: func(T *Hand, q Pose, _ [3]float64) {
		end := -2.6
		if q.on(Two) {
			end = -6.5
		}
		haft(T, end, 2.2, steel["grip"], steel["gripD"], 0.8)
		for k := -1.4; k <= 1.4; k += 0.4 {
			T.Put(end-0.4, k, steel["gold"], 0)
		}
		for k := -4.6; k <= 4.6; k += 0.4 {
			T.Put(2.6, k, pick2(math.Abs(k) > 3.8, steel["goldD"], steel["gold"]), 0)
			T.Put(3, k, steel["goldD"], 0)
		}
		blade(T, 3.2, 25, 2.2)
	}},
	"greatsword": {Two: -4.8, HasTwo: true, Draw: func(T *Hand, _ Pose, _ [3]float64) {
		haft(T, -7.2, 2.2, steel["grip"], steel["gripD"], 0.8)
		for k := -1.8; k <= 1.8; k += 0.4 {
			T.Put(-7.6, k, steel["gold"], 0)
		}
		for k := -6.6; k <= 6.6; k += 0.4 {
			T.Put(2.6, k, pick2(math.Abs(k) > 5.6, steel["goldD"], steel["gold"]), 0)
			T.Put(3, k, steel["goldD"], 0)
		}
		blade(T, 3.2, 31, 3)
		for i := 4.0; i <= 28; i += 0.4 {
			T.Put(i, 0, steel["b"], 0)
		}
	}},
	"dagger": {Draw: func(T *Hand, _ Pose, _ [3]float64) {
		haft(T, -2.4, 1.8, steel["grip"], steel["gripD"], 0.8)
		for k := -2.6; k <= 2.6; k += 0.4 {
			T.Put(2.2, k, steel["goldD"], 0)
		}
		blade(T, 2.6, 10, 1.3)
	}},
	"spear": {Two: -12, HasTwo: true, Draw: func(T *Hand, _ Pose, _ [3]float64) {
		haft(T, -18, 36, steel["wood"], steel["woodD"], 0.5)
		blade(T, 36, 11, 2)
		for k := -2.4; k <= 2.4; k += 0.4 {
			T.Put(36, k, steel["goldD"], 0)
		}
	}},
	"hammer": {Two: -7, HasTwo: true, Draw: func(T *Hand, _ Pose, _ [3]float64) {
		for _, lift := range [3]float64{-0.8, 0, 0.8} {
			for i := -10.0; i <= 18; i += 0.4 {
				for k := -0.8; k <= 0.81; k += 0.4 {
					T.Put(i, k, pick2(k > 0.1, steel["woodD"], steel["wood"]), lift)
				}
			}
		}

		for i := 18.0; i <= 28; i += 0.4 {
			for k := -9.0; k <= 9; k += 0.4 {
				var face uint32
				switch {
				case math.Abs(k) > 7.4:
					face = pick2(k < 0, steel["a"], steel["d"])
				case i < 20:
					face = steel["hi"]
				case i > 26.4:
					face = steel["d"]
				case math.Abs(k) < 2:
					face = steel["gold"]
				default:
					face = steel["b"]
				}
				T.Put(i, k, face, 4.5)
				T.Put(i, k, face, -4.5)
				if i < 18.4 || i > 27.6 || math.Abs(k) > 8.6 {
					for l := -4.0; l <= 4; l += 0.4 {
						var c uint32
						switch {
						case k < 0:
							c = steel["a"]
						case i > 27.6:
							c = steel["d"]
						default:
							c = steel["b"]
						}
						T.Put(i, k, c, l)
					}
				}
			}
		}
	}},
	"scythe": {Two: -11, HasTwo: true, Draw: func(T *Hand, _ Pose, _ [3]float64) {
		haft(T, -16, 31, steel["dark"], steel["darkD"], 0.5)
		for j := 0.0; j <= 28; j += 0.4 {
			u := j / 28
			w, b := 3.2*(1-u)+0.3, 31.5-u*u*12
			for k := -w; k <= w; k += 0.4 {
				var c uint32
				switch {
				case k > w*0.3:
					c = steel["hi"]
				case k < -w*0.4:
					c = steel["d"]
				default:
					c = steel["b"]
				}
				T.Put(b+k, j+0.8, c, 0)
			}
		}
	}},
	"claw": {Draw: func(T *Hand, _ Pose, _ [3]float64) {
		for _, q0 := range [3]float64{-2.4, 0, 2.4} {
			for i := 2.0; i <= 9.5; i += 0.4 {
				u := (i - 2) / 7.5
				k := q0 + u*u*1.8
				T.Put(i, k, pick2(u > 0.55, steel["hi"], steel["a"]), 0)
				if u < 0.6 {
					T.Put(i, k+0.8, steel["d"], 0)
				}
			}
		}
	}},
	"bow": {Across: true, Draw: func(T *Hand, q Pose, off [3]float64) {
		for u := -1.0; u <= 1.001; u += 0.025 {
			k, i := u*17, 6*(1-u*u)-1
			T.Put(i, k, pick2(math.Abs(u) > 0.85, steel["goldD"], steel["wood"]), 0)
			T.Put(i+0.8, k, steel["woodD"], 0)
		}
		tipA, tipB := vec(T.At(-1, -17)), vec(T.At(-1, 17))
		mid := vec(T.At(-1, 0))
		if q.on(Pull) {
			mid = vec(off)
		}
		T.line(tipA, mid, steel["a"])
		T.line(tipB, mid, steel["a"])
		if q.on(Nocked) {
			T.line(mid, vec(T.At(13, 0)), steel["wood"])
			for i := 9.0; i <= 13; i += 0.4 {
				for k := -(13 - i) * 0.45; k <= (13-i)*0.45; k += 0.4 {
					T.Put(i, k, steel["hi"], 0)
				}
			}
		}
	}},
	"pistol": {Across: true, Draw: func(T *Hand, _ Pose, _ [3]float64) {
		for i := -1.0; i <= 9.5; i += 0.4 {
			for k := -4.2; k <= -2.4; k += 0.4 {
				var c uint32
				switch {
				case k < -3.6:
					c = steel["a"]
				case k > -2.9:
					c = steel["d"]
				default:
					c = steel["b"]
				}
				T.Put(i, k, c, 0)
			}
		}
		for i := -1.2; i <= 1.2; i += 0.4 {
			for k := -2.4; k <= 2.4; k += 0.4 {
				T.Put(i, k, steel["gripD"], 0)
			}
		}
		T.Put(9, -4.6, steel["hi"], 0)
	}},
	"launcher": {Two: -9, HasTwo: true, Draw: func(T *Hand, _ Pose, _ [3]float64) {
		for i := -14.0; i <= 22; i += 0.4 {
			for k := -6.0; k <= -1; k += 0.4 {
				var c uint32
				switch {
				case k < -4.8:
					c = steel["oliveA"]
				case k > -2.2:
					c = steel["oliveD"]
				case math.Abs(i-3) < 1.4:
					c = steel["gold"]
				default:
					c = steel["olive"]
				}
				T.Put(i, k, c, 0)
			}
		}
		for k := -6.8; k <= -0.2; k += 0.4 {
			T.Put(22.4, k, steel["b"], 0)
			T.Put(-14.4, k, steel["d"], 0)
		}
	}},
	"handle": {Draw: func(T *Hand, _ Pose, _ [3]float64) {
		haft(T, -2.6, 6, steel["grip"], steel["gripD"], 0.8)
		for k := -1.6; k <= 1.6; k += 0.4 {
			T.Put(-3, k, steel["gold"], 0)
			T.Put(6.4, k, steel["gold"], 0)
		}
	}},
}

Weapons are what the character can hold, by name: the fist is at 0 along each.

関数

func ActFrameSize(e *Effect, rig *Rig) (w, h int, x, y float64)

ActFrameSize returns the size of the frames EachActFrame renders and where the feet sit in them, with the act's bounds sampled by rig.

func ActSpan(e *Effect) (from, to float64)

ActSpan returns when an act's poses begin and end, in effect time; a loop ends when it's told to (to is +Inf).

func AngleTo(x0, y0, x1, y1 float64) float64

AngleTo returns the angle from (x0, y0) to (x1, y1) in radians.

func At(r []uint32, t float64) uint32

At returns the ramp step for t in 0..1, no blending: pixel art picks a color, it doesn't fade between two.

func Backdrop(kind string, w, h, groundY int) []uint32

Backdrop returns a backdrop as w x h colors. kind is "dark", "ground" (a stone floor from groundY down), "sky" (a night gradient with stars), "light" or "black"; any other kind is "dark".

func Band(p *Painter, cx, cy, r, sy, th, k float64, ramp []uint32, keep func(ang float64) bool, hot bool)

Band draws a ring on a tilted plane (sy squashes it: 0.16 lies on the floor, 1 stands up), th thick inward, at alpha k, colored by depth through the band with ramp (dark to bright; white at the outer edge when hot). keep(angle) picks which part to draw, so the far half can go behind things and the near half in front: func(g) bool { return math.Sin(g) < 0 } is the far half; nil draws all of it.

func Blend(r []uint32, t float64) uint32

Blend returns the color blended along a ramp at t (for light, where smooth is right).

func Blue(c uint32) uint32

Blue returns c's blue channel.

func Bolt(r *Rng, x0, y0, x1, y1, jag float64, depth int) [][2]float64

Bolt returns a jagged lightning path from (x0, y0) to (x1, y1) by midpoint displacement, depth times over. jag is how far a midpoint may move sideways, as a share of the segment's length (pixelfx's defaults are 0.22 and 5).

func Bump(t, t0, t1 float64) float64

Bump returns 0 → 1 → 0 over the window [t0, t1] (a sine bump).

func Burst(n int, seed float64, fn func(r *Rng, i int))

Burst calls fn for n one-shot particles, each with a repeatable generator (the same numbers every frame).

func Chain(cues []Cue) func(o *Options) Instance

Chain returns an effect's New for a list of cues.

func Clamp(x float64) float64

Clamp returns x held to [0, 1].

func ClampTo(x, a, b float64) float64

ClampTo returns x held to [a, b].

func Composite(f *Frame, out []byte, bg []uint32, lightK float64) []byte

Composite writes the frame's color over a background, plus its light scaled by lightK (1 is as drawn), into out as RGBA bytes, w * h * 4 of them, and returns it; a nil or short out is replaced by a new slice. bg is nil for transparency, one color for a flat background, or w * h colors. Over transparency, light becomes color with alpha (its brightest channel), which reads as additive over dark backgrounds. The bytes are straight (not premultiplied) alpha, as PNG stores them.

func Crystal(p *Painter, x, base, h, w, lean float64, ramp []uint32, a float64, white bool, glint float64)

Crystal draws a faceted crystal spike standing on (x, base), h tall, w wide at its base, leaning lean px at the tip, shaded in ramp (dark to bright, 6+ steps): a lit ridge, a bright left face, a darker right face, a dark rim. a is its alpha, white flashes it white, and glint (0..1 up its height, or -1 for none) sweeps a highlight.

func Cycle(t, period float64, count int, seed float64, life func(g *Rng) float64, fn func(age, life float64, r *Rng, i int))

Cycle runs particles that repeat every period seconds, for loops with no seam. Particle i is born at its own phase in the period and lives life(g) seconds (g is its own generator, already used once for its phase). For every live copy, fn(age, life, r, i) is called; r is a fresh generator for particle i, the same each period.

func Dist(x0, y0, x1, y1 float64) float64

Dist returns the distance between (x0, y0) and (x1, y1).

func DrawActor(p *Painter, actor *Actor, a float64)

DrawActor draws the stock actor with its feet at the painter's origin, at alpha a (dithered); nil draws the 12 x 19 one.

func DrawScaled(d *core.Drawing, src core.ImageSource, x, y, scale float32)

DrawScaled draws src at (x, y) scaled by scale with smoothing off, so pixel art stays crisp; src must say its Size.

func EachActFrame(e *Effect, o Options, fps int, fn func(i int, t, shakeX, shakeY float64, f *Frame))

EachActFrame renders e acted out, the character and the target with it, the way pixelfx's act tool does: in a frame sized by ActFrameSize, at fps (60 when 0), from the first pose until the act is done or after 8 seconds (two loops for a loop), then 0.3 seconds more for a one-shot. fn gets each frame's index, the performance's time and shake, and the frame, which it must not keep.

func EachFrame(e *Effect, o Options, fps int, fn func(i int, f *Frame))

EachFrame renders every frame of e the way pixelfx renders a sprite sheet, calling fn with each frame's index and the frame: e is placed at its meta's origin with o's flip, angle, light, actor and values, played at fps (its meta's when 0) for round(duration * fps) frames, one more for a one-shot so its last frame is its end, stepping 1/fps between them, with light eased out over the last 8 pixels of each edge unless it fills the screen. fn must not keep the frame, which is reused.

func EdgeFade(f *Frame, e int)

EdgeFade eases the frame's light out over the last e pixels of each edge, in place, leaving color alone: a glow cut off by the canvas edge shows as a box once a frame sits in a game. pixelfx's sprite sheets fade 8 pixels.

func Fbm(x, y, seed float64, octaves int) float64

Fbm returns fractal 2D noise in about [-1, 1], octaves layers of Noise2 (pixelfx's default is 3).

func Fit(r []uint32, n int) []uint32

Fit resamples ramp r to exactly n steps, keeping its ends (the darkest and brightest stay put), so an effect can index steps by number whatever length of palette a caller passes. It returns r itself when it already has n steps, and nil when r is empty, since there is nothing to resample.

func Fixed(life float64) func(g *Rng) float64

Fixed returns a particle life that is always life seconds, for Cycle and Stream.

func Flare(p *Painter, x, y, L, k float64, ramp []uint32)

Flare draws an 8-ray flare: long rays on the axes, shorter between, fading out along their length. ramp runs dark to bright.

func Fly(x, y, vx, vy, t, g, drag float64) (float64, float64)

Fly returns where a particle is after t seconds, launched from (x, y) at (vx, vy) px/s, under gravity g (px/s², positive is down) and linear drag (1/s).

func FlyV(vx, vy, t, g, drag float64) (float64, float64)

FlyV returns a flying particle's velocity at t, for streaks that point along the motion.

func Forks(r *Rng, path [][2]float64, o ForkOpts) [][][2]float64

Forks returns branches off a bolt path, each a bolt of depth 3.

func Fract(x float64) float64

Fract returns the fractional part of x, x - floor(x).

func Green(c uint32) uint32

Green returns c's green channel.

func Hash(ns ...float64) uint32

Hash returns a 32-bit integer hash of any number of integers; each is converted as JavaScript's n | 0 converts it.

func Hex(h string) uint32

Hex reads a color as ParseHex does ("#rgb", "#rrggbb", or "#rrggbbaa" with its alpha ignored) and panics on anything else: use it for colors written in code.

func Hypot(x, y float64) float64

Hypot returns sqrt(x*x + y*y) the way JavaScript's Math.hypot computes it, scaled by the larger value and summed with Kahan compensation, so a port gets the same last bit.

func Hypot3(x, y, z float64) float64

Hypot3 returns sqrt(x*x + y*y + z*z) the way JavaScript's Math.hypot computes it.

func IDs() []string

IDs returns the ids of every registered effect, sorted.

func InBack(t, s float64) float64

InBack is the back-in easing with overshoot s (1.70158 in Ease.InBack).

func InvLerp(a, b, x float64) float64

InvLerp returns how far x is from a to b, 0 when a and b are equal.

func IsScreen(m *Meta) bool

IsScreen reports whether an effect fills the screen (transitions, weather, impact frames): 16:9 and at least 320 wide. Its frames keep their light to the edge.

func Lerp(a, b, t float64) float64

Lerp returns the point t of the way from a to b.

func LoopNoise(phase, radius, seed float64) float64

LoopNoise returns noise that loops: the same value at phase 0 and phase 1, for seamless loops (pixelfx's default radius is 1).

func Luma(c uint32) float64

Luma returns c's perceived brightness, 0..1.

func Mix(a, b uint32, t float64) uint32

Mix returns the linear mix of a and b, t (held to 0..1) of the way to b.

func Ngon(cx, cy, r float64, n int, rot float64) [][2]float64

Ngon returns the corners of a regular polygon with n sides, turned by rot.

func Noise(x, seed float64) float64

Noise returns smooth 1D value noise in [-1, 1].

func Noise2(x, y, seed float64) float64

Noise2 returns smooth 2D value noise in [-1, 1].

func OutBack(t, s float64) float64

OutBack is the back-out easing with overshoot s (1.70158 in Ease.OutBack).

func ParseHex(h string) (uint32, error)

ParseHex reads "#rgb", "#rrggbb" or "#rrggbbaa" as an opaque color: the alpha of "#rrggbbaa" must be hex digits but is ignored, since every color here is opaque.

func Pick[T any](r *Rng, list []T) T

Pick returns one of list, chosen by r.

func PingPong(x float64) float64

PingPong returns x bounced between 0 and 1.

func RGB(r, g, b float64) uint32

RGB returns the opaque color (r, g, b); each channel is converted as JavaScript's x & 255 converts it, so fractions truncate.

func Ramp(list ...string) []uint32

Ramp returns a list of hex colors (dark to bright) as colors, panicking on a malformed one as Hex does.

func Rand(ns ...float64) float64

Rand returns a deterministic random number in [0, 1) from integers (seed, particle index, which value...).

func RasterText(str, font string, plot func(x, y int))

RasterText calls plot(x, y) for every inked pixel of str set in font ("mini" or "big"), with the top-left of the text at (0, 0).

func Red(c uint32) uint32

Red returns c's red channel.

func Register(id string, e *Effect)

Register adds e to the registry as id, "<category>/<name>" such as "fire/torch", and sets e.ID. A category package registers its effects when it is imported. It panics when id is malformed or taken.

func Remap(x, a0, a1, b0, b1 float64) float64

Remap maps x from [a0, a1] to [b0, b1].

func Round(x float64) float64

Round rounds x half up, as JavaScript's Math.round does: Round(-2.5) is -2.

func Scale(c uint32, k float64) uint32

Scale multiplies c's brightness by k.

func Seg(t, t0, t1 float64) float64

Seg returns the progress 0..1 of t through the window [t0, t1]: 0 before it, 1 after it.

func Shortfall(pose Pose) float64

Shortfall returns how far short of where the pose wants them the hands fall, in px: arms don't stretch.

func Sign(x float64) float64

Sign returns -1, 0 or 1 by the sign of x, as JavaScript's Math.sign does.

func Smooth(e0, e1, x float64) float64

Smooth returns the Hermite smoothstep of x between e0 and e1.

func Sparkle(p *Painter, x, y, arm float64, c, tip uint32, k float64)

Sparkle draws a star glint: arms of length arm in color c with tips in tip, a white heart, light of strength k (pixelfx's defaults are tip c and k 0.6).

func Star(cx, cy, r0, r1 float64, n int, rot float64) [][2]float64

Star returns the points of a star with n points between radii r1 (tips) and r0 (inner corners), turned by rot (pixelfx's defaults are 5 and -π/2).

func Stream(t, t0, t1, rate, seed float64, life func(g *Rng) float64, fn func(age, life float64, r *Rng, i int))

Stream runs particles born at a steady rate (per second) between t0 and t1, an emitter that stops: fn(age, life, r, i) for every particle alive at t.

func TextWidth(str, font string) int

TextWidth returns the width in font pixels of str set in font ("mini" or "big"), before scaling.

func TileFbm(x, y, px, py, seed float64, octaves int) float64

TileFbm returns fractal TileNoise: every octave keeps the repeat, so scrolled fields still loop.

func TileNoise(x, y, px, py, seed float64) float64

TileNoise returns 2D value noise whose lattice repeats every px cells in x and py cells in y (0: no repeat). Scroll it by exactly py cells over a loop and the loop has no seam: TileNoise(x, y+phase*py, 0, py, seed).

func ToHex(c uint32) string

ToHex returns c as "#rrggbb", leaving out its alpha.

func ToInt32(x float64) int32

ToInt32 converts x to a 32-bit integer the way JavaScript's x | 0 does: truncated toward zero and wrapped modulo 2^32, with NaN and infinities giving 0.

func ToUint32(x float64) uint32

ToUint32 converts x to an unsigned 32-bit integer the way JavaScript's x >>> 0 does.

func Trail(pos func(t float64) [2]float64, t float64, n int, dt float64) [][2]float64

Trail returns pos(t - i*dt) for i = 0..n-1, held at time 0: a moving thing's trail, newest first.

func Wrap(x, m float64) float64

Wrap returns x modulo m, always on the sign of m.

型

type Act struct {
	Poses   []Key
	Hits    []Hit
	Dust    []DustKick
	Targets []float64
	OnBody  bool
	Follow  Opt
	Ghost   string
}

Act is how a character performs an effect: Poses over time, Hits, Dust, straw Targets at x along the floor (pixelfx's default is 66), OnBody when the effect paints the standing body so each body pixel must carry it into the pose, Follow how much the body's lean and crouch carry what the effect drew on it (1 when unsaid), and Ghost the color of its after-images ("" for the effect's own palette).

type Actor struct {
	Mask   *Mask
	Pixels []uint32
	X, Y   float64
	W, H   int
	K      int
	Head   [2]float64
	Chest  [2]float64
	Eyes   [][2]float64
}

Actor is a character an effect wraps, hits or sits behind, in local space with its feet at (0, 0): its Mask and its own Pixels (W x H, top-left at X, Y), its scale K, the top of its Head, its Chest, and, at scale 2, its Eyes (in the mask).

func StockActor(k int) *Actor

StockActor returns the stock actor at scale k: 1 is 12 x 19 px, 2 is 24 x 38 px (any other k is 1). Each call returns a copy of its mask and pixels, so the caller may change them.

type Align uint8

Align is where text sits on its x.

const (
	// AlignLeft starts the text at x.
	AlignLeft Align = iota
	// AlignCenter centers the text on x.
	AlignCenter
	// AlignRight ends the text at x.
	AlignRight
)
type Bit struct {
	Kind            BitKind
	X, Y, VX, VY    float64
	A, VA, S        float64
	C               uint32
	Ramp            []uint32
	G, Drag, Bounce float64
	Life, Max       float64
	Rest            bool
	Pts             []float64
	PVY             float64
	Dusted          bool
	Data            any
}

Bit is one piece of debris. S is its size, A and VA its angle and spin, C its color, Ramp a chunk's shading (dark to bright), G its gravity scale, Drag, Bounce and Life (seconds). Pts, PVY, Dusted and Data are left to the effect, for its own bookkeeping.

type BitKind int

BitKind is a kind of debris.

const (
	Shard BitKind = iota
	Chunk
	Drip
)

The debris kinds.

type Bits struct {
	List   []Bit
	Ground func(x float64) float64
}

Bits is rigid debris that tumbles, bounces and settles.

func NewBits(ground func(x float64) float64) *Bits

NewBits returns no debris yet over ground (none when nil).

func (bs *Bits) Add(b Bit)

Add adds a piece of debris. Fields left zero take pixelfx's defaults: S 1, C White, G 1 and Life 1 (Kind is Shard, and the rest start at 0).

func (bs *Bits) Count() int

Count returns how many pieces there are.

func (bs *Bits) Draw(p *Painter)

Draw draws every piece.

func (bs *Bits) Update(dt float64)

Update moves every piece on by dt seconds.

type Blaze struct {
	X, Y, Life, Max, Acc, Power float64
}

Blaze is a little fire burning where something landed.

type Blazes struct {
	PS   *Particles
	List []Blaze
}

Blazes are little fires burning where something landed: Add feeds Fire puffs (and the odd ember) into a particle system, fading over its life; DrawBack adds a hot pixel and a glow at its foot.

func NewBlazes(ps *Particles) *Blazes

NewBlazes returns blazes feeding ps.

func (bs *Blazes) Add(x, y, life, power float64)

Add starts a blaze at (x, y) burning life seconds at power.

func (bs *Blazes) Count() int

Count returns how many blazes are burning.

func (bs *Blazes) DrawBack(p *Painter)

DrawBack draws each blaze's hot foot and its glow.

func (bs *Blazes) Update(dt float64)

Update burns every blaze on by dt seconds.

type Bounds struct {
	X0, Y0, X1, Y1 float64
}

Bounds is a box in local space: X0, Y0 its top-left and X1, Y1 its bottom-right.

func ActBounds(e *Effect, rig *Rig) Bounds

ActBounds returns the box an act needs in local space, so nothing gets cut off, sampled over its poses with rig (a new one when nil); pass the same rig to Perform.

type Cue struct {
	FX       *Effect
	T, Until float64
	X, Y     float64
	XFn, YFn func(t float64) float64
	Flip     bool
	Options  map[string]Value
}

Cue is one effect in a chain: FX starts at T (seconds into the move) and is cut off at Until (never when 0), at (X, Y) in local space, or at XFn(t), YFn(t) of the move's time when they are set, mirrored when Flip, with Options laid over the effect's own (its seed is the move's seed plus the cue's index).

type DustKick struct {
	T, X float64
	N    int
	Dir  float64
	C    uint32
}

DustKick is dust kicked up at T: N specks (6 when 0) at X along the floor, flying Dir (-1 left, 1 right, 0 either way at random), in color C (pixelfx's dust colors when 0).

type Effect struct {
	ID         string
	Meta       Meta
	New        func(o *Options) Instance
	Act        *Act
	ActorAlpha func(t float64, o *Options) float64
}

Effect is one pixelfx effect: its ID ("<category>/<name>", set by Register), its Meta, New, which starts playing it with resolved options, and, for one a character acts out, its Act and ActorAlpha, how visible it wants the stand-in character at time t (fully when nil).

func Lookup(id string) (*Effect, bool)

Lookup returns the effect registered as id.

type Flag int

Flag is a set of particle flags.

const (
	// Smokes makes a Fire puff leave smoke when it dies.
	Smokes Flag = 1
	// Big makes smoke bigger and slower.
	Big Flag = 2
	// Back draws the particle behind a character.
	Back Flag = 4
)

The particle flags.

type Font struct {
	H, Space, Gap int
	Glyphs        map[rune]Glyph
}

Font is a pixel font: H rows tall, Space wide for a character it lacks, Gap between characters.

type ForkOpts struct {
	Count            int
	Len, Jag, Spread float64
}

ForkOpts are how Forks branches off a path: Count branches, each up to Len px long, with their own Jag and Spread (pixelfx's defaults are 3, 20, 0.3 and 0.9).

type Frame struct {
	W, H   int
	OX, OY int
	Color  []uint32
	Light  []uint32
	// contains filtered or unexported fields
}

Frame is W x H pixels whose top-left sits at (OX, OY) in world space. Color holds opaque (or, from Painter.Blend, translucent) pixels and Light additive glow, both as colors; Composite puts them together. A frame is the same shape as Sprite Fusion's VFX frames.

func NewFrame(w, h, ox, oy int) *Frame

NewFrame returns a clear w x h frame with its top-left at (ox, oy).

func (f *Frame) Clear() *Frame

Clear empties the frame's color and light.

func (f *Frame) Painter() *Painter

Painter returns the frame's painter, reset: one per frame, reused, as pixelfx's painterFor gives it.

type Frames struct {
	Effect *Effect
	W, H   int
	FPS    int
	// Pivot is where the effect's origin (or, acted out, the character's feet) sits in each frame.
	Pivot [2]float64
	// Acted is true when the frames show the effect acted out.
	Acted  bool
	Pixels [][]byte
}

Frames are an effect rendered to RGBA pixels (straight alpha, W x H x 4 bytes each), ready for a sprite sheet.

func Render(e *Effect, o Options, fps int) *Frames

Render renders every frame of e as EachFrame does.

func RenderAct(e *Effect, o Options, fps int) *Frames

RenderAct renders e acted out as EachActFrame does, without the shake.

func (fr *Frames) Sheet(name, image string) (*image.NRGBA, []byte, error)

Sheet lays the frames out in a grid, as pixelfx's sheets do (about square, row by row), and returns the image and its Aseprite JSON, which sprite.LoadAtlas reads: frames named "<name> <i>" with their duration (1000 / fps ms, rounded) and their pivot at the effect's origin, one tag called name that plays them once for a one-shot or loops a loop, and pixelfx's meta (id, fps, loop, frame size, pivot, columns, and an act's timing). image is the file name the JSON gives the image.

func (fr *Frames) SheetPNG(name, image string) (pngData, jsonData []byte, err error)

SheetPNG returns the sheet's image encoded as PNG with its JSON, as Sheet lays them out.

type Funcs struct {
	UpdateFunc   func(dt float64)
	DrawBackFunc func(p *Painter, t float64)
	DrawFunc     func(p *Painter, t float64)
}

Funcs is an Instance made of functions; a nil one does nothing.

func (f *Funcs) Draw(p *Painter, t float64)

Draw implements Instance.

func (f *Funcs) DrawBack(p *Painter, t float64)

DrawBack implements Instance.

func (f *Funcs) Update(dt float64)

Update implements Instance.

type Glyph struct {
	W    int
	Rows [][]bool
}

Glyph is one character of a pixel font: W columns, and the rows of its inked pixels.

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

Hand draws a held weapon along its handle from the fist: Put(i, k, c, lift) plots color c i px along the handle, k px across it and lift px off its plane, and At(i, k) returns that point.

func (T *Hand) At(i, k float64) [3]float64

At returns the point i px along the handle and k px across it.

func (T *Hand) Put(i, k float64, c uint32, lift float64)

Put plots color c i px along the handle from the fist, k px across it and lift px out of its plane.

type Hit struct {
	T        float64
	Stop     float64
	Shake    float64
	Amp      Opt
	NoTarget bool
	At       Opt
	Push     Opt
	Straw    Opt
	Flash    Opt
	Y        Opt
	Skin     string
	Shiver   float64
}

Hit is a moment of contact: at T, freeze for Stop seconds, shake Shake seconds by Amp px (2 when unsaid), and unless NoTarget, hit the targets (only target At when it is said): Push sways it (1.2 when unsaid), Straw pieces of straw fly (8), Flash flashes it white that long (0.05), Y is where on it they fly from (-26), Skin leaves a look on it (a name in Skins, SkinNone to clear it, "" to keep it) and Shiver shivers it that long.

func ShiftHits(hits []Hit, dt float64) []Hit

ShiftHits reuses an act's hits in a longer move, later by dt.

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

Image holds a frame's picture as an NSGo image source: Set composites a frame over transparency into its pixels, premultiplied as core.ImageSource.Pixels wants them, and steps its version, so a core.Image, a canvas or a shader shows each new frame in place. The zero Image is ready to use.

func (im *Image) Set(f *Frame) core.ImageSource

Set composites f into the image and returns its source.

func (im *Image) Source() core.ImageSource

Source returns the image's source as last Set, the zero source before then.

type Instance interface {
	Update(dt float64)
	DrawBack(p *Painter, t float64)
	Draw(p *Painter, t float64)
}

Instance is an effect being played: Update moves it on by dt seconds, DrawBack draws what goes behind a character and Draw what goes in front, both at the effect's own time t. Effects that are pure functions of t leave Update empty.

type Key struct {
	T    float64
	Pose Pose
	How  string
}

Key is one key of an act's poses: at T seconds (effect time; negative is the wind-up before the effect starts) the character is in Pose, which How it arrives at: "" smoothly, "out" fast then settling, "in" slowly then fast, "line" evenly, "snap" holding the last pose and jumping on the key.

func ShiftKeys(keys []Key, dt, dx float64, over Pose) []Key

ShiftKeys reuses an act's keys in a longer move: later by dt, moved along by dx, with over laid over each pose.

type Kind int

Kind is a simulated particle's kind.

const (
	Spark Kind = iota
	Mote
	Streak
	Flake
	Vapour
	Dust
	StarKind
	Ember
	Smoke
	Fire
	Brand
	Grit
)

The particle kinds.

type Layer uint8

Layer is which of an effect's layers is being drawn.

const (
	// LayerBoth draws both layers, back then front.
	LayerBoth Layer = iota
	// LayerBack is what goes behind a character.
	LayerBack
	// LayerFront is what goes in front of a character.
	LayerFront
)
type LightSpot struct {
	X, Y, R   float64
	Color     uint32
	K         float64
	Life, Max float64
}

LightSpot is one light that flares and dies.

type Lights struct {
	List []LightSpot
}

Lights are lights that flare and die.

func (ls *Lights) Add(x, y, r float64, color uint32, k, life float64)

Add adds a light at (x, y) of radius r and color, strength k, lasting life seconds.

func (ls *Lights) Draw(p *Painter)

Draw draws every light.

func (ls *Lights) Update(dt float64)

Update ages every light by dt seconds.

type Mask struct {
	W, H int
	Data []uint8
}

Mask is a w x h stencil: a pixel is in it where Data is not 0.

type Meta struct {
	Name     string
	Desc     string
	Tags     []string
	Size     [2]int
	Origin   [2]int
	Duration float64
	Loop     bool
	FPS      int
	BG       string
	Actor    int
	Options  []Option
}

Meta is what an effect says about itself: its Name and Desc, Tags, its frame Size and the Origin in it that its local (0, 0) sits at, its Duration in seconds, whether it Loops, the FPS its sheets play at, the backdrop it previews on (BG: "dark", "ground", "sky", "light" or "black"), the stock Actor it is drawn on (0 none, 1 the 12 x 19 one, 2 the 24 x 38 one), and its Options with their defaults, in order.

func (m *Meta) Default(name string) (Value, bool)

Default returns the default of the option called name and whether the effect has it.

type Opt struct {
	V   float64
	Set bool
}

Opt is a number that may be left unsaid, so it takes a default: the zero Opt is unsaid.

func Val(x float64) Opt

Val returns the Opt that says x.

func (o Opt) Or(def float64) float64

Or returns o's number, or def when it is unsaid.

type Option struct {
	Name    string
	Default Value
}

Option is one of an effect's options and its default.

type Options struct {
	X, Y   float64
	Flip   bool
	Angle  float64
	Light  float64
	Actor  *Actor
	Values map[string]Value
}

Options are how an effect is played: X and Y place its origin in frame space, Flip mirrors it, Angle turns it (radians), Light scales its glow (0 is read as 1; below 0 draws no light), Actor is the character it wraps (the stock one its meta names when nil), and Values are its own options by name, such as "seed" and "palette", over the defaults its meta gives.

func (o *Options) Bool(name string) bool

Bool returns the option called name as a bool: true when it is on (or a number that is not 0).

func (o *Options) Color(name string) uint32

Color returns the color option called name, 0 when it is not a color.

func (o *Options) Num(name string) float64

Num returns the number option called name, 0 when it is not a number.

func (o *Options) Numbers(name string) []float64

Numbers returns the list-of-numbers option called name. Don't change what it returns.

func (o *Options) Palette() []uint32

Palette returns the palette option.

func (o *Options) Ramp(name string) []uint32

Ramp returns the ramp option called name, nil when it is not a ramp. Don't change the colors it returns.

func (o *Options) Seed() float64

Seed returns the seed option.

func (o Options) Set(name string, v Value) Options

Set returns o with the option called name set to v. Set checks nothing: when the effect is played, a value of a kind its meta does not take for that option, or an empty ramp, is ignored and the default kept, and a name its meta does not give is passed on as it is. Check a value against Meta.Default first to report a mistake.

func (o *Options) Text(name string) string

Text returns the text option called name.

func (o *Options) Value(name string) (Value, bool)

Value returns the value of the option called name and whether it is set.

type Out struct {
	C uint32
	A float64
	L uint32
	K float64
}

Out is what a Shade function sets for its pixel: C its color, A its alpha (0..1, faded by ordered dither), L the color of light it adds (C when 0) and K how much.

type Painter struct {
	// Frame is the frame the painter draws into.
	Frame *Frame
	// W, H, OX and OY are the frame's size and top-left, and C and L its color and light buffers.
	W, H, OX, OY int
	C, L         []uint32
	// TX and TY are where the effect's origin sits in frame space, FX is -1 when it is mirrored (else 1), and CS and SN are the cosine and sine of its angle.
	TX, TY, FX, CS, SN float64
	// Fade scales every alpha and light (1 while an effect plays, falling to 0 as a stopped loop fades out), and LightK scales light (an effect's light option).
	Fade, LightK float64
	// Layer is the layer being drawn.
	Layer Layer
	// contains filtered or unexported fields
}

Painter draws into a frame's two buffers: Color (opaque pixels, faded with ordered dither, never blended) and Light (additive glow, composited on top). Effects draw in local coordinates around their origin; the painter places, mirrors and rotates them, so an effect never needs to know where it is.

Every shape comes in two forms: one with a color c and alpha a, and one whose name ends in Fn taking a function of the shape's own coordinates that returns both, as pixelfx lets a color or an alpha be a function.

func (p *Painter) Add(sx, sy int, c uint32, k float64)

Add adds k of color c's light to the frame pixel (sx, sy).

func (p *Painter) Arc(cx, cy, r, w, a0, a1 float64, c uint32, a float64)

Arc draws the band of a ring from angle a0 to a1 (radians, a1 > a0), radius r - w to r: the slash and smear shape.

func (p *Painter) ArcFn(cx, cy, r, w, a0, a1 float64, fn func(u, v float64) (uint32, float64))

ArcFn draws the band Arc draws, its color and alpha fn(u, v): u 0 at a0 to 1 at a1, v 0 at the inner edge to 1 at the outer.

func (p *Painter) ArcTaperFn(cx, cy, r float64, w func(u float64) float64, a0, a1 float64, fn func(u, v float64) (uint32, float64))

ArcTaperFn draws the band Arc draws with its width a function of u, for a crescent that tapers at both ends, colored by fn as ArcFn colors it.

func (p *Painter) Beam(x0, y0, x1, y1, width float64, c uint32, a float64)

Beam draws a thick segment with round ends.

func (p *Painter) BeamFn(x0, y0, x1, y1, width float64, fn func(u, v float64) (uint32, float64))

BeamFn draws a thick segment with round ends whose color and alpha are fn(u, v): u along it, v across it (0 at the center, 1 at the edge).

func (p *Painter) Blend(x, y float64, c uint32, a float64)

Blend draws a translucent pixel at the local point (x, y).

func (p *Painter) BlendPx(sx, sy int, c uint32, a float64)

BlendPx blends color c over what's at the frame pixel (sx, sy) at alpha a (0..1), keeping the result's own alpha: soft smoke, vapour and mist. Use Dot for hard pixel fades and Blend for translucent volumes.

func (p *Painter) CellX(x, y float64) int

CellX returns the frame x of the local pixel cell holding (x, y): mirrors and rotations land on whole cells.

func (p *Painter) CellY(x, y float64) int

CellY returns the frame y of the local pixel cell holding (x, y).

func (p *Painter) Circle(cx, cy, r float64, c uint32, a float64)

Circle draws a filled disc.

func (p *Painter) CircleFn(cx, cy, r float64, fn func(d, ang float64) (uint32, float64))

CircleFn draws a filled disc whose color and alpha are fn(d, angle): d 0 at the center to 1 at the rim.

func (p *Painter) Clipped(x0, y0, x1, y1 float64) *Painter

Clipped returns a copy of p drawing into the same frame that drops any pixel whose frame center falls outside [x0, x1) x [y0, y1) in local space.

func (p *Painter) Disc(cx, cy, r float64, c uint32, a float64)

Disc draws a translucent disc: puffs of smoke, vapour, dust.

func (p *Painter) DiscFn(cx, cy, r float64, fn func(d, ang float64) (uint32, float64))

DiscFn draws a translucent disc whose color and alpha are fn(d, angle): d 0 at the center to 1 at the rim.

func (p *Painter) Dot(x, y float64, c uint32, a float64)

Dot draws one pixel at alpha a (0..1), faded by ordered dither; nothing at all when a is 0 or less.

func (p *Painter) Each(x0, y0, x1, y1 float64, fn func(lx, ly float64, sx, sy int))

Each visits every frame pixel whose center falls in the local box [x0, x1] x [y0, y1], with that center in local space: fn(lx, ly, sx, sy). It is the basis of every filled shape, so shapes mirror and rotate exactly.

func (p *Painter) Ellipse(cx, cy, rx, ry float64, c uint32, a float64)

Ellipse draws a filled ellipse with radii rx and ry; nothing when either is 0 or less.

func (p *Painter) EllipseFn(cx, cy, rx, ry float64, fn func(d, ang float64) (uint32, float64))

EllipseFn draws a filled ellipse whose color and alpha are fn(d, angle): d 0 at the center to 1 at the rim.

func (p *Painter) FromX(sx, sy float64) float64

FromX returns the local x of the frame point (sx, sy).

func (p *Painter) FromY(sx, sy float64) float64

FromY returns the local y of the frame point (sx, sy).

func (p *Painter) Get(x, y float64) uint32

Get reads back the color under the local point (x, y), 0 if empty.

func (p *Painter) Glow(x, y, r float64, c uint32, k float64)

Glow adds a radial glow to the light buffer: k at the center, falling to 0 at radius r.

func (p *Painter) GlowLine(x0, y0, x1, y1, r float64, c uint32, k float64)

GlowLine adds a glow around a segment (a soft beam of light), k on the segment falling to 0 at distance r.

func (p *Painter) GlowRing(x, y, R, r float64, c uint32, k float64)

GlowRing adds a glow hugging a circle of radius R (a shockwave's light), falling off over width r.

func (p *Painter) Light(x, y float64, c uint32, k float64)

Light adds k of color c's light to one pixel.

func (p *Painter) Line(x0, y0, x1, y1 float64, c uint32, a float64)

Line draws a 1 px line.

func (p *Painter) LineFn(x0, y0, x1, y1 float64, fn func(u float64) (uint32, float64))

LineFn draws a 1 px line whose color and alpha are fn(u): u 0 at the start to 1 at the end.

func (p *Painter) Mask(m *Mask, x, y float64, c uint32, a float64)

Mask fills a mask with its top-left at (x, y).

func (p *Painter) MaskFn(m *Mask, x, y float64, fn func(mx, my int) (uint32, float64))

MaskFn fills a mask with its top-left at (x, y), each pixel's color and alpha fn(mx, my).

func (p *Painter) Measure(str string, o TextOpts) (w, h float64)

Measure returns the size of text in pixels: its width and height.

func (p *Painter) Outline(m *Mask, x, y float64, c uint32, a float64)

Outline draws the 1 px outline just outside a mask.

func (p *Painter) OutlineFn(m *Mask, x, y float64, fn func(mx, my int) (uint32, float64))

OutlineFn draws the 1 px outline just outside a mask, each pixel's color and alpha fn(mx, my) (which may be -1 or the mask's size, just outside it).

func (p *Painter) Place(x, y float64, flip bool, angle float64) *Painter

Place puts the effect's origin at (x, y) in frame space, mirrored if flip, rotated by angle (radians).

func (p *Painter) Poly(pts [][2]float64, c uint32, a float64)

Poly draws a filled polygon from points (even-odd rule).

func (p *Painter) PolyFn(pts [][2]float64, fn func(x, y float64) (uint32, float64))

PolyFn draws a filled polygon whose color and alpha are fn(x, y) of the local point.

func (p *Painter) Polyline(pts [][2]float64, c uint32, a float64)

Polyline draws lines through a list of points.

func (p *Painter) PolylineFn(pts [][2]float64, fn func(u float64) (uint32, float64))

PolylineFn draws lines through a list of points, each colored by fn as LineFn colors it.

func (p *Painter) Put(sx, sy int, c uint32, a float64)

Put writes color c at the frame pixel (sx, sy) at alpha a (0..1, faded by ordered dither). Color 0 means "nothing": it never erases what's there.

func (p *Painter) Px(x, y float64, c uint32)

Px draws one opaque pixel.

func (p *Painter) Rect(x, y, w, h float64, c uint32, a float64)

Rect draws a filled rectangle.

func (p *Painter) Reset() *Painter

Reset re-reads the frame and clears placement, fade, light strength and clip.

func (p *Painter) Ring(cx, cy, r, w float64, c uint32, a float64)

Ring draws a ring from radius r - w to r.

func (p *Painter) RingFn(cx, cy, r, w float64, fn func(v, ang float64) (uint32, float64))

RingFn draws a ring from radius r - w to r whose color and alpha are fn(v, angle): v 0 at the inner edge to 1 at the outer.

func (p *Painter) Shade(x0, y0, x1, y1 float64, fn func(x, y float64, o *Out) uint32)

Shade runs a pixel shader over a local box: fn(x, y, out) returns a color, or sets out.C, out.A, out.L and out.K (Out says what each is). Returning 0 with out.C left 0 leaves the pixel alone.

func (p *Painter) Sprite(rows []string, pal map[rune]uint32, x, y, a float64, o SpriteOpts)

Sprite draws a little sprite from strings, rows like "..##.." and ".#oo#.", whose top-left is at (x, y) and whose alpha is a: pal maps characters to colors, and "." and " " are empty, as is a character pal leaves out.

func (p *Painter) Text(str string, x, y float64, c uint32, a float64, o TextOpts)

Text draws pixel text in color c at alpha a; (x, y) is the top of the text, at its left, center or right by o.Align.

func (p *Painter) TextFn(str string, x, y float64, fn func(gx, gy int) uint32, a float64, o TextOpts)

TextFn draws pixel text as Text does, each font pixel colored fn(gx, gy) by its place in the unscaled text.

func (p *Painter) ToX(x, y float64) float64

ToX returns the frame x of the local point (x, y).

func (p *Painter) ToY(x, y float64) float64

ToY returns the frame y of the local point (x, y).

func (p *Painter) Tri(x0, y0, x1, y1, x2, y2 float64, c uint32, a float64)

Tri draws a filled triangle.

type Particle struct {
	K            Kind
	X, Y, VX, VY float64
	Life, Max    float64
	Col          uint32
	Size, Seed   float64
	Delay        float64
	Flag         Flag
}

Particle is one simulated particle.

type Particles struct {
	R      *Rng
	List   []Particle
	T      float64
	Ground func(x float64) float64
	Sparks []uint32
	Haze   uint32
	OnLand func(x, y float64)
}

Particles is a particle system: Spawn adds a particle, Update moves them all on, and Draw draws them.

func NewParticles(o SimOpts) *Particles

NewParticles returns an empty particle system.

func (ps *Particles) Count() int

Count returns how many particles there are.

func (ps *Particles) Draw(p *Painter, layer Layer)

Draw draws the particles: LayerBack the soft kinds (vapour, dust, smoke) and those flagged Back, LayerFront the rest, LayerBoth all of them.

func (ps *Particles) Spawn(k Kind, x, y, vx, vy, life float64, col uint32, size, delay float64, flag Flag)

Spawn adds a particle of kind k at (x, y) moving (vx, vy) that lives life seconds, colored col (0 lets Fire and Smoke use their own ramps; pixelfx's default is White), size big (pixelfx's default is 1), appearing after delay seconds, with flag's bits.

func (ps *Particles) Update(dt float64)

Update moves every particle on by dt seconds.

type Performance struct {
	// FX is the effect being performed.
	FX *Player
	// Targets are the straw targets.
	Targets []*Target
	// OnHit, when set, is called on every hit as it lands.
	OnHit func(h Hit)
	// contains filtered or unexported fields
}

Performance is an effect performed: the character, the effect, the target and the freeze, drawn together. Its time runs from the first pose (before the effect's own t = 0) to the last; Update holds everything still during a freeze. Without an act, the effect just plays with the character standing by.

func Perform(e *Effect, o Options, rig *Rig) *Performance

Perform starts e performed with o (X and Y place the feet), its character drawn by rig (a new one when nil). Give it the Rig that ActBounds used to size the frame, as pixelfx shares one between them.

func (pf *Performance) Done() bool

Done reports whether the performance is over: a one-shot when its last pose is, a loop once stopped and faded.

func (pf *Performance) Draw(frame *Frame, body, targets bool)

Draw paints the performance into frame: the effect, the character and the targets together. body false leaves the character out, targets false the targets.

func (pf *Performance) Frozen() bool

Frozen reports whether a hit has everything frozen right now.

func (pf *Performance) Pose() Pose

Pose returns the pose the character is in right now.

func (pf *Performance) Shake() (x, y float64)

Shake returns how far the whole picture is thrown right now, in px.

func (pf *Performance) Stop()

Stop lets a loop end: it fades out and Done goes true.

func (pf *Performance) T() float64

T returns the performance's time: effect time, negative during the wind-up.

func (pf *Performance) Update(dt float64)

Update moves the performance on by dt seconds; a negative, NaN or infinite dt does nothing.

type Player struct {
	// Effect is what is playing.
	Effect *Effect
	// Options are its resolved options; changing X, Y or Flip moves it.
	Options *Options
	// contains filtered or unexported fields
}

Player is a live instance of an effect: pixelfx's createFx.

func NewPlayer(e *Effect, o Options) *Player

NewPlayer starts playing e with o, over the defaults its meta gives: see Options.Set for which values it takes.

func (f *Player) Done() bool

Done reports whether it has ended.

func (f *Player) Draw(frame *Frame, layer Layer)

Draw draws it into frame: LayerBack what goes behind a character, LayerFront what goes in front, LayerBoth both.

func (f *Player) Stop()

Stop lets it end: a loop fades out, a one-shot is cut short.

func (f *Player) T() float64

T returns how long it has played, in seconds.

func (f *Player) Update(dt float64)

Update moves it on by dt seconds. Simulations step at 120 Hz or finer whatever the caller's frame rate, so they look the same everywhere. A negative, NaN or infinite dt does nothing. Every 1/120 s of dt costs a step, so a caller resuming after a long pause should clamp dt first.

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

Pose is what a character is doing: the keys it sets, and what the near and far hands hold. The zero Pose sets nothing, which is standing easy.

func LerpPose(a, b Pose, u float64) Pose

LerpPose returns the pose u of the way from a to b: numbers move, everything else changes at the later key.

func PoseAt(track []Key, t float64) Pose

PoseAt returns the pose at time t on a track of keys. Limbs move in whole 12 fps steps counted from each key, so they read as held drawings; the feet's place over the floor (X, Y) stays smooth.

func (p Pose) Get(k PoseKey) (float64, bool)

Get returns k's value in p and whether p says it.

func (p Pose) Has(k PoseKey) bool

Has reports whether p says k.

func (p Pose) Hold(weapon string) Pose

Hold returns p with the near hand holding weapon (one of Weapons' names; "" holds nothing).

func (p Pose) HoldOff(weapon string) Pose

HoldOff returns p with the far hand holding weapon ("" holds nothing).

func (p Pose) MarshalJSON() ([]byte, error)

MarshalJSON writes the pose as pixelfx writes one: an object of the keys it says, by their pixelfx names (switches as true or false), and weapon and offWeapon when it holds something.

func (p Pose) Merge(q Pose) Pose

Merge returns p with everything q says laid over it, as pixelfx's { ...p, ...q }.

func (p Pose) OffWeapon() string

OffWeapon returns what the far hand holds, "" for nothing.

func (p Pose) Or(k PoseKey, def float64) float64

Or returns k's value in p, or def when p doesn't say it.

func (p Pose) Weapon() string

Weapon returns what the near hand holds, "" for nothing.

func (p Pose) With(vs ...PoseValue) Pose

With returns p with each of vs set.

func (p Pose) Without(ks ...PoseKey) Pose

Without returns p with each of ks left unsaid.

type PoseKey uint8

PoseKey is one thing a pose can say. A pose only says what differs from standing easy (Stand), in screen terms, px from the feet, y negative up. Give the hands and feet; the skeleton works out the rest.

How the body works. He faces right, three-quarters towards us, so his near shoulder is on the left of the chest on screen and his far shoulder on the right: for arms raised or open to us, the near hand goes left (FX < 0) and the far hand right (BX > 0). A hand driving forward closes the chest and brings its shoulder round; a hand drawn back opens him up. Bones have fixed lengths: an arm reaches about 15 px from its shoulder (shoulders are near y = -29), a leg 17 px. Arms don't stretch, so step the body in rather than ask too much.

How to hold things. Keep a little bend in the elbow. The blade lags the hand on a swing, so the wrist breaks and it whips. Long weapons rest in one hand with the butt on the floor and take the second hand to swing. Everything is in depth, so a weapon can swing round the front of him: turn the body (Yaw) and the weapon goes with it.

const (
	// Lean bends the spine forward (+) or back (-).
	Lean PoseKey = iota
	// Crouch lowers the hips.
	Crouch
	// Yaw turns the whole body about its feet (0 faces right, π faces left, in between towards us; a spin is really a spin).
	Yaw
	// FX and FY place the near (right) hand.
	FX
	FY
	// BX and BY place the far (left) hand.
	BX
	BY
	// FFX and FFY place the near foot.
	FFX
	FFY
	// FBX and FBY place the far foot.
	FBX
	FBY
	// X and Y are where the feet are, from the effect's origin.
	X
	Y
	// HX rolls the head and HY nods it.
	HX
	HY
	// WL foreshortens the weapon towards the viewer: its length on screen, 1 is full; WZ -1 turns it away instead.
	WL
	WZ
	// SA is the angle on screen of what the near hand holds (radians, 0 points forward), SB that of what the far hand holds.
	SA
	SB
	// FZ and BZ are the hands' depth, FZZ and BZZ the feet's.
	FZ
	BZ
	FZZ
	BZZ
	// Turn is how far the chest faces us, in radians (it follows the hands if you leave it out); Twist is extra chest turn.
	Turn
	Twist
	// Face -1 turns him round to face left.
	Face
	// Ghost leaves after-images.
	Ghost
	// Two puts both hands on the weapon.
	Two
	// ArmsFront brings the far hand round in front of the chest.
	ArmsFront
	// Pull draws a bow to the far hand, and Nocked puts an arrow on the string.
	Pull
	Nocked
	// ToeF and ToeB put the near and far foot up on the toes.
	ToeF
	ToeB
)

The pose keys. Numbers move smoothly between keys of an act; the switches (Two, ArmsFront, Pull, Nocked, ToeF, ToeB) are on when not 0 and change at the later key.

func (k PoseKey) Is(v float64) PoseValue

Is returns k set to v.

func (k PoseKey) On() PoseValue

On returns the switch k turned on.

func (k PoseKey) String() string

String returns the key's name in pixelfx, such as "fx".

type PoseValue struct {
	Key   PoseKey
	Value float64
}

PoseValue is a key with its value, for Pose.With.

type Posed struct {
	N              int
	Xs, Ys         []int16
	Color          []uint32
	Src            []int16
	Ink            []uint8
	X0, Y0, X1, Y1 int
	Z              float64
}

Posed is a pose drawn down to pixels, in local space with the feet at (0, 0): pixel i is at (Xs[i], Ys[i]) in Color, came from pixel Src[i] of the standing 24 x 38 character (-1 for none), and is ink (outline) when Ink[i] is 1. X0, Y0, X1 and Y1 bound it, and Z is the body's mean depth.

type PosedPart struct {
	Name   string
	Part   int
	N      int
	Xs, Ys []int16
	Color  []uint32
	CX, CY float64
	Z      float64
}

PosedPart is one part of a figure taken apart: its name and number, its pixels as Posed holds them, and where its middle is (CX, CY) and its mean depth Z.

func PosedParts(pose Pose) []PosedPart

PosedParts returns the figure taken apart: each part drawn alone, with its own outline, and where its middle is. For exploded views.

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

Rig draws poses down to pixels and keeps the ones it drew, keyed as pixelfx keys them: every key rounded to a pixel (angles to a twentieth of a radian), so poses that round alike share the first one's pixels. An Act and ActBounds take one, so an effect acted out draws what pixelfx draws for it in a fresh process. The zero Rig is ready to use; a Rig is not safe for concurrent use.

func NewRig() *Rig

NewRig returns a Rig with nothing drawn yet.

func (g *Rig) Posed(pose Pose) *Posed

Posed returns the pixels of a pose, in local space with the feet at (0, 0).

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

Rng is a seeded random generator (mulberry32), the same sequence as pixelfx's for the same seed.

func NewRng(seed float64) *Rng

NewRng returns a generator seeded with seed, converted as JavaScript's seed >>> 0; a seed of 0 is read as 1.

func RngOf(ns ...float64) *Rng

RngOf returns a generator for one particle: RngOf(seed, i) gives the same numbers every frame.

func (r *Rng) Chance(p float64) bool

Chance reports true with probability p.

func (r *Rng) Gauss() float64

Gauss returns a roughly normal number, mean 0, standard deviation 1.

func (r *Rng) Int(a, b float64) float64

Int returns a whole number from a to b, both included.

func (r *Rng) Next() float64

Next returns the next number in [0, 1).

func (r *Rng) Range(a, b float64) float64

Range returns a number in [a, b).

func (r *Rng) Seed(seed float64)

Seed restarts r from seed, as NewRng does.

func (r *Rng) Sign() float64

Sign returns -1 or 1 with even odds.

type SimOpts struct {
	Rng    *Rng
	Seed   float64
	Ground func(x float64) float64
	Sparks []uint32
	Haze   uint32
	OnLand func(x, y float64)
}

SimOpts configure a Particles system: Rng is the generator it draws from (one seeded with Seed when nil), Ground the floor y under local x (sparks bounce on it; none when nil), Sparks the head-to-tail colors of a Spark (pixelfx's hot ramp when nil), Haze the color vapour glows with (none when 0), and OnLand what is called when a Brand hits the floor.

type Skeleton struct {
	Joints  map[string][3]float64
	Bones   [][2]string
	Handles []string
}

Skeleton is the skeleton of a pose, in the same local space as Rig.Posed: x right, y down, feet at (0, 0), z toward the viewer, the whole figure turned by its yaw. Joints are by name, Bones join two joints, and Handles are what a pose moves (hands and feet); everything else is solved from them.

func SkeletonOf(pose Pose) Skeleton

SkeletonOf returns the skeleton of a pose.

type Skin struct {
	Color  uint32
	Amount float64
}

Skin is what a hit can leave on the target: a color, and how much of it.

type SpriteOpts struct {
	Scale       float64
	Flip, FlipY bool
	Tint        uint32
}

SpriteOpts are how Sprite draws: Scale (0 is 1), Flip (mirror left-right), FlipY (upside down) and Tint (draw every pixel in one color; 0 draws each in its own).

type Target struct {
	X float64
	// contains filtered or unexported fields
}

Target is a straw target on a spring: it sways, flashes, takes a skin, shivers and sheds straw. X is the floor under it, in local space.

func NewTarget(x, seed float64) *Target

NewTarget returns a target standing at x, its straw seeded with seed.

func (g *Target) Draw(C []uint32, W, H int, x, y float64, flip bool)

Draw draws the target into a w x h color buffer, its floor at (x, y), mirrored when flip.

func (g *Target) DrawStraw(C []uint32, W, H int, x, y float64, flip bool)

DrawStraw draws the straw the target has shed.

func (g *Target) Hit(h Hit)

Hit hits the target as h says.

func (g *Target) Step(dt float64)

Step moves the target on by dt seconds.

type TextOpts struct {
	Font    string
	Scale   float64
	Align   Align
	Outline uint32
	Shadow  uint32
}

TextOpts are how Text draws: Font ("mini", 3x5, when empty, or "big", 5x7), Scale (0 is 1), Align, and an Outline and a Shadow color (0 for none).

type TimedHit struct {
	T      float64 `json:"t"`
	Freeze float64 `json:"freeze"`
	Shake  float64 `json:"shake"`
	Amp    float64 `json:"amp"`
	Push   float64 `json:"push"`
	Skin   string  `json:"skin,omitempty"`
	At     *int    `json:"at,omitempty"`
}

TimedHit is one hit of a Timing: when, how long to freeze and shake and by how much, how hard it pushes the target, the skin it leaves and which target it hits (all when unsaid).

type TimedPose struct {
	T    float64 `json:"t"`
	How  string  `json:"how"`
	Pose Pose    `json:"pose"`
}

TimedPose is one key of a Timing: when, how the pose arrives, and the pose.

type Timing struct {
	Windup   float64     `json:"windup"`
	Recovery float64     `json:"recovery"`
	OnBody   bool        `json:"onBody"`
	Targets  []float64   `json:"targets"`
	Hits     []TimedHit  `json:"hits"`
	Poses    []TimedPose `json:"poses"`
}

Timing is an act as plain data, for a game with its own character: how long the wind-up and recovery are, when to freeze and shake, what a target should do, and the poses themselves. Times are in the effect's own seconds: start the effect at 0.

func ActTiming(e *Effect) *Timing

ActTiming returns e's act as plain data, nil when it has none.

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

Value is an option's value: a number, a bool, a color, a ramp of colors, text or a list of numbers.

func Bool(b bool) Value

Bool returns a bool value.

func Color(hex string) Value

Color returns a color value from "#rgb", "#rrggbb" or "#rrggbbaa" (alpha ignored), panicking on anything else as Hex does.

func ColorOf(c uint32) Value

ColorOf returns a color value.

func Num(x float64) Value

Num returns a number value.

func Nums(xs ...float64) Value

Nums returns a list-of-numbers value.

func Palette(hex ...string) Value

Palette returns a ramp value from hex colors (dark to bright), panicking on a malformed one as Hex does.

func ParseValue(kind ValueKind, s string) (Value, error)

ParseValue reads s as a value of kind, as Value.String writes it: a number must be the whole of s (surrounding space aside), a color is #rgb, #rrggbb or #rrggbbaa (whose alpha is ignored), and a ramp's colors and a list's numbers are separated by commas.

func RampOf(colors []uint32) Value

RampOf returns a ramp value of colors.

func Text(s string) Value

Text returns a text value.

func (v Value) Kind() ValueKind

Kind returns what v holds.

func (v Value) String() string

String writes v as the game pixelfx command reads it: a number, true or false, #rrggbb, a comma-separated list of colors or numbers, or the text itself.

type ValueKind uint8

ValueKind is what an option holds.

const (
	// KindNone is no value.
	KindNone ValueKind = iota
	// KindNumber is a number, such as a seed, a size or a speed.
	KindNumber
	// KindBool is on or off.
	KindBool
	// KindColor is one color.
	KindColor
	// KindRamp is a list of colors, dark to bright: a palette.
	KindRamp
	// KindText is a string, such as the words a UI effect shows.
	KindText
	// KindNumbers is a list of numbers.
	KindNumbers
)
func (k ValueKind) String() string

String names the kind as the game pixelfx command and its errors do.

type View struct {
	Source func() core.ImageSource
	Scale  float32
	// Class is Tailwind CSS classes and Style the style, as core.Canvas's.
	Class string
	Style core.Style
	// Label names what the view shows for assistive technology.
	Label string
}

View is a canvas that draws an effect's frames scaled up without smoothing: Source returns the picture to show (an Image's, usually), read again whenever a signal it reads changes, and Scale is how many points each pixel takes (1 when 0): any scale works, and a whole number keeps every pixel the same size.

func (v View) Render(*core.Scope) core.Node

Render implements core.Node.

type Weapon struct {
	Two    float64
	HasTwo bool
	Across bool
	Draw   func(T *Hand, q Pose, off [3]float64)
}

Weapon is something the character can hold: Two is where the other hand goes on it when both do (none when HasTwo is false), Across lays the handle across the weapon's length, and Draw draws it with the pose and the far hand's place.