Skip to content

Instantly share code, notes, and snippets.

@eihigh
Last active April 1, 2024 07:59
Show Gist options
  • Save eihigh/e9f238ea652408fb71b43c0895c6083d to your computer and use it in GitHub Desktop.
Save eihigh/e9f238ea652408fb71b43c0895c6083d to your computer and use it in GitHub Desktop.
Experimental 2D Graphics API
package main
import "g2d"
func main() {
buf := g2d.Upload(g2d.Uniform(g2d.Transparent, g2d.Vec2{64, 64}))
tex := g2d.Upload(someImg)
buf.Draw(tex, g2d.Shifts(16, 16).Rotate(g2d.Tau/9))
d := g2d.Drawer{Dst: buf, Sampler: g2d.Linear, Frag: g2d.BlendAdd}
d.Draw(tex, g2d.Circle, g2d.Scales(40, 40))
p := g2d.Path().LineTo(pos).QuadTo(pos2)
buf.Draw(g2d.Brush, p.Stroke(g2d.StrokeStyle), g2d.Colorize(cyan))
pixels := make(g2d.Pixels, 0, 64*64)
pixels = buf.Download(pixels)
png.Encode(f, pixels)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment