Documentation
¶
Overview ¶
Package sketch is a simplified wrapper around Ebiten Go's 2D game engine designed for creative coding and quick visual experiments. Instead of managing the full Ebiten game loop yourself, you implement a single `Sketchable` interface and call `Run`.
Index ¶
- Constants
- func CursorPosition() vector.Vector
- func FPS() float64
- func Fullscreen(enable bool)
- func IsFullscreen() bool
- func IsKeyPressed(k Key) bool
- func IsMouseButtonPressed(k Key) bool
- func MonitorSize() vector.Vector
- func Run(screenWidth, screenHeight int, sketch Sketchable, opts ...Option) error
- func Scroll() (dx, dy float64)
- func TPS() float64
- type Key
- type MouseButton
- type Option
- type Screen
- func (s *Screen) Arc(v vector.Vector, radius, startAngle, endAngle, strokeWidth float64, ...)
- func (s *Screen) At(x, y int) color.Color
- func (s *Screen) Circle(v vector.Vector, radius, strokeWidth float64, c color.Color)
- func (s *Screen) Clear()
- func (s *Screen) Fill(c color.Color)
- func (s *Screen) FillArc(v vector.Vector, radius, startAngle, endAngle float64, c color.Color)
- func (s *Screen) FillCircle(v vector.Vector, radius, strokeWidth float64, c color.Color)
- func (s *Screen) FillRectangle(v vector.Vector, width, height, strokeWidth float64, c color.Color)
- func (s *Screen) FillShape(points []vector.Vector, close bool, c color.Color)
- func (s *Screen) Height() float64
- func (s *Screen) Line(v1, v2 vector.Vector, strokeWidth float64, c color.Color)
- func (s *Screen) Pull()
- func (s *Screen) Push()
- func (s *Screen) Rectangle(v vector.Vector, width, height, strokeWidth float64, c color.Color)
- func (s *Screen) Rotate(angle float64)
- func (s *Screen) Scale(rate float64)
- func (s *Screen) ScaleX(rate float64)
- func (s *Screen) ScaleY(rate float64)
- func (s *Screen) Shape(points []vector.Vector, close bool, strokeWidth float64, c color.Color)
- func (s *Screen) Size() vector.Vector
- func (s *Screen) Transform(v vector.Vector)
- func (s *Screen) TransformX(dx float64)
- func (s *Screen) TransformY(dy float64)
- func (s *Screen) Width() float64
- type Sketch
- type Sketchable
- type State
Constants ¶
const ( // Termination is returned when the sketch is terminated. Termination sketchErr = "sketch terminated" // ErrNilSketch is returned when the sketch is not provided. ErrNilSketch sketchErr = "sketch cannot be nil" // ErrInvalidScreenDimensions is returned when the screen dimensions are not positive. ErrInvalidScreenDimensions sketchErr = "screen dimensions must be positive" // ErrSketchAlreadyRunning is returned when the sketch is already running. ErrSketchAlreadyRunning sketchErr = "another sketch is already running" )
Variables ¶
This section is empty.
Functions ¶
func CursorPosition ¶
CursorPosition returns the current position of the mouse cursor.
func IsFullscreen ¶
func IsFullscreen() bool
IsFullscreen returns true if the sketch is currently in fullscreen.
func IsKeyPressed ¶
IsKeyPressed returns true if the given key is currently pressed.
func IsMouseButtonPressed ¶
IsKeyPressed returns true if the given key is currently pressed.
func Run ¶
func Run( screenWidth, screenHeight int, sketch Sketchable, opts ...Option, ) error
Run runs the sketch. It returns ErrNilSketch if sketch is nil. It returns ErrInvalidScreenDimensions if screenWidth or screenHeight is less than or equal to 0. It returns ErrSketchAlreadyRunning if another sketch is already running.
Types ¶
type Key ¶
type Key int
Key is a key on the keyboard.
const ( KeyA Key = Key(ebiten.KeyA) KeyB Key = Key(ebiten.KeyB) KeyC Key = Key(ebiten.KeyC) KeyD Key = Key(ebiten.KeyD) KeyE Key = Key(ebiten.KeyE) KeyF Key = Key(ebiten.KeyF) KeyG Key = Key(ebiten.KeyG) KeyH Key = Key(ebiten.KeyH) KeyI Key = Key(ebiten.KeyI) KeyJ Key = Key(ebiten.KeyJ) KeyK Key = Key(ebiten.KeyK) KeyL Key = Key(ebiten.KeyL) KeyM Key = Key(ebiten.KeyM) KeyN Key = Key(ebiten.KeyN) KeyO Key = Key(ebiten.KeyO) KeyP Key = Key(ebiten.KeyP) KeyQ Key = Key(ebiten.KeyQ) KeyR Key = Key(ebiten.KeyR) KeyS Key = Key(ebiten.KeyS) KeyT Key = Key(ebiten.KeyT) KeyU Key = Key(ebiten.KeyU) KeyV Key = Key(ebiten.KeyV) KeyW Key = Key(ebiten.KeyW) KeyX Key = Key(ebiten.KeyX) KeyY Key = Key(ebiten.KeyY) KeyZ Key = Key(ebiten.KeyZ) KeyAltLeft Key = Key(ebiten.KeyAltLeft) KeyAltRight Key = Key(ebiten.KeyAltRight) KeyArrowDown Key = Key(ebiten.KeyArrowDown) KeyArrowLeft Key = Key(ebiten.KeyArrowLeft) KeyArrowRight Key = Key(ebiten.KeyArrowRight) KeyArrowUp Key = Key(ebiten.KeyArrowUp) KeyBackquote Key = Key(ebiten.KeyBackquote) KeyBackslash Key = Key(ebiten.KeyBackslash) KeyBackspace Key = Key(ebiten.KeyBackspace) KeyBracketLeft Key = Key(ebiten.KeyBracketLeft) KeyBracketRight Key = Key(ebiten.KeyBracketRight) KeyCapsLock Key = Key(ebiten.KeyCapsLock) KeyComma Key = Key(ebiten.KeyComma) KeyContextMenu Key = Key(ebiten.KeyContextMenu) KeyControlLeft Key = Key(ebiten.KeyControlLeft) KeyControlRight Key = Key(ebiten.KeyControlRight) KeyDelete Key = Key(ebiten.KeyDelete) KeyDigit0 Key = Key(ebiten.KeyDigit0) KeyDigit1 Key = Key(ebiten.KeyDigit1) KeyDigit2 Key = Key(ebiten.KeyDigit2) KeyDigit3 Key = Key(ebiten.KeyDigit3) KeyDigit4 Key = Key(ebiten.KeyDigit4) KeyDigit5 Key = Key(ebiten.KeyDigit5) KeyDigit6 Key = Key(ebiten.KeyDigit6) KeyDigit7 Key = Key(ebiten.KeyDigit7) KeyDigit8 Key = Key(ebiten.KeyDigit8) KeyDigit9 Key = Key(ebiten.KeyDigit9) KeyEnd Key = Key(ebiten.KeyEnd) KeyEnter Key = Key(ebiten.KeyEnter) KeyEqual Key = Key(ebiten.KeyEqual) KeyEscape Key = Key(ebiten.KeyEscape) KeyF1 Key = Key(ebiten.KeyF1) KeyF2 Key = Key(ebiten.KeyF2) KeyF3 Key = Key(ebiten.KeyF3) KeyF4 Key = Key(ebiten.KeyF4) KeyF5 Key = Key(ebiten.KeyF5) KeyF6 Key = Key(ebiten.KeyF6) KeyF7 Key = Key(ebiten.KeyF7) KeyF8 Key = Key(ebiten.KeyF8) KeyF9 Key = Key(ebiten.KeyF9) KeyF10 Key = Key(ebiten.KeyF10) KeyF11 Key = Key(ebiten.KeyF11) KeyF12 Key = Key(ebiten.KeyF12) KeyF13 Key = Key(ebiten.KeyF13) KeyF14 Key = Key(ebiten.KeyF14) KeyF15 Key = Key(ebiten.KeyF15) KeyF16 Key = Key(ebiten.KeyF16) KeyF17 Key = Key(ebiten.KeyF17) KeyF18 Key = Key(ebiten.KeyF18) KeyF19 Key = Key(ebiten.KeyF19) KeyF20 Key = Key(ebiten.KeyF20) KeyF21 Key = Key(ebiten.KeyF21) KeyF22 Key = Key(ebiten.KeyF22) KeyF23 Key = Key(ebiten.KeyF23) KeyF24 Key = Key(ebiten.KeyF24) KeyHome Key = Key(ebiten.KeyHome) KeyInsert Key = Key(ebiten.KeyInsert) KeyIntlBackslash Key = Key(ebiten.KeyIntlBackslash) KeyMetaLeft Key = Key(ebiten.KeyMetaLeft) KeyMetaRight Key = Key(ebiten.KeyMetaRight) KeyMinus Key = Key(ebiten.KeyMinus) KeyNumLock Key = Key(ebiten.KeyNumLock) KeyNumpad0 Key = Key(ebiten.KeyNumpad0) KeyNumpad1 Key = Key(ebiten.KeyNumpad1) KeyNumpad2 Key = Key(ebiten.KeyNumpad2) KeyNumpad3 Key = Key(ebiten.KeyNumpad3) KeyNumpad4 Key = Key(ebiten.KeyNumpad4) KeyNumpad5 Key = Key(ebiten.KeyNumpad5) KeyNumpad6 Key = Key(ebiten.KeyNumpad6) KeyNumpad7 Key = Key(ebiten.KeyNumpad7) KeyNumpad8 Key = Key(ebiten.KeyNumpad8) KeyNumpad9 Key = Key(ebiten.KeyNumpad9) KeyNumpadAdd Key = Key(ebiten.KeyNumpadAdd) KeyNumpadDecimal Key = Key(ebiten.KeyNumpadDecimal) KeyNumpadDivide Key = Key(ebiten.KeyNumpadDivide) KeyNumpadEnter Key = Key(ebiten.KeyNumpadEnter) KeyNumpadEqual Key = Key(ebiten.KeyNumpadEqual) KeyNumpadMultiply Key = Key(ebiten.KeyNumpadMultiply) KeyNumpadSubtract Key = Key(ebiten.KeyNumpadSubtract) KeyPageDown Key = Key(ebiten.KeyPageDown) KeyPageUp Key = Key(ebiten.KeyPageUp) KeyPause Key = Key(ebiten.KeyPause) KeyPeriod Key = Key(ebiten.KeyPeriod) KeyPrintScreen Key = Key(ebiten.KeyPrintScreen) KeyQuote Key = Key(ebiten.KeyQuote) KeyScrollLock Key = Key(ebiten.KeyScrollLock) KeySemicolon Key = Key(ebiten.KeySemicolon) KeyShiftLeft Key = Key(ebiten.KeyShiftLeft) KeyShiftRight Key = Key(ebiten.KeyShiftRight) KeySlash Key = Key(ebiten.KeySlash) KeySpace Key = Key(ebiten.KeySpace) KeyTab Key = Key(ebiten.KeyTab) KeyAlt Key = Key(ebiten.KeyAlt) KeyControl Key = Key(ebiten.KeyControl) KeyShift Key = Key(ebiten.KeyShift) )
type MouseButton ¶
type MouseButton int
MouseButton is a mouse button.
const ( MouseButtonLeft MouseButton = MouseButton(ebiten.MouseButtonLeft) MouseButtonRight MouseButton = MouseButton(ebiten.MouseButtonRight) MouseButtonMiddle MouseButton = MouseButton(ebiten.MouseButtonMiddle) MouseButton0 MouseButton = MouseButton(ebiten.MouseButton0) MouseButton1 MouseButton = MouseButton(ebiten.MouseButton1) MouseButton2 MouseButton = MouseButton(ebiten.MouseButton2) MouseButton3 MouseButton = MouseButton(ebiten.MouseButton3) MouseButton4 MouseButton = MouseButton(ebiten.MouseButton4) )
type Option ¶
type Option func(sketchBuildParams)
Option is a function that configures a sketch.
func WithAntyaliasing ¶
WithAntyaliasing enables or disables antialiasing (enabled by default).
func WithBackgroundColor ¶
WithBackgroundColor sets the background color of the sketch ([240, 240, 240, 255] by default).
func WithResizing ¶
WithResizing enables or disables resizing (enabled by default).
func WithRunnableOnUnfocused ¶
WithRunnableOnUnfocused enables or disables the game to be runnable on unfocused (enabled by default).
func WithTerminationKeys ¶
WithTerminationKey sets the key which will terminate the game.
func WithWindowTitle ¶
WithWindowTitle sets the window title of the sketch (no title by default).
type Screen ¶
type Screen struct {
// contains filtered or unexported fields
}
Screen is the screen used to draw to.
func (*Screen) Arc ¶
func (s *Screen) Arc(v vector.Vector, radius, startAngle, endAngle, strokeWidth float64, c color.Color)
Arc draws an arc at the given position with the given radius, start angle, end angle, stroke width and color.
func (*Screen) Circle ¶
Circle draws a circle at the given position with the given radius, stroke width and color.
func (*Screen) FillArc ¶
FillArc draws a filled arc (pie slice) at the given position with the given radius, start angle, end angle and color.
func (*Screen) FillCircle ¶
FillCircle draws a filled circle at the given position with the given radius, stroke width and color.
func (*Screen) FillRectangle ¶
FillRectangle draws a filled rectangle at the given position with the given width, height, stroke width and color.
func (*Screen) FillShape ¶
FillShape draws a filled polygon through the given points with the given color. If close is true, the shape is closed. If len(points) < 2, nothing is drawn. If len(points) == 2, a line is drawn.
func (*Screen) Pull ¶
func (s *Screen) Pull()
Pull removes the most recently pushed transformation layer. Pulling the initial layer has no effect.
func (*Screen) Push ¶
func (s *Screen) Push()
Push adds an identity transformation layer to the stack.
func (*Screen) Rectangle ¶
Rectangle draws a rectangle at the given position with the given width, height, stroke width and color.
func (*Screen) Shape ¶
Shape draws a polygon through the given points with the given stroke width and color. If close is true, the shape is closed. If len(points) < 2, nothing is drawn. If len(points) == 2, a line is drawn.
func (*Screen) TransformX ¶
TransformX moves the origin of the coordinate system along the X axis.
func (*Screen) TransformY ¶
TransformY moves the origin of the coordinate system along the Y axis.
type Sketch ¶
type Sketch struct{}
Sketch is a noop Sketchable which can be embedded and added to Sketch.
type Sketchable ¶
type Sketchable interface {
// Update is called every frame.
Update(*State) error
// Draw is used each frame to render it.
Draw(*Screen)
// Setup is called once before first Update() call.
Setup(state *State) error
}
Sketchable is a single sketchable object.
type State ¶
type State struct {
// contains filtered or unexported fields
}
State is the state of the sketch used to provide information about the current state of the sketch to Update().
func (*State) ScreenSize ¶
ScreenSize returns the width and height of the screen.