common

package
v0.0.0-...-28575ab Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package common provides types and functions that are used by multiple demos.

Index

Constants

View Source
const DegToRad = math.Pi / 180.0

DegToRad conversion factor.

View Source
const RadToDeg = 180.0 / math.Pi

RadToDeg conversion factor.

Variables

This section is empty.

Functions

func AbsInt

func AbsInt(v int) int

AbsInt calculates the absolute value og an integer.

func Clamp

func Clamp(v, low, high float64) float64

Clamp clamps to [low, high].

func Clamp32

func Clamp32(v, low, high float32) float32

Clamp32 clamps to [low, high].

func ClampInt

func ClampInt(v, low, high int) int

ClampInt clamps to [low, high].

func Distance

func Distance(x1, y1, x2, y2 float64) float64

Distance calculates the distance between two points.

func DistanceSq

func DistanceSq(x1, y1, x2, y2 float64) float64

DistanceSq calculates the squared distance between two points.

func Norm

func Norm(dx, dy float64) (float64, float64, float64)

Norm normalizes a vector. The third return value is the original vector's length.

func NormAngle

func NormAngle(angle float64) float64

NormAngle brings an angle into range [0, 2*PI).

func NormAngle32

func NormAngle32(angle float32) float32

NormAngle32 brings an angle into range [0, 2*PI).

func RandBetweenUIn8

func RandBetweenUIn8(lim1, lim2 uint8) uint8

RandBetweenUIn8 returns a random uint8 between the given limits, both inclusive

func Rotate

func Rotate(x, y, angle float64) (float64, float64)

Rotate rotates a vector.

func SelectRoulette

func SelectRoulette(probs []float64) (int, bool)

SelectRoulette performs roulette selection

func SubtractHeadings

func SubtractHeadings(h1, h2 float64) float64

SubtractHeadings calculates the rotation required to come from h2 to h1.

Types

type EbitenImage

type EbitenImage struct {
	Image  *ebiten.Image
	Width  int
	Height int
}

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 NewGame

func NewGame(mod *model.Model, width, height int) Game

NewGame returns a new game

func (*Game) Draw

func (g *Game) Draw(screen *ebiten.Image)

Draw the game.

func (*Game) Initialize

func (g *Game) Initialize()

Initialize the game.

func (*Game) IsMouseInside

func (g *Game) IsMouseInside() bool

IsMouseInside returns whether the mouse is inside the game canvas.

func (*Game) Layout

func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int)

Layout the game.

func (*Game) Run

func (g *Game) Run() error

Run the game.

func (*Game) Update

func (g *Game) Update() error

Update the game.

type Grid

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

Grid data structure for 2D uniform grids.

func NewGrid

func NewGrid[T any](width, height int, cellsize ...float64) Grid[T]

NewGrid returns a new Grid.

func NewGridExtent

func NewGridExtent[T any](width, height float64, cellsize ...float64) Grid[T]

NewGridExtent returns a new Grid with the given global extent.

func (*Grid[T]) CellCenter

func (g *Grid[T]) CellCenter(x, y int) (float64, float64)

CellCenter returns the world coordinates of the center of the given cell.

func (*Grid[T]) Cellsize

func (g *Grid[T]) Cellsize() float64

Cell size of the Grid.

func (*Grid[T]) Contains

func (g *Grid[T]) Contains(x, y int) bool

Contains returns whether the grid contains the given cell.

func (*Grid[T]) Fill

func (g *Grid[T]) Fill(value T)

Fill the grid with a value.

func (*Grid[T]) Get

func (g *Grid[T]) Get(x, y int) T

Get a value from the Grid.

func (*Grid[T]) GetPointer

func (g *Grid[T]) GetPointer(x, y int) *T

Get a pointer to a value from the Grid.

func (*Grid[T]) Height

func (g *Grid[T]) Height() int

Height of the Grid.

func (*Grid[T]) IsInBounds

func (g *Grid[T]) IsInBounds(x, y float64) bool

Contains returns whether the grid contains the given world coordinates.

func (*Grid[T]) Set

func (g *Grid[T]) Set(x, y int, value T)

Set a value in the grid.

func (*Grid[T]) ToCell

func (g *Grid[T]) ToCell(x, y float64) (int, int)

ToCell converts world coordinates to integer patch coordinates.

func (*Grid[T]) ToCellCenter

func (g *Grid[T]) ToCellCenter(x, y float64) (float64, float64)

ToCellCenter returns the world coordinates of the center of the cell the given point is in.

func (*Grid[T]) Width

func (g *Grid[T]) Width() int

Width of the Grid.

type Image

type Image struct {
	Image  *image.RGBA
	Width  int
	Height int
}

Image resource for drawing. Will be shown on an HTML5 canvas.

type Mouse

type Mouse struct {
	image.Point
	IsInside bool
}

Mouse resource for events.

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) Add

func (v *Vec2f) Add(other Vec2f)

Add adds a vector in-place

func (Vec2f) Angle

func (v Vec2f) Angle() float64

Len returns the length of the vector

func (*Vec2f) Copy

func (v *Vec2f) Copy() Vec2f

Copy copies the vector

func (Vec2f) Distance

func (v Vec2f) Distance(other Vec2f) float64

Distance to another vector

func (Vec2f) DistanceSq

func (v Vec2f) DistanceSq(other Vec2f) float64

DistanceSq to another vector

func (*Vec2f) Div

func (v *Vec2f) Div(factor float64)

Div divides a vector in-place

func (Vec2f) Get

func (v Vec2f) Get(dim int) float64

Get returns the coordinate value for a specific dimension

func (*Vec2f) IsZero

func (v *Vec2f) IsZero() bool

IsZero adds a vector in-place

func (Vec2f) Len

func (v Vec2f) Len() float64

Len returns the length of the vector

func (Vec2f) LenSq

func (v Vec2f) LenSq() float64

LenSq returns the squared length of the vector

func (*Vec2f) Mul

func (v *Vec2f) Mul(factor float64)

Mul multiplies a vector in-place

func (*Vec2f) Norm

func (v *Vec2f) Norm(length float64) float64

Norm normalizes a vector to the given length and returns the original length.

func (*Vec2f) Sub

func (v *Vec2f) Sub(other Vec2f)

Sub subtracts a vector in-place

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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