simulation

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2026 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FPS

func FPS(framesPerSecond int) float64

FPS returns the delta time for a fixed frames-per-second rate.

Types

type Glyph

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

Glyph represents a glyph in the simulation. The X axis uses a spring follower for a drifting, slightly-lagged feel. The Y axis uses direct Euler integration so gravity and floor bounces are lag-free and land exactly on the floor row.

type PhysicsConfig

type PhysicsConfig struct {
	Gravity            float64 // cells/frame² downward acceleration
	Restitution        float64 // fraction of speed retained on floor bounce
	XFloorFriction     float64 // fraction of target x velocity retained on floor bounce
	EnableCollision    bool    // enables glyph-glyph collisions (extra CPU work)
	EnableDespawn      bool    // enables resting glyph despawn after timeout
	RestThreshold      float64 // cells/frame speed below which a glyph is considered at rest
	RestTimeoutSeconds float64 // seconds at rest before despawn
	SpringFrequency    float64 // spring angular frequency for x-axis follow behavior
	SpringDampingRatio float64 // spring damping ratio for x-axis follow behavior
	LaunchKickMax      float64 // max upward launch speed magnitude for initial glyphs
	SpawnKickMax       float64 // max upward launch speed magnitude for spawned glyphs
	TargetDriftMax     float64 // max absolute x target drift speed
}

PhysicsConfig controls spring tuning and y-axis bounce behavior.

func DefaultPhysicsConfig

func DefaultPhysicsConfig() PhysicsConfig

DefaultPhysicsConfig returns the baseline motion tuning.

type Simulation

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

Simulation manages the bouncing glyphs.

func New

func New(count, fps int) *Simulation

New creates a new Simulation. Width and height are determined from the terminal on the first WindowSizeMsg.

func NewWithPhysicsConfig

func NewWithPhysicsConfig(count, fps int, physics PhysicsConfig) *Simulation

NewWithPhysicsConfig creates a new Simulation using caller-provided physics tuning.

func (*Simulation) EnableStream

func (sim *Simulation) EnableStream(reader io.Reader, spawnInterval, dropDelay time.Duration)

EnableStream configures the simulation to read glyphs from a stream and spawn them at a fixed interval.

func (*Simulation) Init

func (sim *Simulation) Init() tea.Cmd

Init requests the first animation frame.

func (*Simulation) Run

func (sim *Simulation) Run()

Run starts the Bubble Tea simulation.

func (*Simulation) Update

func (sim *Simulation) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update advances simulation state on frame ticks and handles quit keys.

func (*Simulation) View

func (sim *Simulation) View() string

type Spring

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

Spring caches coefficients for a damped harmonic oscillator.

func NewSpring

func NewSpring(deltaTime, angularFrequency, dampingRatio float64) (spring Spring)

NewSpring computes the coefficients for a spring with the given time step, angular frequency, and damping ratio.

func (Spring) Update

func (spring Spring) Update(pos, vel, equilibriumPos float64) (newPos, newVel float64)

Update advances a position and velocity toward the given equilibrium point.

type StreamConfig

type StreamConfig struct {
	Reader        io.Reader
	SpawnInterval time.Duration
	DropDelay     time.Duration
}

StreamConfig controls stdin-driven glyph spawning.

Jump to

Keyboard shortcuts

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