Circles - Maths317
To draw a circle knowing the radius (r) and the center of the circle at point
Loop through 360 and set the radius to the loops index, and use the formula above to get all the points of the circle.
Test Code
package main
import (
"github.com/disintegration/imaging"
"image/color"
"math"
)
func main() {
width := 500
height := 300
img := imaging.New(width, height, color.White)
radius := 50
for angle := 0; angle <= 360; angle++ {
angleInRadians := float64(angle) * (math.Pi / 180)
x := float64(radius) * math.Sin(angleInRadians)
y := float64(radius) * math.Cos(angleInRadians)
img.Set(width/2 + int(x), height/2 + int(y), color.Black)
}
err := imaging.Save(img, "out_circles1.png")
if err != nil {
panic(err)
}
}