Add icon example

This commit is contained in:
Sasha Koshka 2023-07-01 11:20:51 -04:00
parent 41720caef5
commit dd0655ea3c

40
examples/icon/main.go Normal file
View File

@ -0,0 +1,40 @@
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,
Bounds: img.Rect,
Width: 4,
}
black := []uint8 { 0, 0, 0, 255 }
orange := []uint8 { 255, 48, 0, 255 }
midpoint := image.Pt(canvas.Bounds.Dx() / 2, canvas.Bounds.Dy() / 2)
canvas.FillRectangle(orange, canvas.Bounds)
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.")
}