Documentation ¶
Overview ¶
Package sixteen simulates a 16-segment display drawn on a canvas.
Given a canvas, determines the placement and size of the individual segments and exposes API that can turn individual segments on and off or display ASCII characters.
The following outlines segments in the display and their names.
A1 A2 ------- ------- | \ | / | | \ | / | F | H J K | B | \ | / | | \ | / | -G1---- ----G2- | / | \ | | / | \ | E | N M L | C | / | \ | | / | \ | ------- ------- D1 D2
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Sanitize ¶
Sanitize returns a copy of the string, replacing all unsupported characters with a space character.
func SupportsChars ¶
SupportsChars asserts whether the display supports all runes in the provided string. The display only supports a subset of ASCII characters. Returns any unsupported runes found in the string in an unspecified order.
Types ¶
type Attributes ¶ added in v0.10.0
type Attributes struct { // VertBotY is the Y coordinate where the area of the segment vertically // at the bottom starts, i.e. Y coordinate of D1 and D2. VertBotY int // contains filtered or unexported fields }
Attributes contains attributes needed to draw the segment display. Refer to doc/segment_placement.svg for a visual aid and explanation of the usage of the square roots.
func NewAttributes ¶ added in v0.10.0
func NewAttributes(bcAr image.Rectangle) *Attributes
NewAttributes calculates attributes needed to place the segments for the provided pixel area.
type Display ¶
type Display struct {
// contains filtered or unexported fields
}
Display represents the segment display. This object is not thread-safe.
func (*Display) ClearSegment ¶
ClearSegment sets the specified segment off. This method is idempotent.
func (*Display) Draw ¶
Draw draws the current state of the segment display onto the canvas. The canvas must be at least MinCols x MinRows cells, or an error will be returned. Any options provided to draw overwrite the values provided to New.
func (*Display) SetCharacter ¶
SetCharacter sets all the segments that are needed to display the provided character. The display only supports a subset of ASCII characters, use SupportsChars() or Sanitize() to ensure the provided character is supported. Doesn't clear the display of segments set previously.
func (*Display) SetSegment ¶
SetSegment sets the specified segment on. This method is idempotent.
func (*Display) ToggleSegment ¶
ToggleSegment toggles the state of the specified segment, i.e it either sets or clears it depending on its current state.
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option is used to provide options.
type Segment ¶
type Segment int
Segment represents a single segment in the display.
const ( // A1 is a segment, see the diagram above. A1 Segment // A2 is a segment, see the diagram above. A2 // B is a segment, see the diagram above. B // C is a segment, see the diagram above. C // D1 is a segment, see the diagram above. D1 // D2 is a segment, see the diagram above. D2 // E is a segment, see the diagram above. E // F is a segment, see the diagram above. F // G1 is a segment, see the diagram above. G1 // G2 is a segment, see the diagram above. G2 // H is a segment, see the diagram above. H // J is a segment, see the diagram above. J // K is a segment, see the diagram above. K // L is a segment, see the diagram above. L // M is a segment, see the diagram above. M // N is a segment, see the diagram above. N )
func AllSegments ¶
func AllSegments() []Segment
AllSegments returns all 16 segments in an undefined order.
Directories ¶
Path | Synopsis |
---|---|
Package testsixteen provides helpers for tests that use the sixteen package.
|
Package testsixteen provides helpers for tests that use the sixteen package. |