Documentation ¶
Overview ¶
Package common provides types and functions that are used by multiple demos.
Index ¶
- Constants
- func AbsInt(v int) int
- func Clamp(v, low, high float64) float64
- func Clamp32(v, low, high float32) float32
- func ClampInt(v, low, high int) int
- func Distance(x1, y1, x2, y2 float64) float64
- func DistanceSq(x1, y1, x2, y2 float64) float64
- func Norm(dx, dy float64) (float64, float64, float64)
- func NormAngle(angle float64) float64
- func NormAngle32(angle float32) float32
- func RandBetweenUIn8(lim1, lim2 uint8) uint8
- func Rotate(x, y, angle float64) (float64, float64)
- func SelectRoulette(probs []float64) (int, bool)
- func SubtractHeadings(h1, h2 float64) float64
- type EbitenImage
- type Game
- type Grid
- func (g *Grid[T]) CellCenter(x, y int) (float64, float64)
- func (g *Grid[T]) Cellsize() float64
- func (g *Grid[T]) Contains(x, y int) bool
- func (g *Grid[T]) Fill(value T)
- func (g *Grid[T]) Get(x, y int) T
- func (g *Grid[T]) GetPointer(x, y int) *T
- func (g *Grid[T]) Height() int
- func (g *Grid[T]) IsInBounds(x, y float64) bool
- func (g *Grid[T]) Set(x, y int, value T)
- func (g *Grid[T]) ToCell(x, y float64) (int, int)
- func (g *Grid[T]) ToCellCenter(x, y float64) (float64, float64)
- func (g *Grid[T]) Width() int
- type Image
- type Mouse
- type SimulationSpeed
- type Vec2f
- func (v *Vec2f) Add(other Vec2f)
- func (v Vec2f) Angle() float64
- func (v *Vec2f) Copy() Vec2f
- func (v Vec2f) Distance(other Vec2f) float64
- func (v Vec2f) DistanceSq(other Vec2f) float64
- func (v *Vec2f) Div(factor float64)
- func (v Vec2f) Get(dim int) float64
- func (v *Vec2f) IsZero() bool
- func (v Vec2f) Len() float64
- func (v Vec2f) LenSq() float64
- func (v *Vec2f) Mul(factor float64)
- func (v *Vec2f) Norm(length float64) float64
- func (v *Vec2f) Sub(other Vec2f)
Constants ¶
const DegToRad = math.Pi / 180.0
DegToRad conversion factor.
const RadToDeg = 180.0 / math.Pi
RadToDeg conversion factor.
Variables ¶
This section is empty.
Functions ¶
func DistanceSq ¶
DistanceSq calculates the squared distance between two points.
func NormAngle32 ¶
NormAngle32 brings an angle into range [0, 2*PI).
func RandBetweenUIn8 ¶
RandBetweenUIn8 returns a random uint8 between the given limits, both inclusive
func SelectRoulette ¶
SelectRoulette performs roulette selection
func SubtractHeadings ¶
SubtractHeadings calculates the rotation required to come from h2 to h1.
Types ¶
type EbitenImage ¶
EbitenImage resource for drawing. Will be shown on an HTML5 canvas.
type Game ¶
type Game struct { Model *model.Model Screen EbitenImage Mouse Mouse // contains filtered or unexported fields }
Game container
func (*Game) IsMouseInside ¶
IsMouseInside returns whether the mouse is inside the game canvas.
type Grid ¶
type Grid[T any] struct { // contains filtered or unexported fields }
Grid data structure for 2D uniform grids.
func NewGridExtent ¶
NewGridExtent returns a new Grid with the given global extent.
func (*Grid[T]) CellCenter ¶
CellCenter returns the world coordinates of the center of the given cell.
func (*Grid[T]) GetPointer ¶
Get a pointer to a value from the Grid.
func (*Grid[T]) IsInBounds ¶
Contains returns whether the grid contains the given world coordinates.
func (*Grid[T]) ToCellCenter ¶
ToCellCenter returns the world coordinates of the center of the cell the given point is in.
type SimulationSpeed ¶
type SimulationSpeed struct {
Exponent int
}
SimulationSpeed resource. The Game will adapt the simulation speed if the resource is present.
type Vec2f ¶
type Vec2f struct {
X, Y float64
}
Vec2f is a 2d float vector
func (Vec2f) DistanceSq ¶
DistanceSq to another vector