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.
- Canonical golden-angle spiral with pluggable radius scaling.
TraceandSpiraliterators for on-demand or batched generation.FitConstantutility to size the bloom to a canvas.streamsubpackage 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.
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 }) }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.
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.
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.
See Agent.md for guidance when automating changes or extending the library.
TBD – add your preferred license before publishing.