Corrected building tree render positions, should they be out of bounds
This commit is contained in:
parent
a1483fccc3
commit
e4b8074d09
20
layergen.py
20
layergen.py
@ -326,16 +326,20 @@ class mstr_layergen:
|
|||||||
for x in range(0, osm_mask.width, int(osm_mask.width/200)):
|
for x in range(0, osm_mask.width, int(osm_mask.width/200)):
|
||||||
px = epx[x,y]
|
px = epx[x,y]
|
||||||
if px[3] == 255:
|
if px[3] == 255:
|
||||||
rx = randrange(30,60)
|
rx = randrange(24,60)
|
||||||
ry = randrange(30,60)
|
ry = randrange(24,60)
|
||||||
f = randrange(1,10)
|
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
|
# Do some magic - but not on edges
|
||||||
if x > 0 and x < osm_mask.width and y > 0 and y < osm_mask.height:
|
if x > 0 and x < osm_mask.width and y > 0 and y < osm_mask.height:
|
||||||
if f != 5:
|
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:
|
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
|
# We need to change the image in certain conditions
|
||||||
@ -673,13 +677,17 @@ class mstr_layergen:
|
|||||||
shf_y = randrange(y-11, y+11)
|
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:
|
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
|
# Pick a number of trees to place
|
||||||
numtrees = randrange(1, 5)
|
numtrees = randrange(1, 6)
|
||||||
for i in range(1, numtrees):
|
for i in range(1, numtrees):
|
||||||
# Pick some file
|
# Pick some file
|
||||||
pick = str(randrange(1, 11))
|
pick = str(randrange(1, 11))
|
||||||
tree = Image.open(mstr_datafolder + "Textures/building/area/p" + pick + ".png")
|
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))
|
trees.alpha_composite(tree, (shf_x, shf_y))
|
||||||
#layer_comp.paste(tree, (shf_x, shf_y))
|
|
||||||
trees.alpha_composite(layer_comp)
|
trees.alpha_composite(layer_comp)
|
||||||
layer_comp = trees
|
layer_comp = trees
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user