From dd0655ea3c5089fb2410923b408e3579d79f47d7 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Sat, 1 Jul 2023 11:20:51 -0400 Subject: [PATCH] Add icon example --- examples/icon/main.go | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 examples/icon/main.go diff --git a/examples/icon/main.go b/examples/icon/main.go new file mode 100644 index 0000000..69df3bd --- /dev/null +++ b/examples/icon/main.go @@ -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.") +}