40 lines
1.0 KiB
Go
40 lines
1.0 KiB
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, 300, 300))
|
|
canvas := ggfx.Image[uint8] {
|
|
Pix: img.Pix,
|
|
Stride: img.Stride,
|
|
Rect: img.Rect,
|
|
Width: 4,
|
|
}
|
|
black := []uint8 { 0, 0, 0, 255 }
|
|
yellow := []uint8 { 255, 255, 0, 255 }
|
|
midpoint := image.Pt(canvas.Rect.Dx() / 2, canvas.Rect.Dy() / 2)
|
|
|
|
face := ggfx.Circle(32, 100, midpoint)
|
|
canvas.FillPolygon(yellow, face...)
|
|
canvas.StrokePolygon(black, 2, face...)
|
|
|
|
eye := ggfx.Circle(12, 16, midpoint.Add(image.Pt(-40, -30)))
|
|
canvas.FillPolygon(black, eye...)
|
|
eye = ggfx.Circle(12, 16, midpoint.Add(image.Pt(40, -30)))
|
|
canvas.FillPolygon(black, eye...)
|
|
|
|
mouth := ggfx.Circle(24, 70, midpoint)
|
|
canvas.PolyLine(black, 2, mouth[1:12]...)
|
|
|
|
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.")
|
|
}
|