diff --git a/environment.py b/environment.py index e48068b..6f84401 100644 --- a/environment.py +++ b/environment.py @@ -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) \ No newline at end of file + 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()