/poisson-disk-sampling

Poisson Disk Sampling in Go

Primary LanguageGoMIT LicenseMIT

Poisson Disk Sampling

Build Status Go Report Card GoDoc License Donate

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

basic example

Basic Example

with minimum distance

Minimum Distance Example

with circle area filter

Circle Area Filter Example

with rectangle area filter

Rectangle Area Filter Example

with simplex noise post filter

Simplex Noise Post Filter Example

with PNG map post filter

PNG Map

PNG Post Filter Example

full featured example

Full Featured Example