diff --git a/torus.py b/torus.py index 581bee5..07d7134 100644 --- a/torus.py +++ b/torus.py @@ -97,10 +97,21 @@ class NoInamge(): self.levels = 25 # [-1, 0, 1] self.torus = TorusWorld(rfrac_init) + self.illumination = None + self.res = (50, 100) + + self.update_illumination() + self.init_top_view() self.init_side_view() self.init_map_view() + def update_illumination(self): + # TODO: refactor TorusWorld.illumination() do use vectoization!! + phi = np.linspace(-np.pi, np.pi, self.res[0]) + theta = np.linspace(-np.pi, np.pi, self.res[1]) + self.illumination = np.array([[self.torus.illumination(ph, th) for th in theta] for ph in phi]) + def init_map_view(self): self.lines['map_border'], = self.ax['map'].plot(*self._mantle_map(), 'k') self.lines['pos_map'], = self.ax['map'].plot(*self._sunpos_map(), marker='o', color='r', markersize=10,) @@ -142,16 +153,14 @@ class NoInamge(): data = np.append(data, data[:, 0:1], axis=1) return data - def _contour_map(self, n=100): - theta = np.linspace(-np.pi, np.pi, n) - phi = np.linspace(-np.pi, np.pi, int(n*self.torus.r_min)) - - y = np.array([[w]*n for w in self.torus.r_min*phi]) + def _contour_map(self): + phi = np.linspace(-np.pi, np.pi, self.res[0]) + y = np.array([[w]*self.res[1] for w in self.torus.r_min*phi]) func = (np.pi)*(self.torus.r_maj - self.torus.r_min*np.cos(phi)) - x = np.array([np.linspace(-f, f, n) for f in func]) + x = np.array([np.linspace(-f, f, self.res[1]) for f in func]) # x, y = np.meshgrid(np.linspace(-func[0], func[0], n), rmin*theta) - z = np.array([[self.torus.illumination(ph, th) for th in theta] for ph in phi]) + z = self.illumination return x, y, z @@ -226,6 +235,7 @@ class NoInamge(): def update_torus(self, rfrac): self.torus.update(rfrac) + self.update_illumination() self.redraw_plot(self.ax['map'], self.lines['map_border'], self._mantle_map) self.redraw_plot(self.ax['side'], self.lines['circles_side'], self._crossection) self.redraw_plot(self.ax['side'], self.lines['path_side'], self._sunpath_side) @@ -237,6 +247,7 @@ class NoInamge(): def update_sun(self, phi, theta): self.torus.put_sun(phi, theta) + self.update_illumination() self.redraw_plot(self.ax['map'], self.lines['pos_map'], self._sunpos_map) self.redraw_plot(self.ax['side'], self.lines['pos_side'], self._sunpos_side) self.redraw_plot(self.ax['top'], self.lines['pos_top'], self._sunpos_top)