generate

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 24 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	AtlasWidth  = 8 * cellWidth
	AtlasHeight = len(RowSpecs) * cellHeight
)

Atlas pixel size, eight cells wide and one row per state

View Source
var BaseVariations = []string{
	"",
	"a distinctly different colour palette and markings",
	"a heavier, broader silhouette with sturdier proportions",
	"a different facial structure and expression matching the concept tone, with unique accent/accessory details",
	"a leaner, taller build and an alternate colour scheme",
	"bolder, more saturated colours and a stronger expression matching the concept tone",
}

Per draft nudges varying the look but not the pose

View Source
var RowSpecs = []RowSpec{
	{"idle", 0, 6}, {"running-right", 1, 8}, {"running-left", 2, 8}, {"waving", 3, 4}, {"jumping", 4, 5},
	{"failed", 5, 8}, {"waiting", 6, 6}, {"running", 7, 6}, {"review", 8, 6},
}

Atlas rows in the petdex order, short rows leaving their tail transparent

View Source
var StateActions = map[string]string{
	"idle": "a calm idle loop: subtle breathing, a tiny blink or gentle bob, no big gestures",
	"running-right": "a sideways walk/run locomotion cycle moving to the RIGHT: the character " +
		"faces and travels right with clear directional steps, a smooth gait loop",
	"running-left": "a sideways walk/run locomotion cycle moving to the LEFT: the character " +
		"faces and travels left with clear directional steps (the mirror of the " +
		"right-facing run)",
	"waving":  "a friendly greeting: raising a paw/hand/limb to wave, clear up-and-down gesture",
	"jumping": "a happy celebration jump: anticipation, lift off the ground, peak, and land",
	"failed":  "a sad or deflated reaction: slumped, dejected, small frown — readable but not noisy",
	"waiting": "an expectant 'waiting on you' pose: looking up/out as if asking for input " +
		"or approval — distinct from idle and review",
	"running": "focused active work, staying IN PLACE (NOT walking or foot-running): " +
		"leaning in, concentrating, busy 'thinking / processing / typing' energy",
	"review": "careful inspection: a focused lean, head tilt, studying something intently",
}

What each state depicts, phrased to avoid detached effects, motion lines and shadows

Functions

func BuildBasePrompt

func BuildBasePrompt(concept, style, variation string) string

Base look prompt, a single centred full body mascot, the variation differentiating drafts

func BuildRowPrompt

func BuildRowPrompt(state string, frameCount int, style string) string

Row strip prompt of the frame count poses left to right, identity locked to the attached base

func ClearTransparentRGB

func ClearTransparentRGB(img *image.NRGBA) *image.NRGBA

Zeroes the colour of fully transparent pixels so no halo residue remains

func ComposeAtlas

func ComposeAtlas(framesByState map[string][]*image.NRGBA) *image.NRGBA

Packs per state frames into the atlas, short states leaving trailing cells transparent

func ExtractStripFrames

func ExtractStripFrames(path string, frameCount int, method string, fit bool) ([]*image.NRGBA, error)

Turns one generated row strip into the frames, components first then slots, auto salvaging leniently

func Generate

func Generate(ctx context.Context, env *tools.Env, prompt string, n int, references []string, sprite *SpriteProvider, prefix, aspectRatio string) ([]string, error)

Generates n sprite images and returns their local paths, retrying without the transparent flag where rejected

func GenerateBaseDrafts

func GenerateBaseDrafts(ctx context.Context, env *tools.Env, concept string, o DraftOptions) ([]string, error)

Generates candidate base looks concurrently and returns their hardened image paths

func MirrorFrames

func MirrorFrames(frames []*image.NRGBA) []*image.NRGBA

Each frame flipped horizontally

func NormalizeCells

func NormalizeCells(framesByState []StateFrames, pad int) map[string][]*image.NRGBA

Registers every frame into a cell with one shared scale and baseline so the pet never slides or pulses

func RemoveBackground

func RemoveBackground(img *image.NRGBA, chromaKey *[3]int, threshold float64) *image.NRGBA

Image with its flat background keyed out from the border inward, a real alpha background only repaired

func SingleFrame

func SingleFrame(path string, fit bool) (*image.NRGBA, error)

One frame from a standalone image, fit false giving the raw keyed sprite for NormalizeCells

func StyleHint

func StyleHint(style string) string

Style suffix of a named style, auto when empty, nothing for an unknown one

Types

type AtlasValidation

type AtlasValidation struct {
	OK               bool
	Width, Height    int
	Errors, Warnings []string
	FilledStates     []string
}

AtlasValidation is the geometry, occupancy and transparency check of an atlas

func ValidateAtlas

func ValidateAtlas(atlas *image.NRGBA) AtlasValidation

Checks atlas geometry, occupancy and transparency

type Box

type Box [4]int

Box is a left, top, right, bottom pixel rectangle as PIL boxes are

type DraftOptions

type DraftOptions struct {
	N           int
	Style       string
	References  []string
	Provider    *SpriteProvider
	OnDraft     func(index int, path string)
	IsCancelled func() bool
}

Draft generation options, zero N taking four and empty Style auto

type GenerationError

type GenerationError struct{ Msg string }

GenerationError is any image generation failure, no provider, API error or IO

func (*GenerationError) Error

func (e *GenerationError) Error() string

type HatchOptions

type HatchOptions struct {
	BaseImage, Slug, DisplayName, Description, Concept, Style string
	OnProgress                                                ProgressFn
	Provider                                                  *SpriteProvider
	IsCancelled                                               func() bool
}

Hatch inputs, empty Style meaning auto

type HatchResult

type HatchResult struct {
	Slug, DisplayName, Spritesheet string
	States                         []string
	Validation                     AtlasValidation
}

HatchResult is the outcome of a successful hatch

func HatchPet

func HatchPet(ctx context.Context, env *tools.Env, o HatchOptions) (*HatchResult, error)

Turns an approved base image into a full installed pet, idle falling back to the base look

type ProgressFn

type ProgressFn func(event, detail string)

ProgressFn receives hatch progress events such as row, compose and save

type RowSpec

type RowSpec struct {
	State       string
	Row, Frames int
}

RowSpec is one atlas row, its state, row index and frame count

type SpriteProvider

type SpriteProvider struct {
	Name               string
	Provider           media.ImageGenProvider
	SupportsReferences bool
}

SpriteProvider is the resolved image provider and whether it takes reference images

func ResolveProvider

func ResolveProvider(ctx context.Context, env *tools.Env, requireReferences bool, prefer string) (*SpriteProvider, error)

Picks the sprite image provider, the env override, prefer, the active one, then the first available

type StateFrames

type StateFrames struct {
	State  string
	Frames []*image.NRGBA
}

StateFrames is one state's frames in insertion order

Jump to

Keyboard shortcuts

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