Fixed trees spawning on road
This commit is contained in:
+9
-4
@@ -85,7 +85,7 @@ func DarkenLakeAreas(heightmap image.Image, lakePixels []image.Point) image.Imag
|
||||
return composite
|
||||
}
|
||||
|
||||
func GenerateTrees(img *image.RGBA, lakePixels []image.Point, minTreeSize, maxTreeSize, treeCoverage, treeClumpiness float64, seed int64) []image.Point {
|
||||
func GenerateTrees(img *image.RGBA, lakePixels, roadPixels []image.Point, minTreeSize, maxTreeSize, treeCoverage, treeClumpiness float64, seed int64) []image.Point {
|
||||
width := img.Bounds().Dx()
|
||||
height := img.Bounds().Dy()
|
||||
|
||||
@@ -124,6 +124,11 @@ func GenerateTrees(img *image.RGBA, lakePixels []image.Point, minTreeSize, maxTr
|
||||
isLake[p] = true
|
||||
}
|
||||
|
||||
isRoad := make(map[image.Point]bool)
|
||||
for _, p := range roadPixels {
|
||||
isRoad[p] = true
|
||||
}
|
||||
|
||||
randSrc := rand.New(rand.NewSource(seed))
|
||||
|
||||
// 3. Determine initial clump trees
|
||||
@@ -133,7 +138,7 @@ func GenerateTrees(img *image.RGBA, lakePixels []image.Point, minTreeSize, maxTr
|
||||
for range numClumpTrees {
|
||||
for range 100 { // try 100 times to find a valid spot
|
||||
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] && !isRoad[p] {
|
||||
initialPoints = append(initialPoints, p)
|
||||
break
|
||||
}
|
||||
@@ -143,7 +148,7 @@ func GenerateTrees(img *image.RGBA, lakePixels []image.Point, minTreeSize, maxTr
|
||||
// 4. Place remaining trees using Bridson's Algorithm
|
||||
minRadius := minTreeSize
|
||||
allPoints := poissonDiscSampling(width, height, minRadius, 30, initialPoints, func(p image.Point) bool {
|
||||
return treeNoiseMap.GrayAt(p.X, p.Y).Y >= threshold && !isLake[p]
|
||||
return treeNoiseMap.GrayAt(p.X, p.Y).Y >= threshold && !isLake[p] && !isRoad[p]
|
||||
}, seed)
|
||||
|
||||
var treePixels []image.Point
|
||||
@@ -158,7 +163,7 @@ func GenerateTrees(img *image.RGBA, lakePixels []image.Point, minTreeSize, maxTr
|
||||
for y := p.Y - int(r); y <= p.Y+int(r); y++ {
|
||||
for x := p.X - int(r); x <= p.X+int(r); x++ {
|
||||
pt := image.Point{X: x, Y: y}
|
||||
if !pt.In(img.Bounds()) || isLake[pt] {
|
||||
if !pt.In(img.Bounds()) || isLake[pt] || isRoad[pt] {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user