scratch

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: May 31, 2024 License: Apache-2.0 Imports: 1 Imported by: 0

README

This package has been moved to a new GitHub account.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Black color.RGBA = color.RGBA{0x00, 0x00, 0x00, 0xFF}
	White color.RGBA = color.RGBA{0xFF, 0xFF, 0xFF, 0xFF}
	Red   color.RGBA = color.RGBA{0xFF, 0x00, 0x00, 0xFF}
	Lime  color.RGBA = color.RGBA{0x00, 0xFF, 0x00, 0xFF}
	Blue  color.RGBA = color.RGBA{0x00, 0x00, 0xFF, 0xFF}

	Yellow  color.RGBA = color.RGBA{0xFF, 0xFF, 0x00, 0xFF}
	Aqua    color.RGBA = color.RGBA{0x00, 0xFF, 0xFF, 0xFF}
	Magenta color.RGBA = color.RGBA{0xFF, 0x00, 0xFF, 0xFF}

	Orange color.RGBA = color.RGBA{0xFF, 0xA5, 0x00, 0xFF}
	Green  color.RGBA = color.RGBA{0x00, 0x80, 0x00, 0xFF}
	Purple color.RGBA = color.RGBA{0x80, 0x00, 0x80, 0xFF}
	Indigo color.RGBA = color.RGBA{0x4B, 0x00, 0x82, 0xFF}
	Violet color.RGBA = color.RGBA{0xEE, 0x82, 0xEE, 0xFF}

	// Other random ones
	SkyBlue color.RGBA = color.RGBA{0x87, 0xCE, 0xEB, 0xFF}
)

https://www.w3schools.com/colors/colors_names.asp

Functions

func Lerp added in v0.0.3

func Lerp(a, b, ratio float64) float64

The ratio is capped between 0 and 1

func LerpColor added in v0.0.3

func LerpColor(a, b color.RGBA, ratio float64) color.RGBA

Creates a color between the given a and b. 0 means a is given, 1 means b is given, .5 is a color half way between. The ratio is capped between 0 and 1 Currently the function floors the number instead of rounding to nearest.

func LerpUint8 added in v0.0.3

func LerpUint8(a, b uint8, ratio float64) uint8

The ratio is capped between 0 and 1 Currently the function floors the number instead of rounding to nearest.

Types

type Broker added in v0.0.3

type Broker[T any] struct {
	// contains filtered or unexported fields
}

A data broker that can be published to, and any entity that has subscribed will get a copy of the message. Any subscriber should make sure to unsubscribe before deleting the reference. An independent go routine is started to receive published messages and to distribute them to all subscribers. The go routine stops once Stop() is called and all subscribers have unsubscribed. Ideally this is a 1-to-n communication system. If there are multiple publishers, it would be hard to know when to call Stop.

func NewBroker added in v0.0.3

func NewBroker[T any](bufferSize int) *Broker[T]

Creates a new Broker of any given type and start it running.

func (*Broker[T]) Publish added in v0.0.3

func (b *Broker[T]) Publish(msg T)

Send a message to every current subscriber.

func (*Broker[T]) Stop added in v0.0.3

func (b *Broker[T]) Stop()

Stop the data broker. Only call this once. All subscriptions will be closed

func (*Broker[T]) Subscribe added in v0.0.3

func (b *Broker[T]) Subscribe() chan T

Subscribe to the data broker. Messages can be received on the returned channel.

func (*Broker[T]) Unsubscribe added in v0.0.3

func (b *Broker[T]) Unsubscribe(msgCh chan T)

Unsubscribe from the data broker. The reference to the channel can be safely discarded after calling this.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳