Based on article: http://devmag.org.za/2009/05/03/poisson-disk-sampling/
package main
import (
"os"
"image"
"image/draw"
"image/color"
"image/png"
"github.com/plandem/poisson-disk-sampling"
)
func main() {
width, height, numPoints := 1024, 1024, 1000
//generate poisson disk samplings
points := poisson.NewPoissonDisk(numPoints)
//draw result
img := image.NewRGBA(image.Rect(0, 0, width, height))
draw.Draw(img, img.Bounds(), &image.Uniform{color.Black}, image.ZP, draw.Src)
for _, point := range points {
x := int(point.X * float64(width))
y := int(point.Y * float64(height))
img.Set(x, y, color.White)
}
//save result png
f, _ := os.OpenFile("output.png", os.O_WRONLY|os.O_CREATE, 0600)
defer f.Close()
png.Encode(f, img)
}
Get more examples at example_test.go