diff --git a/common/perlinnoise.go b/common/perlinnoise.go index f177f13..7ef7725 100644 --- a/common/perlinnoise.go +++ b/common/perlinnoise.go @@ -15,10 +15,12 @@ const ( perlinAmpFalloff = 0.5 ) +// PerlinNoise is a perline noise struct to generate perlin noise. type PerlinNoise struct { perlin []float64 } +// NewPerlinNoise returns a PerlinNoise object. func NewPerlinNoise() *PerlinNoise { perlin := &PerlinNoise{perlin: nil} perlin.perlin = make([]float64, perlinSize+1) @@ -29,14 +31,17 @@ func NewPerlinNoise() *PerlinNoise { return perlin } +// Noise1D returns a float noise number on one dimension. func (p *PerlinNoise) Noise1D(x float64) float64 { return p.noise(x, 0, 0) } +// Noise1D returns a float noise number on two dimensions. func (p *PerlinNoise) Noise2D(x, y float64) float64 { return p.noise(x, y, 0) } +// Noise1D returns a float noise number on three dimensions. func (p *PerlinNoise) Noise3D(x, y, z float64) float64 { return p.noise(x, y, z) } diff --git a/common/utils.go b/common/utils.go index 6be0ee9..ebe524e 100644 --- a/common/utils.go +++ b/common/utils.go @@ -10,6 +10,8 @@ type HSV struct { H, S, V int } +// ToRGB converts a HSV color mode to RGB mode +// mh, ms, mv are used to set the maximum number for HSV. func (hs HSV) ToRGB(mh, ms, mv int) color.RGBA { if hs.H > mh { hs.H = mh @@ -111,18 +113,22 @@ func ConvertPolarToPixel(r, theta, xaixs, yaixs float64, h, w int) (int, int) { return i, j } +// Distance returns the Euclidean distance between two point on 2D dimension. func Distance(x1, y1, x2, y2 float64) float64 { return math.Sqrt(math.Pow(x1-x2, 2.0) + math.Pow(y1-y2, 2.0)) } +// RandomRangeInt returns a integer number between min and max. func RandomRangeInt(min, max int) int { return rand.Intn(max-min) + min } +// RandomRangeFloat64 returns a float64 number between min and max. func RandomRangeFloat64(min, max float64) float64 { return min + rand.Float64()*(max-min) } +// RandomGaussian returns a gaussian random float64 number. func RandomGaussian(mean, std float64) float64 { return rand.NormFloat64()*std + mean }