]> marstr Code Repo - orthographic/commitdiff
Corrected building tree render positions, should they be out of bounds
authormarstr <marcus@marstr.online>
Tue, 3 Sep 2024 20:00:29 +0000 (22:00 +0200)
committermarstr <marcus@marstr.online>
Tue, 3 Sep 2024 20:16:21 +0000 (22:16 +0200)
layergen.py

index c24ab24170020f9b240021dd6790ee2319d9b62d..44aa8ae4ebf18d0475fc20de71da57de37b25496 100644 (file)
@@ -326,16 +326,20 @@ class mstr_layergen:
                     for x in range(0, osm_mask.width, int(osm_mask.width/200)):
                         px = epx[x,y]
                         if px[3] == 255:
-                            rx = randrange(30,60)
-                            ry = randrange(30,60)
+                            rx = randrange(24,60)
+                            ry = randrange(24,60)
                             f = randrange(1,10)
+
+                            # Randomize the found locations a little
+                            psx = randrange(x-11, x+11)
+                            psy = randrange(y-11, y+11)
                             
                             # Do some magic - but not on edges
                             if x > 0 and x < osm_mask.width and y > 0 and y < osm_mask.height:
                                 if f != 5:
-                                    imgd.ellipse((x-int(rx/2), y-int(ry/2), x+rx, y+ry), fill="black")
+                                    imgd.ellipse((psx-int(rx/2), psy-int(ry/2), psx+rx, psy+ry), fill="black")
                                 if f == 3 or f == 7:
-                                    imgd.ellipse((x-int(rx/2), y-int(ry/2), x+rx, y+ry), fill=(0,0,0,0))
+                                    imgd.ellipse((psx-int(rx/2), psy-int(ry/2), psx+rx, psy+ry), fill=(0,0,0,0))
 
 
             # We need to change the image in certain conditions
@@ -673,13 +677,17 @@ class mstr_layergen:
                                         shf_y = randrange(y-11, y+11)
                                         if shf_x > 0 and shf_x < self._imgsize and shf_y > 0 and shf_y < self._imgsize:
                                             # Pick a number of trees to place
-                                            numtrees = randrange(1, 5)
+                                            numtrees = randrange(1, 6)
                                             for i in range(1, numtrees):
                                                 # Pick some file
                                                 pick = str(randrange(1, 11))
                                                 tree = Image.open(mstr_datafolder + "Textures/building/area/p" + pick + ".png")
+                                                # Do a correction for the location if needed
+                                                if shf_x < 1: shf_x = 1
+                                                if shf_y < 1: shf_y = 1
+                                                if shf_x > self._imgsize - tree.width: shf_x = self._imgsize - tree.width - 1
+                                                if shf_y > self._imgsize - tree.height: shf_y = self._imgsize - tree.height - 1
                                                 trees.alpha_composite(tree, (shf_x, shf_y))
-                                                #layer_comp.paste(tree, (shf_x, shf_y))
                     trees.alpha_composite(layer_comp)
                     layer_comp = trees