package main import ( "image" "image/color" "image/png" "log" "os" "golang.org/x/image/math/f32" "golang.org/x/image/vector" ) type ctx struct { dst *image.RGBA ra *vector.Rasterizer } func (c *ctx) moveTo(x, y float32) { c.ra.MoveTo(f32.Vec2{x, y}) } func (c *ctx) lineTo(x, y float32) { c.ra.LineTo(f32.Vec2{x, y}) } func (c *ctx) draw(argb uint32) { src := image.NewUniform(color.NRGBA{ A: uint8((argb >> 24) & 0xff), R: uint8((argb >> 16) & 0xff), G: uint8((argb >> 8) & 0xff), B: uint8(argb & 0xff), }) c.ra.Draw(c.dst, c.dst.Bounds(), src, image.ZP) c.ra.Reset(c.dst.Bounds().Dx(), c.dst.Bounds().Dy()) } func (c *ctx) writePng(fn string) { file, err := os.Create(fn) if err != nil { log.Fatal(err) } defer file.Close() if err := png.Encode(file, c.dst); err != nil { log.Fatal(err) } } func main() { const w, h = 1280, 720 ctx := ctx{ dst: image.NewRGBA(image.Rect(0, 0, w, h)), ra: vector.NewRasterizer(w, h), } parse(&ctx) ctx.writePng("vector.png") }