Documentation ¶
Overview ¶
Package tie provides a Processing-like API for simple and fun drawing, game making, data and algorithm visualization, generally - art :).
To start writing a new sketch, You need to initialize the engine first:
tie.Init(width, height, title, is_window_resizable)
Then You need to pass the functions You want to act as the ones listed below, in the right order, but only preload, setup, and draw are necessary:
preload // called only once, before setup, nothing can be drawn here setup // called only once, before draw, you can draw here draw // called once every frame keyPressed // called every time a key gets pressed keyReleased // called every time a key gets released mouseMoved // called every time the mouse is moved mousePressed // called every time a mouse key gets pressed mouseReleased // called every time a mouse key gets released scrolledY // called every time the mouse scroll Y-axis gets scrolled scrolledX // called every time the mouse scroll X-axis gets scrolled
To do that, call PassFunctions with the functions You want to use as arguments:
tie.PassFunctions( preload, setup, draw, )
The only thing that's left is launching the engine with:
tie.Launch()
The whole sketch should look something like this:
package main // import the package import ( "github.com/franeklubi/tie" ) func main() { // initialize engine in main tie.Init(500, 500, "window_name", false) // width, height, window_name, is_resizable // pass all the functions you want used by the engine tie.PassFunctions( preload, setup, draw, ) // launch the engine tie.Launch() } var ( img tie.Image ) func preload() { img = tie.LoadImage("/path/to/image.png") } func setup() { tie.Background(255, 255, 255, 255) } func draw() { tie.Fill(0, 255, 255, 255) tie.Rect(tie.Width/2-50, tie.Height/2-50, 100, 100) }
For more examples visit https://github.com/franeklubi/tie-examples/
Index ¶
- Constants
- Variables
- func Abs(n float64) float64
- func Acos(n float64) float64
- func Asin(n float64) float64
- func Atan(n float64) float64
- func Atan2(n1, n2 float64) float64
- func Background(r, g, b, a byte)
- func BeginShape(mode uint32)
- func CaToGl(x, y float64) (float64, float64)
- func Ceil(n float64) float64
- func Cos(n float64) float64
- func Cube(size float64)
- func DegToRad(degrees float64) float64
- func DepthRefreshOff()
- func DepthRefreshOn()
- func Ellipse(x, y, w, h float64)
- func EndShape()
- func Fill(r, g, b, a byte)
- func Floor(n float64) float64
- func GlToCa(x, y float64) (float64, float64)
- func HideMouse()
- func HsvToRgb(hue, saturation, value float64, alpha byte) (byte, byte, byte, byte)
- func Init(width, height float64, title string, resizable bool)
- func LOG(itm ...interface{})
- func Launch()
- func Limit(val, min, max float64) float64
- func LinInt(val, target, rate float64) float64
- func Line(x1, y1, x2, y2 float64)
- func Loop()
- func Mod(n1, n2 float64) float64
- func MoveBackFor2D()
- func MoveForwardFor3D()
- func NoFill()
- func NoLoop()
- func NoStroke()
- func PassFunctions(p ...func())
- func Point(x, y float64)
- func Pop()
- func Print(itm ...interface{})
- func Println(itm ...interface{})
- func Push()
- func RadToDeg(radians float64) float64
- func Random(n float64) float64
- func ReMap(val, start1, stop1, start2, stop2 float64) float64
- func Rect(x, y, w, h float64)
- func Redraw()
- func RgbToGl(r, g, b, a byte) (float64, float64, float64, float64)
- func Rotate(degrees float64)
- func RotateX(degrees float64)
- func RotateY(degrees float64)
- func RotateZ(degrees float64)
- func Scale(x, y, z float64)
- func SetCursorPos(x, y float64)
- func SetPos(x, y int)
- func SetSize(x, y int)
- func ShowMouse()
- func Sin(n float64) float64
- func Sphere(size float64, fidelity uint32)
- func Sqrt(n float64) float64
- func Stroke(r, g, b, a byte)
- func StrokeWidth(width float64)
- func Tan(n float64) float64
- func Text(txt string, size int, center_align bool)
- func ToggleFullscreen()
- func Translate(x, y, z float64)
- func TranslateGl(x, y, z float64)
- func Vertex(x, y float64)
- func Vertex3D(x, y, z float64)
- func VertexGl(x, y, z float64)
- type Color
- type ColorGl
- type Image
Constants ¶
const ( // keyboard special keys ENTER string = "ā" ESC string = "Ā" BACKSPACE string = "ă" CTRL string = "ŕ" L_CTRL string = "ŕ" R_CTRL string = "ř" SHIFT string = "Ŕ" L_SHIFT string = "Ŕ" R_SHIFT string = "Ř" ALT string = "Ŗ" ALT_GR string = "Ś" UP string = "ĉ" DOWN string = "Ĉ" LEFT string = "ć" RIGHT string = "Ć" // function keys F1 string = "Ģ" F2 string = "ģ" F3 string = "Ĥ" F4 string = "ĥ" F5 string = "Ħ" F6 string = "ħ" F7 string = "Ĩ" F8 string = "ĩ" F9 string = "Ī" F10 string = "ī" F11 string = "Ĭ" F12 string = "ĭ" // mouse keys MOUSE_LEFT glfw.MouseButton = glfw.MouseButtonLeft MOUSE_RIGHT glfw.MouseButton = glfw.MouseButtonRight MOUSE_MIDDLE glfw.MouseButton = glfw.MouseButtonMiddle // math consts PI float64 = math.Pi E float64 = math.E // OpenGL consts POINTS uint32 = gl.POINTS LINES uint32 = gl.LINES LINE_STRIP uint32 = gl.LINE_STRIP LINE_LOOP uint32 = gl.LINE_LOOP POLYGON uint32 = gl.POLYGON TRIANGLES uint32 = gl.TRIANGLES TRIANGLE_STRIP uint32 = gl.TRIANGLE_STRIP TRIANGLE_FAN uint32 = gl.TRIANGLE_FAN QUADS uint32 = gl.QUADS QUAD_STRIP uint32 = gl.QUAD_STRIP )
Consts helpful when interfacing with tie
Variables ¶
var ( // Width and Height of a created window Width float64 Height float64 )
var ( // when the respective events get triggered, these variables will change correspondingly Key_pressed bool = false Key string = "" MouseX float64 = 0 MouseY float64 = 0 Mouse_key glfw.MouseButton ScrollValue float64 = 0 )
var ( // total frame count Frames float64 = 0 )
Functions ¶
func BeginShape ¶
func BeginShape(mode uint32)
BeginShape (together with EndShape) provides a toolset for drawing more complex shapes
It should be called with one of the OpenGL consts (see Constants section)
To draw a shape - one of Vertex functions has to be called between the BeginShape and EndShape functions
func CaToGl ¶
CaToGl maps the tie coordinates ((0,0) at upper left) to OpenGL standard coordinates ((0,0) at the center)
func DepthRefreshOff ¶
func DepthRefreshOff()
DepthRefreshOff turns automatic depth refreshing off
Every time a shape is drawn the depth buffer is cleared to prevent Z-fighting
func EndShape ¶
func EndShape()
EndShape should be called after BeginShape
It draws a described shape to the buffer
func GlToCa ¶
GlToCa maps OpenGL standard coordinates ((0,0) at the center) to the tie coordinates ((0,0) at upper left)
func HsvToRgb ¶
Desired usage:
Fill(HsvToRgb(h, s, v, a)) Stroke(HsvToRgb(h, s, v, a)) Background(HsvToRgb(h, s, v, a))
RgbToHsv returns RGBA values based on HSV and Alpha values.
(hue=0-360, saturation=0-1, value=0-1, alpha=0-255)
func MoveBackFor2D ¶
func MoveBackFor2D()
MoveBackFor2D translates the matrix back from the point of origin, so that the entire 2d canvas can be seen
func MoveForwardFor3D ¶
func MoveForwardFor3D()
MoveForwardFor3D translates the matrix forward, so that the camera is at the point of origin
func PassFunctions ¶
func PassFunctions(p ...func())
PassFunctions serves as a middleman between a user and the engine. It receives a number of funcs that are going to be called at certain engine's events
func Pop ¶
func Pop()
Pop should be called after Push
It restores Your matrix to state saved by Push earlier
func Stroke ¶
func Stroke(r, g, b, a byte)
Stroke sets colour used to draw shapes' outline based on RGBA values (applies to Line and Point too)
func ToggleFullscreen ¶
func ToggleFullscreen()
ToggleFullscreen toggles between fullscreen and windowed modes
func TranslateGl ¶
func TranslateGl(x, y, z float64)
TranslateGl translates the matrix using the OpenGL standard coordinates ((0,0) at the center)
func Vertex ¶
func Vertex(x, y float64)
Vertex should be called between BeginShape and EndShape
Vertex lets you specify a vertex of the shape to be drawn using standard coordinates ((0,0) at upper left)
Types ¶
type Color ¶
type Color struct {
R, G, B, A byte
}
Color is used to hold the 0-255 range RGBA values
type ColorGl ¶
type ColorGl struct {
R, G, B, A float64
}
ColorGl is used to hold the 0-1 range RGBA values
type Image ¶
type Image struct { Pixels []byte // Pixels of a loaded image W, H int // Width and Height of an Image }
Image is used to hold the loaded image's pixel and size data
Pixels are stored in a down to up && left to right arrangement
To manipulate them see (*Image) Replace
func CopyPixels ¶
func CopyPixels() Image
CopyPixels returns an Image containing current frame buffer
func (*Image) PastePixels ¶
PastePixels draws an Image to the screen