def _add_measurement(self, length, angle, added_time):
"""
Adds a visualization for a measured distance to the scene
:param length: length in cm
:param angle: the angle
"""
mx, my = self._get_middle()
angle_rad = deg2rad(angle)
ex, ey = mx + length * math.cos(angle_rad), my + length * math.sin(angle_rad)
age = time.time() - added_time
age = age if age < self.fade_out_time else self.fade_out_time
alpha_channel_value = scale((0, self.fade_out_time), (255, 0), age)
assert 0 <= alpha_channel_value <= 255
brush_color = QColor(self.measured_distances_color)
brush_color.setAlpha(alpha_channel_value)
brush = QBrush(brush_color)
tpen = QPen(brush_color)
self.scene.addLine(mx, my, ex, ey, pen=tpen)
self.scene.addEllipse(ex-self.dot_width/2, ey-self.dot_width/2, self.dot_width, self.dot_width, pen=tpen, brush=brush)
评论列表
文章目录