modernized old syntax
This commit is contained in:
+12
-15
@@ -26,14 +26,14 @@ func GenerateHeightmap(width, height, octaves int, scale float64, seed int64) im
|
|||||||
scale = 100.0
|
scale = 100.0
|
||||||
}
|
}
|
||||||
|
|
||||||
for x := 0; x < width; x++ {
|
for x := range width {
|
||||||
for y := 0; y < height; y++ {
|
for y := range height {
|
||||||
var noise float64
|
var noise float64
|
||||||
frequency := 1.0
|
frequency := 1.0
|
||||||
amplitude := 1.0
|
amplitude := 1.0
|
||||||
maxAmplitude := 0.0
|
maxAmplitude := 0.0
|
||||||
|
|
||||||
for i := 0; i < octaves; i++ {
|
for range octaves {
|
||||||
noise += p.Noise2D(float64(x)*frequency/scale, float64(y)*frequency/scale) * amplitude
|
noise += p.Noise2D(float64(x)*frequency/scale, float64(y)*frequency/scale) * amplitude
|
||||||
maxAmplitude += amplitude
|
maxAmplitude += amplitude
|
||||||
amplitude /= 2.0
|
amplitude /= 2.0
|
||||||
@@ -110,8 +110,8 @@ func GenerateTrees(img *image.RGBA, lakePixels []image.Point, minTreeSize, maxTr
|
|||||||
noise := opensimplex.New(seed)
|
noise := opensimplex.New(seed)
|
||||||
treeNoiseMap := image.NewGray(image.Rect(0, 0, width, height))
|
treeNoiseMap := image.NewGray(image.Rect(0, 0, width, height))
|
||||||
treeNoiseZoom := 0.05
|
treeNoiseZoom := 0.05
|
||||||
for y := 0; y < height; y++ {
|
for y := range height {
|
||||||
for x := 0; x < width; x++ {
|
for x := range width {
|
||||||
val := noise.Eval2(float64(x)*treeNoiseZoom, float64(y)*treeNoiseZoom)
|
val := noise.Eval2(float64(x)*treeNoiseZoom, float64(y)*treeNoiseZoom)
|
||||||
val = (val + 1) / 2 // Normalize to 0-1
|
val = (val + 1) / 2 // Normalize to 0-1
|
||||||
treeNoiseMap.SetGray(x, y, color.Gray{Y: uint8(val * 255)})
|
treeNoiseMap.SetGray(x, y, color.Gray{Y: uint8(val * 255)})
|
||||||
@@ -127,14 +127,11 @@ func GenerateTrees(img *image.RGBA, lakePixels []image.Point, minTreeSize, maxTr
|
|||||||
randSrc := rand.New(rand.NewSource(seed))
|
randSrc := rand.New(rand.NewSource(seed))
|
||||||
|
|
||||||
// 3. Determine initial clump trees
|
// 3. Determine initial clump trees
|
||||||
numClumpTrees := int(treeClumpiness)
|
numClumpTrees := min(int(treeClumpiness), numTreesToPlace)
|
||||||
if numClumpTrees > numTreesToPlace {
|
|
||||||
numClumpTrees = numTreesToPlace
|
|
||||||
}
|
|
||||||
|
|
||||||
initialPoints := make([]image.Point, 0, numClumpTrees)
|
initialPoints := make([]image.Point, 0, numClumpTrees)
|
||||||
for i := 0; i < numClumpTrees; i++ {
|
for range numClumpTrees {
|
||||||
for j := 0; j < 100; j++ { // try 100 times to find a valid spot
|
for range 100 { // try 100 times to find a valid spot
|
||||||
p := image.Point{X: randSrc.Intn(width), Y: randSrc.Intn(height)}
|
p := image.Point{X: randSrc.Intn(width), Y: randSrc.Intn(height)}
|
||||||
if treeNoiseMap.GrayAt(p.X, p.Y).Y >= threshold && !isLake[p] {
|
if treeNoiseMap.GrayAt(p.X, p.Y).Y >= threshold && !isLake[p] {
|
||||||
initialPoints = append(initialPoints, p)
|
initialPoints = append(initialPoints, p)
|
||||||
@@ -196,7 +193,7 @@ func poissonDiscSampling(width, height int, minRadius float64, k int, initialPoi
|
|||||||
listIndex := randSrc.Intn(len(activeList))
|
listIndex := randSrc.Intn(len(activeList))
|
||||||
p := activeList[listIndex]
|
p := activeList[listIndex]
|
||||||
found := false
|
found := false
|
||||||
for i := 0; i < k; i++ {
|
for range k {
|
||||||
angle := randSrc.Float64() * 2 * math.Pi
|
angle := randSrc.Float64() * 2 * math.Pi
|
||||||
radius := minRadius + randSrc.Float64()*minRadius
|
radius := minRadius + randSrc.Float64()*minRadius
|
||||||
x, y := float64(p.X)+radius*math.Cos(angle), float64(p.Y)+radius*math.Sin(angle)
|
x, y := float64(p.X)+radius*math.Cos(angle), float64(p.Y)+radius*math.Sin(angle)
|
||||||
@@ -247,7 +244,7 @@ func bresenham(path []image.Point) []image.Point {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var fullPath []image.Point
|
var fullPath []image.Point
|
||||||
for i := 0; i < len(path)-1; i++ {
|
for i := range len(path) - 1 {
|
||||||
p1, p2 := path[i], path[i+1]
|
p1, p2 := path[i], path[i+1]
|
||||||
dx, dy := p2.X-p1.X, p2.Y-p1.Y
|
dx, dy := p2.X-p1.X, p2.Y-p1.Y
|
||||||
absDx, absDy := int(math.Abs(float64(dx))), int(math.Abs(float64(dy)))
|
absDx, absDy := int(math.Abs(float64(dx))), int(math.Abs(float64(dy)))
|
||||||
@@ -321,7 +318,7 @@ func calculatePath(start, end image.Point, curvyness, avgDim float64, randSrc *r
|
|||||||
|
|
||||||
baseNumWaves := (dist / mainWavelength) * curvyness
|
baseNumWaves := (dist / mainWavelength) * curvyness
|
||||||
|
|
||||||
for i := 0; i < 3; i++ {
|
for i := range 3 {
|
||||||
|
|
||||||
freqMultiplier := 1.0 + float64(i)
|
freqMultiplier := 1.0 + float64(i)
|
||||||
|
|
||||||
@@ -342,7 +339,7 @@ func calculatePath(start, end image.Point, curvyness, avgDim float64, randSrc *r
|
|||||||
|
|
||||||
controlPoints := make([]image.Point, numControlPoints+1)
|
controlPoints := make([]image.Point, numControlPoints+1)
|
||||||
|
|
||||||
for i := 0; i <= numControlPoints; i++ {
|
for i := range numControlPoints + 1 {
|
||||||
|
|
||||||
t := float64(i) / float64(numControlPoints)
|
t := float64(i) / float64(numControlPoints)
|
||||||
|
|
||||||
|
|||||||
@@ -28,13 +28,13 @@ func (pq priorityQueue) Swap(i, j int) {
|
|||||||
pq[i].index = i
|
pq[i].index = i
|
||||||
pq[j].index = j
|
pq[j].index = j
|
||||||
}
|
}
|
||||||
func (pq *priorityQueue) Push(x interface{}) {
|
func (pq *priorityQueue) Push(x any) {
|
||||||
n := len(*pq)
|
n := len(*pq)
|
||||||
item := x.(*lakePixel)
|
item := x.(*lakePixel)
|
||||||
item.index = n
|
item.index = n
|
||||||
*pq = append(*pq, item)
|
*pq = append(*pq, item)
|
||||||
}
|
}
|
||||||
func (pq *priorityQueue) Pop() interface{} {
|
func (pq *priorityQueue) Pop() any {
|
||||||
old := *pq
|
old := *pq
|
||||||
n := len(old)
|
n := len(old)
|
||||||
item := old[n-1]
|
item := old[n-1]
|
||||||
@@ -79,7 +79,7 @@ func GenerateLakes(width, height, numLakes int, lakeSizeLower, lakeSizeUpper flo
|
|||||||
noiseGen := opensimplex.New(seed)
|
noiseGen := opensimplex.New(seed)
|
||||||
|
|
||||||
// 3. Generate a lake in a subset of the chunks
|
// 3. Generate a lake in a subset of the chunks
|
||||||
for i := 0; i < numLakes; i++ {
|
for i := range numLakes {
|
||||||
if i >= len(chunkIndices) {
|
if i >= len(chunkIndices) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -209,7 +209,7 @@ func GenerateRivers(width, height, numRivers int, minWidth, maxWidth, curvyness
|
|||||||
}
|
}
|
||||||
|
|
||||||
rivers := make([]River, numRivers)
|
rivers := make([]River, numRivers)
|
||||||
for i := 0; i < numRivers; i++ {
|
for i := range numRivers {
|
||||||
widthPercent := float64(i) / float64(numRivers-1)
|
widthPercent := float64(i) / float64(numRivers-1)
|
||||||
if numRivers == 1 {
|
if numRivers == 1 {
|
||||||
widthPercent = 0.5
|
widthPercent = 0.5
|
||||||
@@ -221,10 +221,7 @@ func GenerateRivers(width, height, numRivers int, minWidth, maxWidth, curvyness
|
|||||||
return rivers[i].Width > rivers[j].Width
|
return rivers[i].Width > rivers[j].Width
|
||||||
})
|
})
|
||||||
|
|
||||||
numControlPoints := int(avgDim * 0.03)
|
numControlPoints := max(int(avgDim*0.03), 60)
|
||||||
if numControlPoints < 60 {
|
|
||||||
numControlPoints = 60
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := range rivers {
|
for i := range rivers {
|
||||||
r := &rivers[i]
|
r := &rivers[i]
|
||||||
|
|||||||
Reference in New Issue
Block a user