Simple and fast 2D graphics library for Go.
width := 1280
height := 720
canvas := kiten.NewCanvas(width, height, kiten.BlendAdd)
(you can use this later to overlay or draw on images, for example)
canvas := kiten.CanvasFromImageRGBA(image, kiten.BlendAdd)
If you're rendering multiple frames, remember to clear the canvas when drawing a new frame
canvas.Fill(color.RGBA{0, 0, 0, 255})
canvas.Line(100, 100, 500, 700, color.RGBA{255, 0, 0, 255})
canvas.Circle(150, 150, 70, color.RGBA{0, 0, 255, 255})
canvas.CircleFilled(150, 150, 70, color.RGBA{0, 0, 255, 255})
canvas.CircleOutline(150, 150, 70, color.RGBA{0, 0, 255, 255}, color.RGBA{0, 255, 0, 255})
This will do nothing if the coordinates are invalid
canvas.SetPixel(500, 500, color.RGBA{255, 255, 255, 255})
This will return a transparent color if the coordinates are invalid
canvas.PixelAt(170, 300) // Returns color.RGBA
canvas.Rect(100, 100, 200, 200, color.RGBA{0, 255, 0, 255})
canvas.RectFilled(100, 100, 200, 200, color.RGBA{0, 255, 0, 255})
canvas.PutCanvas(450, 300, 100, 150, canvas2)
import (
"rand"
"image"
)
// Generate a path
path := []image.Point{}
for i := 0; i < 100; i++ {
path = append(path, image.Pt(i*30, canvas.Height/2-rand.Intn(100)))
}
// Draw it
canvas.DrawPath(path, color.RGBA{255, 255, 255, 255})
import "golang.org/x/image/font/inconsolata"
canvas.Text("Hello World!", 500, 500, inconsolata.Regular8x16, color.RGBA{255, 255, 255, 255})
import "os"
file, err := os.Create("output.png")
if err != nil {
panic(err)
}
defer file.Close()
err := canvas.WritePNG(file)
if err != nil {
panic(err)
}
canvas.Triangle(500, 500, 500, 700, 600, 700, color.RGBA{255, 255, 255, 255})
canvas.TriangleFilled(500, 500, 500, 700, 600, 700, color.RGBA{255, 255, 255, 255})
canvas.TriangleOutline(500, 500, 500, 700, 600, 700, color.RGBA{255, 255, 255, 255}, color.RGBA{255, 0, 0, 255})