Skip to content

Instantly share code, notes, and snippets.

@peterhellberg
Created March 1, 2020 19:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterhellberg/ce85e6af3b57ab08de69c57119c258bf to your computer and use it in GitHub Desktop.
Save peterhellberg/ce85e6af3b57ab08de69c57119c258bf to your computer and use it in GitHub Desktop.
Cubic Bezier Curve using gfx
package main
import "github.com/peterhellberg/gfx"
var (
p = gfx.PaletteAmmo8
dst = gfx.NewImage(256, 256, p[1])
p0 = gfx.V(16, 192)
p1 = gfx.V(32, 8)
p2 = gfx.V(192, 244)
p3 = gfx.V(240, 128)
inc = 0.0009
)
func main() {
gfx.DrawLineBresenham(dst, p0, p1, p[0])
gfx.DrawLineBresenham(dst, p2, p3, p[0])
gfx.DrawCicleFast(dst, p0, 4, p[0])
gfx.DrawCicleFast(dst, p1, 4, p[0])
gfx.DrawCicleFast(dst, p2, 4, p[0])
gfx.DrawCicleFast(dst, p3, 4, p[0])
for i, v := range gfx.CubicBezierCurve(p0, p1, p2, p3, inc) {
gfx.SetVec(dst, v, p.At(float64(i)*inc))
}
gfx.SavePNG("/tmp/bezier.png", gfx.NewScaledImage(dst, 2))
}
@peterhellberg
Copy link
Author

Ammo8 Arne16 Ink PICO8
cubic-bezier-curve-Ammo8 cubic-bezier-curve-Arne16 cubic-bezier-curve-Ink cubic-bezier-curve-PICO8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment