gg
Repository ufficiale: fogleman/gg: Go Graphics - 2D rendering in Go with a simple API. (github.com)
Documentazione ufficiale: gg package - github.com/fogleman/gg - Go Packages
Esempi ufficiali: gg/examples at master · fogleman/gg (github.com)
gg è un motore di rendering grafico 2D consolidato, adatto per generare immagini.
Installazione
go get -u github.com/fogleman/ggGuida Rapida
go
package main
import "github.com/fogleman/gg"
func main() {
dc := gg.NewContext(1000, 1000) // Crea una tela alta 1000 e larga 1000
dc.DrawCircle(500, 500, 400) // Disegna un cerchio di raggio 400 alle coordinate (500,500)
dc.SetRGB(0, 0, 0) // Imposta il colore nero
dc.Fill() // Riempi
dc.SavePNG("out.png") // Salva nel file immagine
}Punti

go
func TestDot(t *testing.T) {
dc := gg.NewContext(1000, 1000)
dc.SetRGB(0, 0, 0)
for i := 1; i < 10; i++ {
dc.DrawPoint(float64(50*i), float64(50*i), 5) // Imposta coordinate e raggio del punto
}
dc.Fill() // Riempi
dc.SavePNG("out.png")
}Linee

go
func TestLines(t *testing.T) {
dc := gg.NewContext(1000, 1000)
dc.SetRGB(0, 0, 0)
dc.SetLineWidth(5) // Imposta larghezza linea
dc.DrawLine(1000, 0, 0, 1000)
dc.DrawLine(1000, 1000, 0, 0)
dc.Stroke() // Collega
dc.SavePNG("lines.png")
}