diff --git a/examples/glaggle/main.go b/examples/glaggle/main.go index b77f8dc..a2d63c8 100644 --- a/examples/glaggle/main.go +++ b/examples/glaggle/main.go @@ -1,7 +1,6 @@ package main import "os" -import "math" import "image" import "image/png" import "git.tebibyte.media/tomo/ggfx" @@ -18,16 +17,16 @@ func main () { yellow := []uint8 { 255, 255, 0, 255 } midpoint := image.Pt(canvas.Bounds.Dx() / 2, canvas.Bounds.Dy() / 2) - face := circle(32, 100, midpoint) + face := ggfx.Circle(32, 100, midpoint) canvas.FillPolygon(yellow, face...) canvas.StrokePolygon(black, 2, face...) - eye := circle(12, 16, midpoint.Add(image.Pt(-40, -30))) + eye := ggfx.Circle(12, 16, midpoint.Add(image.Pt(-40, -30))) canvas.FillPolygon(black, eye...) - eye = circle(12, 16, midpoint.Add(image.Pt(40, -30))) + eye = ggfx.Circle(12, 16, midpoint.Add(image.Pt(40, -30))) canvas.FillPolygon(black, eye...) - mouth := circle(16, 70, midpoint) + mouth := ggfx.Circle(16, 70, midpoint) canvas.StrokePolygon(black, 2, mouth[1:8]...) file, err := os.Create("TEST.png") @@ -38,15 +37,3 @@ func main () { println("Open TEST.png to see the result.") } - -func circle (resolution int, radius float64, center image.Point) []image.Point { - points := make([]image.Point, resolution) - for index := range points { - angle := float64(index) * ((2 * math.Pi) / float64(len(points))) - point := image.Pt ( - int(math.Cos(angle) * radius), - int(math.Sin(angle) * radius)) - points[index] = point.Add(center) - } - return points -} diff --git a/shapes.go b/shapes.go new file mode 100644 index 0000000..cd22974 --- /dev/null +++ b/shapes.go @@ -0,0 +1,16 @@ +package ggfx + +import "math" +import "image" + +func Circle (resolution int, radius float64, center image.Point) []image.Point { + points := make([]image.Point, resolution) + for index := range points { + angle := float64(index) * ((2 * math.Pi) / float64(len(points))) + point := image.Pt ( + int(math.Cos(angle) * radius), + int(math.Sin(angle) * radius)) + points[index] = point.Add(center) + } + return points +}