def next_color(self): self.start_time, self.start_color, _ = ( self.day_colors[self.target_color_index]) self.target_color_index = ((self.target_color_index + 1) % len(self.day_colors)) self.target_time, self.target_color, self.hsv_transition = ( self.day_colors[self.target_color_index]) if not self.hsv_transition: self.start_color = hsb_to_rgb(*self.start_color) self.target_color = hsb_to_rgb(*self.target_color)
def update_day_color(self): if self.current_time >= 24.00: self.current_time = wrap(0.00, 24.00, self.current_time) while (self.current_time < self.start_time or self.current_time >= self.target_time): self.next_color() self.target_time = self.target_time or 24.00 t = ((self.current_time - self.start_time) / (self.target_time - self.start_time)) if self.hsv_transition: new_color = interpolate_hsb(self.start_color, self.target_color, t) new_color = hsb_to_rgb(*new_color) else: new_color = interpolate_rgb(self.start_color, self.target_color, t) if (self.current_color is None or rgb_distance(self.current_color, new_color) > 3): self.current_color = new_color self.set_fog_color(self.current_color) self.current_time += self.time_step * self.time_multiplier
def test_hsb_to_rgb(self): self.assertEqual(color.hsb_to_rgb(0.5, 0.4, 0.3), (45, 76, 76)) self.assertEqual(color.hsb_to_rgb(0.1, 0.2, 0.3), (76, 70, 61))