add comment

This commit is contained in:
Yongwei Xing 2021-03-16 16:10:50 +08:00
parent 92a6bb7672
commit 64cce3faa5
2 changed files with 11 additions and 0 deletions

View file

@ -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)
}

View file

@ -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
}