Skip to content

jackhutson/phyllo

Repository files navigation

phyllo

phyllo is a small Go library that implements Vogel’s model of phyllotaxis (the Fibonacci flower). It focuses on fast, allocation-free generation of the spiral and provides helpers for streaming batches of points to downstream renderers.

Features

  • Canonical golden-angle spiral with pluggable radius scaling.
  • Trace and Spiral iterators for on-demand or batched generation.
  • FitConstant utility to size the bloom to a canvas.
  • stream subpackage with a reusable buffer and cancellation-aware streaming loop—ideal for Server-Sent Events (SSE) or WebSocket transports.
  • Table-driven tests and benchmarks covering accuracy and throughput.

Quick Start

package main import ( "fmt" "github.com/jackhutson/phyllo" ) func main() { const ( count = 1000 width = 800 height = 600 margin = 32	) constant := phyllo.FitConstant(count, width, height, margin) params := phyllo.DefaultParams(count, phyllo.Point2D{X: width / 2, Y: height / 2}, constant) phyllo.Trace(params, func(pt phyllo.Point) bool { fmt.Printf("%d -> (%.2f, %.2f)\n", pt.Index, pt.X, pt.Y) return pt.Index < 10 // stop early for the example	}) }

Batching for Streaming

s := phyllo.NewSpiral(params) buf := make([]phyllo.Point, 0, 512) for { batch := s.NextBatch(buf[:0]) if len(batch) == 0 { break	} // send batch to your renderer }

The stream package wraps the loop above and works with any object that implements the stream.Sink interface. For SSE, create a sink that marshals the batch to JSON and writes it to an http.ResponseWriter.

Benchmarks

Run the bundled benchmarks to validate performance on your hardware:

go test -run=^$ -bench=. -benchmem 

On an Apple M1 Pro, PointAt runs in ~13ns and a 200k point batch completes in ~6.5ms—fast enough to drive 60fps animation with headroom.

Project Layout

  • params.go, point.go, spiral.go: Core phyllotaxis math.
  • stream/: Streaming helpers and tests.
  • testdata/points.json: Golden fixture for cross-language parity tests.
  • docs/: Planning notes.

Agent Collaboration

See Agent.md for guidance when automating changes or extending the library.

License

TBD – add your preferred license before publishing.

About

Simple lib to implement a basic phyllotaxis algorithm for visualizations

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages