From e4b8074d09c401a236315eb1775c3c31109dd569 Mon Sep 17 00:00:00 2001 From: marstr Date: Tue, 3 Sep 2024 22:00:29 +0200 Subject: [PATCH] Corrected building tree render positions, should they be out of bounds --- layergen.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/layergen.py b/layergen.py index c24ab24..44aa8ae 100644 --- a/layergen.py +++ b/layergen.py @@ -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 -- 2.30.2