radar

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package radar is a widget that renders an animated radar sweep display.

The widget draws a rotating beam over a circular grid of range rings and crosshairs, reproducing the classic phosphor-persistence look of a monochrome PPI radar scope. The sweep trail fades from the beam's leading edge back through a configurable angular width.

Contact points are placed on the scope by the caller. Each contact dims gradually as the beam sweeps away and brightens again on the next pass, matching real radar refresh behaviour.

The sweep speed, beam width, direction (CW / CCW), total arc, and colours are all configurable through Option values.

Index

Constants

View Source
const DefaultBeamWidth = 35.0

DefaultBeamWidth is the default angular width of the sweep trail in degrees.

View Source
const DefaultContactChar = '◆'

DefaultContactChar is the default rune used to mark contact positions.

View Source
const DefaultRangeRings = 3

DefaultRangeRings is the default number of concentric range rings.

View Source
const DefaultSweepSpan = 360.0

DefaultSweepSpan is the default total sweep arc in degrees (full rotation).

View Source
const DefaultSweepSpeed = 60.0

DefaultSweepSpeed is the default sweep speed in degrees per second.

Variables

This section is empty.

Functions

This section is empty.

Types

type Contact

type Contact struct {
	// Angle is the bearing in degrees, measured clockwise from North
	// (0 = North, 90 = East, 180 = South, 270 = West).
	Angle float64

	// Distance is the range expressed as a fraction of the display radius
	// (0.0 = at the origin, 1.0 = at the outer ring edge).
	Distance float64

	// Elevation is the contact's altitude in feet above sea level.
	Elevation float64

	// Label is a short human-readable identifier shown in the contact log
	// and in the hover tooltip.
	Label string

	// Info is an optional extra line of free-form text appended to the
	// hover tooltip (e.g. "AIR · 350 kt"). Leave empty to omit.
	Info string
	// contains filtered or unexported fields
}

Contact represents a single radar return (blip) displayed on the scope.

type Direction

type Direction int

Direction specifies the direction of the radar sweep.

const (
	// DirectionClockwise sweeps the beam in a clockwise direction.
	DirectionClockwise Direction = iota
	// DirectionCounterClockwise sweeps the beam counter-clockwise.
	DirectionCounterClockwise
)

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option is used to provide options to Radar.

func BeamColor

func BeamColor(r, g, b int) Option

BeamColor sets the primary color of the radar beam and its phosphor trail. r, g, b are RGB24 components in the range [0, 255]. Defaults to neon green (0, 255, 70).

func BeamWidth

func BeamWidth(degrees float64) Option

BeamWidth sets the angular width of the visible sweep trail (the phosphor fade). The value is in degrees. Larger values create a wider, more gradual fade. Defaults to 35.

func Border

func Border(ls linestyle.LineStyle, cOpts ...cell.Option) Option

Border configures the Radar to have a border of the specified style. Optionally accepts cell options to style the border (e.g. color).

func BorderTitle

func BorderTitle(title string) Option

BorderTitle sets a text title displayed within the border. Has no effect if no border style is configured.

func ContactChar

func ContactChar(ch rune) Option

ContactChar sets the Unicode rune drawn at each contact point on the display. Defaults to '◆'.

func ContactColor

func ContactColor(r, g, b int) Option

ContactColor sets the color used to render contact blip runes. r, g, b are RGB24 components in the range [0, 255]. Defaults to red (255, 50, 50).

func HideTooltip

func HideTooltip() Option

HideTooltip disables the mouse-hover tooltip popup.

func RangeRings

func RangeRings(n int) Option

RangeRings sets the number of concentric distance markers drawn on the display. Must be between 1 and 10. Defaults to 3.

func ShowTooltip

func ShowTooltip() Option

ShowTooltip enables the mouse-hover tooltip popup. This is the default.

func StartAngle

func StartAngle(degrees float64) Option

StartAngle sets the initial beam angle in degrees measured clockwise from North (top of the display). Defaults to 0.

func SweepDirection

func SweepDirection(d Direction) Option

SweepDirection sets whether the beam sweeps clockwise or counter-clockwise. Defaults to DirectionClockwise.

func SweepSpan

func SweepSpan(degrees float64) Option

SweepSpan sets the total arc swept in one pass. Use 360 for a full rotation. Values less than 360 cause the beam to oscillate between 0 and SweepSpan rather than continuously rotating. Defaults to 360.

func SweepSpeed

func SweepSpeed(degreesPerSecond float64) Option

SweepSpeed sets the angular velocity of the radar sweep beam. The value is in degrees per second; e.g. 60 = one full rotation every 6 s. Defaults to 60.

type Radar

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

Radar renders an animated radar sweep display on the terminal.

Implements widgetapi.Widget. This object is thread-safe.

func New

func New(opts ...Option) (*Radar, error)

New returns a new Radar widget configured with the provided options. The widget is ready to draw immediately; call SetContacts to populate it.

func (*Radar) Draw

func (r *Radar) Draw(cvs *canvas.Canvas, meta *widgetapi.Meta) error

Draw renders the radar scope onto the canvas. It advances the sweep beam according to the time elapsed since the previous frame and recomputes contact intensities before rendering.

Draw implements widgetapi.Widget.Draw.

func (*Radar) Keyboard

func (r *Radar) Keyboard(k *terminalapi.Keyboard, meta *widgetapi.EventMeta) error

Keyboard implements widgetapi.Widget.Keyboard. The Radar widget does not process keyboard events.

func (*Radar) Mouse

func (r *Radar) Mouse(m *terminalapi.Mouse, meta *widgetapi.EventMeta) error

Mouse implements widgetapi.Widget.Mouse. The widget records the cursor position on every event so that Draw can render a contact tooltip when the cursor is over a blip.

func (*Radar) Options

func (r *Radar) Options() widgetapi.Options

Options implements widgetapi.Widget.Options.

func (*Radar) SetContacts

func (r *Radar) SetContacts(contacts []*Contact, opts ...Option) error

SetContacts replaces the set of contact points displayed on the scope. Provided options override values set when New was called.

Passing nil or an empty slice clears all contacts.

Directories

Path Synopsis
Binary radardemo displays a live radar sweep with randomly generated contacts and a real-time contact log.
Binary radardemo displays a live radar sweep with randomly generated contacts and a real-time contact log.

Jump to

Keyboard shortcuts

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