ggfx/examples/icon/main.go

41 lines
977 B
Go

package main
import "os"
import "image"
import "image/png"
import "git.tebibyte.media/tomo/ggfx"
func main () {
img := image.NewRGBA(image.Rect(0, 0, 256, 256))
canvas := ggfx.Image[uint8] {
Pix: img.Pix,
Stride: img.Stride,
Rect: img.Rect,
Width: 4,
}
black := []uint8 { 0, 0, 0, 255 }
orange := []uint8 { 255, 48, 0, 255 }
midpoint := image.Pt(canvas.Rect.Dx() / 2, canvas.Rect.Dy() / 2)
canvas.FillRectangle(orange, canvas.Rect)
for x := 1; x <= 6; x ++ {
point := image.Pt(x, 7 - x)
canvas.FillRectangle(black, image.Rectangle {
Min: point.Mul(32),
Max: point.Add(image.Pt(1, 1)).Mul(32),
})
}
ring := ggfx.Circle(32, 88, midpoint)
canvas.StrokePolygon(orange, 32, ring...)
canvas.StrokePolygon(black, 16, ring...)
file, err := os.Create("TEST.png")
if err != nil { panic(err.Error()) }
defer file.Close()
err = png.Encode(file, img)
if err != nil { panic(err.Error()) }
println("Open TEST.png to see the result.")
}