def _get_current_displayed_thickness(self): t = self.get_elapsed_time() factor = 1.0 + 0.3 * math.sin(t * 25.0) bound = clamp( (self.setup_duration + self.beam_duration + self.teardown_duration - t) / self.teardown_duration, 0.0, 1.0, ) return int(round(self.displayed_thickness * factor * bound))
def draw(self, destination): if self.is_in_setup_phase(): k = self.get_setup_phase_completion_percentage() brightness = int(clamp(256 * k, 0.0, 256 - 1e-9)) color = (brightness, ) * 3 pg.draw.circle(destination, color, self.start.ints(), 5) pg.draw.circle(destination, color, self.end.ints(), 5) else: pg.draw.circle(destination, (255, 255, 255), self.start.ints(), 5) pg.draw.circle(destination, (255, 255, 255), self.end.ints(), 5) thickness = self._get_current_displayed_thickness() pg.draw.line( destination, (255, 255, 255), self.start.ints(), self.end.ints(), thickness, )
def get_setup_phase_completion_percentage(self): return clamp(self.get_elapsed_time() / self.setup_duration, 0.0, 1.0)
def move(self, dx: int, dy: int): self.row = clamp(self.row + dy, 0, self.rows - 1) self.col = clamp(self.col + dx, 0, self.cols - 1) self.movement_state.move_to(self.get_coords_at(self.row, self.col))
def get_current_coords(self) -> Vector: k = clamp(self.elapsed_time / self.movement_length, 0.0, 1.0) return self.old_coords.interpolated(self.new_coords, k, self.mapping)
def calculate_alpha_coefficient(self, elapsed_time: float) -> float: return clamp(elapsed_time / self.length, 0.0, 1.0)