Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 33 additions & 44 deletions environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,37 @@

import numpy as np

def build_hospital(xmin, xmax, ymin, ymax, plt, addcross=True):
'''builds hospital

Defines hospital and returns wall coordinates for
the hospital, as well as coordinates for a red cross
above it

Keyword arguments
-----------------
xmin : int or float
lower boundary on the x axis

xmax : int or float
upper boundary on the x axis

ymin : int or float
lower boundary on the y axis

ymax : int or float
upper boundary on the y axis

plt : matplotlib.pyplot object
the plot object to which to append the hospital drawing
if None, coordinates are returned

Returns
-------
None
'''

#plot walls
plt.plot([xmin, xmin], [ymin, ymax], color = 'black')
plt.plot([xmax, xmax], [ymin, ymax], color = 'black')
plt.plot([xmin, xmax], [ymin, ymin], color = 'black')
plt.plot([xmin, xmax], [ymax, ymax], color = 'black')
class environment:
def __init__(self, xmin, xmax, ymin, ymax, plt, addcross=True):
self.xmin = xmin
self.xmax = xmax
self.ymin = ymin
self.ymax = ymax
self.plt = plt
self.addcross = addcross

#plot red cross
if addcross:
xmiddle = xmin + ((xmax - xmin) / 2)
height = np.min([0.3, (ymax - ymin) / 5])
plt.plot([xmiddle, xmiddle], [ymax, ymax + height], color='red',
linewidth = 3)
plt.plot([xmiddle - (height / 2), xmiddle + (height / 2)],
[ymax + (height / 2), ymax + (height / 2)], color='red',
linewidth = 3)
def build_hospital(self):
# plot walls
self.plt.plot([self.xmin, self.xmin], [self.ymin, self.ymax], color='black')
self.plt.plot([self.xmax, self.xmax], [self.ymin, self.ymax], color='black')
self.plt.plot([self.xmin, self.xmax], [self.ymin, self.ymin], color='black')
self.plt.plot([self.xmin, self.xmax], [self.ymax, self.ymax], color='black')

# plot red cross
if self.addcross:
xmiddle = self.xmin + ((self.xmax - self.xmin) / 2)
height = np.min([0.3, (self.ymax - self.ymin) / 5])
self.plt.plot([xmiddle, xmiddle], [self.ymax, self.ymax + height], color='red',
linewidth=3)
self.plt.plot([xmiddle - (height / 2), xmiddle + (height / 2)],
[self.ymax + (height / 2), self.ymax + (height / 2)], color='red',
linewidth=3)

def set(self, xmin, xmax, ymin, ymax, plt, addcross):
self.xmin = xmin
self.xmax = xmax
self.ymin = ymin
self.ymax = ymax
self.plt = plt
self.addcross = addcross
build_hospital()