Skip to content
Snippets Groups Projects
Commit b9b6c26f authored by Egli Adrian (IT-SCI-API-PFI)'s avatar Egli Adrian (IT-SCI-API-PFI)
Browse files

Rendering "nicified"

parent c31d45e5
No related branches found
No related tags found
No related merge requests found
......@@ -79,20 +79,18 @@ class PILGL(GraphicsLayer):
self.firstFrame = True
self.create_layers()
def build_background_map(self,dTargets):
def build_background_map(self, dTargets):
self.background_grid = np.zeros(shape=(self.width, self.height))
for x in range(self.width):
for y in range(self.height):
distance = int(np.floor(np.sqrt(self.width*2.0 + self.height)))
distance = int(np.floor(np.sqrt(self.width * 2.0 + self.height)))
for rc in dTargets:
r = rc[1]
c = rc[0]
d = int(np.floor(np.sqrt((x-r)**2 + (y-c)**2)))
distance = min(d,distance)
d = int(np.floor(np.sqrt((x - r) ** 2 + (y - c) ** 2)))
distance = min(d, distance)
self.background_grid[x][y] = distance
def rgb_s2i(self, sRGB):
""" convert a hex RGB string like 0091ea to 3-tuple of ints """
return tuple(int(sRGB[iRGB * 2:iRGB * 2 + 2], 16) for iRGB in [0, 1, 2])
......@@ -236,7 +234,6 @@ class PILSVG(PILGL):
self.lwAgents = []
self.agents_prev = []
self.loadBuildingSVGs()
self.loadScenerySVGs()
self.loadRailSVGs()
......@@ -273,12 +270,18 @@ class PILSVG(PILGL):
pil_img = Image.open(fIn)
return pil_img
def loadBuildingSVGs(self):
dBuildingFiles = [
"Buildings/Bank.svg",
"Buildings/Bar.svg",
"Buildings/Wohnhaus.svg",
"Buildings/Hochhaus.svg",
"Buildings/Hotel.svg",
"Buildings/Office.svg",
"Buildings/Polizei.svg",
"Buildings/Post.svg",
"Buildings/Supermarkt.svg",
"Buildings/Tankstelle.svg",
"Buildings/Fabrik_A.svg",
"Buildings/Fabrik_B.svg",
"Buildings/Fabrik_C.svg",
......@@ -288,18 +291,14 @@ class PILSVG(PILGL):
"Buildings/Fabrik_G.svg",
"Buildings/Fabrik_H.svg",
"Buildings/Fabrik_I.svg",
"Buildings/Hochhaus.svg",
"Buildings/Hotel.svg",
"Buildings/Office.svg",
"Buildings/Polizei.svg",
"Buildings/Post.svg",
"Buildings/Supermarkt.svg",
"Buildings/Tankstelle.svg",
"Buildings/Wohnhaus.svg"]
]
imgBg = self.pilFromSvgFile('svg', "Background_city.svg")
self.dBuildings = []
for sFile in dBuildingFiles:
img = self.pilFromSvgFile('svg',sFile)
img = self.pilFromSvgFile('svg', sFile)
img = Image.alpha_composite(imgBg, img)
self.dBuildings.append(img)
def loadScenerySVGs(self):
......@@ -316,16 +315,20 @@ class PILSVG(PILGL):
"Scenery/Bergwelt_A_Teil_2_mitte.svg",
"Scenery/Bergwelt_A_Teil_3_rechts.svg",
]
imgBg = self.pilFromSvgFile('svg', "Background_Light_green.svg")
self.dScenery = []
for sFile in dSceneryFiles:
img = self.pilFromSvgFile('svg',sFile)
img = self.pilFromSvgFile('svg', sFile)
img = Image.alpha_composite(imgBg, img)
self.dScenery.append(img)
def loadRailSVGs(self):
""" Load the rail SVG images, apply rotations, and store as PIL images.
"""
dRailFiles = {
"": "Background_#91D1DD.svg",
"": "Background_Light_green.svg",
"WE": "Gleis_Deadend.svg",
"WW EE NN SS": "Gleis_Diamond_Crossing.svg",
"WW EE": "Gleis_horizontal.svg",
......@@ -355,16 +358,18 @@ class PILSVG(PILGL):
"NN SS": "Bahnhof_#d50000_Gleis_vertikal.svg"}
# Dict of rail cell images indexed by binary transitions
self.dPilRail = self.loadSVGs(dRailFiles, rotate=True)
self.dPilRail = self.loadSVGs(dRailFiles, rotate=True, backgroundImage="Background_rail.svg",
whitefilter="Background_white_filter.svg")
# Load the target files (which have rails and transitions of their own)
# They are indexed by (binTrans, iAgent), ie a tuple of the binary transition and the agent index
dPilRail2 = self.loadSVGs(dTargetFiles, rotate=False, agent_colors=self.ltAgentColors)
dPilRail2 = self.loadSVGs(dTargetFiles, rotate=False, agent_colors=self.ltAgentColors, backgroundImage="Background_rail.svg",
whitefilter="Background_white_filter.svg")
# Merge them with the regular rails.
# https://stackoverflow.com/questions/38987/how-to-merge-two-dictionaries-in-a-single-expression
self.dPilRail = {**self.dPilRail, **dPilRail2}
def loadSVGs(self, dDirFile, rotate=False, agent_colors=False):
def loadSVGs(self, dDirFile, rotate=False, agent_colors=False, backgroundImage=None, whitefilter=None):
dPil = {}
transitions = RailEnvTransitions()
......@@ -387,6 +392,14 @@ class PILSVG(PILGL):
pilRail = self.pilFromSvgFile('svg', sFile)
if backgroundImage is not None:
imgBg = self.pilFromSvgFile('svg', backgroundImage)
pilRail = Image.alpha_composite(imgBg, pilRail)
if whitefilter is not None:
imgBg = self.pilFromSvgFile('svg', whitefilter)
pilRail = Image.alpha_composite(pilRail, imgBg)
if rotate:
# For rotations, we also store the base image
dPil[binTrans] = pilRail
......@@ -412,13 +425,13 @@ class PILSVG(PILGL):
if binTrans in self.dPilRail:
pilTrack = self.dPilRail[binTrans]
if binTrans == 0 :
if binTrans == 0:
if self.background_grid[col][row] < 4:
a = int(self.background_grid[col][row])
a = a % len(self.dBuildings)
pilTrack = self.dBuildings[a]
else:
a = int(self.background_grid[col][row]) - 4
elif self.background_grid[col][row] > 5:
a = int(self.background_grid[col][row]) - 5
a = a % len(self.dScenery)
pilTrack = self.dScenery[a]
......
......@@ -100,7 +100,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "2460d8e561a3407d8fe2a6f28773bc04",
"model_id": "d97b62cfb71442548d19f76225810450",
"version_major": 2,
"version_minor": 0
},
......
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Generator: Adobe Illustrator 23.0.3, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
version="1.1"
id="Ebene_1"
x="0px"
y="0px"
viewBox="0 0 240 240"
style="enable-background:new 0 0 240 240;"
xml:space="preserve"
sodipodi:docname="Background_#DEBDA0 - Kopie.svg"
inkscape:version="0.92.4 (5da689c313, 2019-01-14)"><metadata
id="metadata11"><rdf:RDF><cc:Work
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage"/></cc:Work></rdf:RDF></metadata>
<defs
id="defs9"/>
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1920"
inkscape:window-height="1137"
id="namedview7"
showgrid="false"
inkscape:zoom="0.98333333"
inkscape:cx="120"
inkscape:cy="120"
inkscape:window-x="-8"
inkscape:window-y="-8"
inkscape:window-maximized="1"
inkscape:current-layer="Ebene_1"/>
<style
type="text/css"
id="style2">
.st0{fill:#DEBDA0;}
</style>
<rect
style="fill:#eef4d7"
id="rect13"
width="242.03391"
height="238.98306"
x="3.2327943e-08"
y="-1.1314779e-07"/></svg>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Generator: Adobe Illustrator 23.0.3, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
version="1.1"
id="Ebene_1"
x="0px"
y="0px"
viewBox="0 0 240 240"
style="enable-background:new 0 0 240 240;"
xml:space="preserve"
sodipodi:docname="Background_Light_gray.svg"
inkscape:version="0.92.4 (5da689c313, 2019-01-14)"><metadata
id="metadata11"><rdf:RDF><cc:Work
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage"/></cc:Work></rdf:RDF></metadata>
<defs
id="defs9"/>
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1920"
inkscape:window-height="1137"
id="namedview7"
showgrid="false"
inkscape:zoom="0.98333333"
inkscape:cx="-102.20339"
inkscape:cy="120"
inkscape:window-x="-8"
inkscape:window-y="-8"
inkscape:window-maximized="1"
inkscape:current-layer="Ebene_1"/>
<style
type="text/css"
id="style2">
.st0{fill:#DEBDA0;}
</style>
<rect
style="fill:#fdf7fa;fill-opacity:1"
id="rect13"
width="242.03391"
height="238.98306"
x="3.2327943e-08"
y="-1.1314779e-07"/></svg>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Generator: Adobe Illustrator 23.0.3, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
version="1.1"
id="Ebene_1"
x="0px"
y="0px"
viewBox="0 0 240 240"
style="enable-background:new 0 0 240 240;"
xml:space="preserve"
sodipodi:docname="Background_rail.svg"
inkscape:version="0.92.4 (5da689c313, 2019-01-14)"><metadata
id="metadata11"><rdf:RDF><cc:Work
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage"/></cc:Work></rdf:RDF></metadata>
<defs
id="defs9"/>
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1920"
inkscape:window-height="1137"
id="namedview7"
showgrid="false"
inkscape:zoom="0.98333333"
inkscape:cx="-362.54237"
inkscape:cy="120"
inkscape:window-x="-8"
inkscape:window-y="-8"
inkscape:window-maximized="1"
inkscape:current-layer="Ebene_1"/>
<style
type="text/css"
id="style2">
.st0{fill:#DEBDA0;}
</style>
<rect
style="fill:#fbf6f7;fill-opacity:1"
id="rect13"
width="242.03391"
height="238.98306"
x="3.2327943e-08"
y="-1.1314779e-07"/></svg>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Generator: Adobe Illustrator 23.0.3, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
version="1.1"
id="Ebene_1"
x="0px"
y="0px"
viewBox="0 0 240 240"
style="enable-background:new 0 0 240 240;"
xml:space="preserve"
sodipodi:docname="Background_white_filter.svg"
inkscape:version="0.92.4 (5da689c313, 2019-01-14)"><metadata
id="metadata11"><rdf:RDF><cc:Work
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage"/></cc:Work></rdf:RDF></metadata>
<defs
id="defs9"/>
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1920"
inkscape:window-height="1137"
id="namedview7"
showgrid="false"
inkscape:zoom="0.98333333"
inkscape:cx="-324.40678"
inkscape:cy="120"
inkscape:window-x="-8"
inkscape:window-y="-8"
inkscape:window-maximized="1"
inkscape:current-layer="Ebene_1"/>
<style
type="text/css"
id="style2">
.st0{fill:#DEBDA0;}
</style>
<rect
style="fill:#ffffff;fill-opacity:0.50196081"
id="rect13"
width="242.03391"
height="238.98306"
x="3.2327943e-08"
y="-1.1314779e-07"/></svg>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment