def apply(self, time_percent): if (time_percent < self.previous_time): self.effects = [] if self.frame_counter % 4 == 0: self.create_bottom_animation() if self.frame_counter % 4 == 1: self.create_seeds_animation() if self.frame_counter % 4 == 2: self.create_last_animation() if self.frame_counter % 4 == 3: self.effects.append( AlwaysOnEffect(self.flower.bottom_parts, self.color)) self.effects.append( AlwaysOnEffect(self.flower.seeds, self.color)) self.effects.append( AlwaysOnEffect(self.flower.get_leaves(), self.color)) self.frame_counter += 1 for effect in self.effects: effect.apply(time_percent, self.flower.get_array()) self.previous_time = time_percent
def __init__(self, flower, props): FlowerAnimation.__init__(self, flower, props) self.effects = [] whole_flower = True leds_percent_per_beat = 0.4 brightness = 1.0 fade = 0.90 if self.props != None: if 'only_top' in self.props: whole_flower = not self.props['only_top'] if 'leds_percent_per_beat' in self.props: leds_percent_per_beat = self.props['leds_percent_per_beat'] if 'brightness' in self.props: brightness = self.props['brightness'] if 'fade' in self.props: fade = self.props['fade'] if whole_flower == True: self.effects.append( ConfettiEffect( self.flower.bottom_parts + self.flower.top_leaves, leds_percent_per_beat, brightness, fade)) self.effects.append(AlwaysOnEffect(self.flower.seeds, [0, 0, 0])) else: self.effects.append( ConfettiEffect(self.flower.top_leaves, leds_percent_per_beat, brightness, fade)) self.effects.append(AlwaysOnEffect(self.flower.line, [5, 50, 0])) self.effects.append(AlwaysOnEffect(self.flower.leaves, [0, 50, 0])) self.effects.append(AlwaysOnEffect(self.flower.seeds, [0, 0, 0]))
def create_bottom_animation(self): self.effects = [] hue = self.previous_hue + 0.1 + random.random() * 0.8 if hue > 1: hue -= 1 self.previous_hue = hue self.previous_color = self.color self.color = Colors.hls_to_rgb(hue, 1, 1) self.effects.append( AdvanceEffect.initColor(self.flower.line_back, self.previous_color, self.color)) self.effects.append( AdvanceEffect.initColor(self.flower.line_front, self.previous_color, self.color)) self.effects.append( AdvanceEffect.initColor(self.flower.leaf_right_front, self.previous_color, self.color)) self.effects.append( AdvanceEffect.initColor(self.flower.leaf_right_back, self.previous_color, self.color)) self.effects.append( AdvanceEffect.initColor(self.flower.leaf_left_front, self.previous_color, self.color)) self.effects.append( AdvanceEffect.initColor(self.flower.leaf_left_back, self.previous_color, self.color)) self.effects.append( AlwaysOnEffect(self.flower.seeds, self.previous_color)) self.effects.append( AlwaysOnEffect(self.flower.get_leaves(), self.previous_color))
def create_effects(self): self.effects = [] color1 = Colors.hls_to_rgb(self.hue1, 1, 1) color2 = Colors.hls_to_rgb(self.hue2, 1, 1) self.effects.append(AlternateColorEvery3Effect(self.sheep.body, color1, color2)) self.effects.append(AlwaysOnEffect(self.sheep.head + self.sheep.legs, color1)) self.effects.append(AlwaysOnEffect(self.sheep.eyes, color2))
def __init__(self, lake, props): LakeAnimation.__init__(self, lake, props) self.effects = [] self.brightness = 0.2 self.hue1 = 0.7 self.hue2 = 0.8 if self.props != None: if 'hue1' in self.props: self.hue1 = self.props['hue1'] if 'hue2' in self.props: self.hue2 = self.props['hue2'] if 'brightness' in self.props: self.brightness = self.props['brightness'] for i in range(0, len(self.lake.waves_arr)): w = self.lake.waves_arr[i] self.effects.append( EqEffect(w, brightness=self.brightness, hue1=self.hue1, hue2=self.hue2)) #the lake segments between the waves for i in range(1, len(self.lake.waves_arr)): high_start = self.lake.conn_arr[i][0] high_end = self.lake.conn_arr[i - 1][0] if high_start < high_end: high_indexes = range(high_start, high_end) else: high_indexes = range( high_start, self.lake.contour[-1]) + range(0, high_end) low_indexes = range(self.lake.conn_arr[i - 1][1], self.lake.conn_arr[i][1]) self.effects.append( AlwaysOnEffect( high_indexes, Colors.hls_to_rgb(self.hue1, 1.0, self.brightness))) self.effects.append( AlwaysOnEffect( low_indexes, Colors.hls_to_rgb(self.hue2, 1.0, self.brightness))) #make nice transitions in the corners self.effects.append( GradientEffect( range(self.lake.conn_arr[0][0], self.lake.conn_arr[0][1]), Colors.hls_to_rgb(self.hue1, 1.0, self.brightness), Colors.hls_to_rgb(self.hue2, 1.0, self.brightness))) self.effects.append( GradientEffect( range(self.lake.conn_arr[12][1], self.lake.conn_arr[12][0]), Colors.hls_to_rgb(self.hue2, 1.0, self.brightness), Colors.hls_to_rgb(self.hue1, 1.0, self.brightness)))
def create_seeds_animation(self): self.effects = [] self.effects.append( GoToColorEffect(self.flower.seeds, self.previous_color, self.color)) self.effects.append( AlwaysOnEffect(self.flower.bottom_parts, self.color)) self.effects.append( AlwaysOnEffect(self.flower.get_leaves(), self.previous_color))
def next_hue(self): self.effects = [] new_hue = self.hue + self.hue_speed if new_hue > 1 : new_hue -= 1 prev_color = Colors.hls_to_rgb(self.hue, 1.0, 1.0) new_color = Colors.hls_to_rgb(new_hue, 1.0, 1.0) self.effects.append(GoToColorEffect(self.flower.get_leaves() + self.flower.seeds, prev_color, new_color)) self.hue = new_hue self.effects.append(AlwaysOnEffect(self.flower.line, [50, 200, 0])) self.effects.append(AlwaysOnEffect(self.flower.leaves, [0, 200, 0]))
def create_effects(self): bodyEffect = AlternateColorEvery3Effect(self.sheep.get_body_indexes(),self.current_color1,self.current_color2) #leg12Effect = AlternateColor2ArraysEffect(self.sheep.get_leg12_side1_indexes(),self.sheep.get_leg12_side2_indexes() ,self.current_color1,self.current_color2) #leg34Effect = AlternateColor2ArraysEffect(self.sheep.get_leg34_side1_indexes(),self.sheep.get_leg34_side2_indexes() ,self.current_color1,self.current_color2) legsEffect1 = AlwaysOnEffect(self.sheep.get_leg12_side1_indexes() + self.sheep.get_leg34_side1_indexes(), self.current_color2) legsEffect2 = AlwaysOnEffect(self.sheep.get_leg12_side2_indexes() + self.sheep.get_leg34_side2_indexes(), self.current_color1) headEffect = AlwaysOnEffect(self.sheep.get_head_indexes(),self.current_color1) earsEffect1 = AdvanceEffect.initColor(self.sheep.get_inner_ear_indexes()[::-1], self.current_color2, self.current_color1) earsEffect2 = AdvanceEffect.initColor(self.sheep.get_outer_ear_indexes()[::-1], self.current_color2, self.current_color1) self.effects = [bodyEffect, legsEffect1, legsEffect2, headEffect, earsEffect1, earsEffect2]
def _start_spike(self): self.effects = [] self.last_hue += self.hue_speed if self.last_hue > 1: self.last_hue -= 1 rand_color = Colors.hls_to_rgb(self.last_hue, 1.0, 1.0) self.effects.append(AlwaysOnEffect(self.lake.waves_arr[self.last_wave], rand_color)) contour_color = Colors.hls_to_rgb(self.last_hue, 0.5, 0.7) self.effects.append(AlwaysOnEffect(self.lake.contour, contour_color)) self.last_wave += 1 if self.last_wave >= len(self.lake.waves_arr): self.last_wave = 0
def __init__(self, lake, props): LakeAnimation.__init__(self, lake, props) self.effects = [] self.previous_time = 1 self.hue = 0.67 if self.props != None: if 'hue_start' in self.props: self.hue = self.props['hue_start'] self.base_effect = AlwaysOnEffect(self.lake.whole_lake, Colors.hls_to_rgb(self.hue, 1, 1)) self.start_times = [] self.speeds = [] self.create_effects()
def create_last_animation(self): self.effects = [] for leaf in self.flower.get_leaves_array(): leaf_1 = leaf[:len(leaf) / 2] leaf_2 = leaf[len(leaf) / 2:][::-1] self.effects.append( AdvanceEffect.initColor(leaf_1, self.previous_color, self.color)) self.effects.append( AdvanceEffect.initColor(leaf_2, self.previous_color, self.color)) self.effects.append( AlwaysOnEffect(self.flower.bottom_parts, self.color)) self.effects.append(AlwaysOnEffect(self.flower.seeds, self.color))
def _restart(self): self.effects = [] self.effects.append(AlwaysOnEffect(self.tree.get_stem(), [133, 87, 35])) self.last_hue += self.hue_speed if self.last_hue > 1: self.last_hue -= 1 rand_color = Colors.hls_to_rgb(self.last_hue, 1.0, 1.0) arr = self.tree.get_leaves_array() self.effects.append(AlwaysOnEffect(arr[self.last_leaf][0], rand_color)) self.effects.append(AlwaysOnEffect(arr[self.last_leaf][1], rand_color)) self.last_leaf += 1 if self.last_leaf >= len(arr): self.last_leaf = 0
def apply(self, time_percent): spin = int(math.floor(time_percent * self.num_of_spins)) if (spin != self.current_spin): self.current_spin = spin on = [] for i in range(self.num_of_lights): on.append(random.randrange(len(self.elements))) self.effects = [] for i in range(len(self.elements)): hue = self.hues[i] color = [ int(c * 255) for c in colorsys.hsv_to_rgb(hue, 1.0, 0.03) ] self.effects.append(AlwaysOnEffect(self.elements[i], color)) for i in range(len(on)): hue = self.hues[on[i]] color = [ int(c * 255) for c in colorsys.hsv_to_rgb(hue, 1.0, 0.35) ] to_color = [ int(c * 255) for c in colorsys.hsv_to_rgb(hue, 1.0, 0.03) ] self.effects.append( FadeOutEffect.initLimit(self.elements[on[i]], color, to_color, 1)) oneSpinTime = 1.0 / float(self.num_of_spins) relativePercent = (time_percent - oneSpinTime * self.current_spin) * self.num_of_spins for effect in self.effects: effect.apply(relativePercent, self.sheep.get_array())
def apply(self, time_percent): spin = int(math.floor(time_percent * self.num_of_spins)) if (spin != self.current_spin): self.current_spin = spin oneSpinTime = 1.0 / self.num_of_spins relativePercent = (time_percent - oneSpinTime * self.current_spin) * self.num_of_spins for effect in self.effects: effect.apply(relativePercent, self.flower.get_array()) seedColor = self.flower.get_array()[self.flower.get_leaves()[0] * 3:self.flower.get_leaves()[0] * 3 + 3] seedColor = AlwaysOnEffect(self.flower.get_seeds(), seedColor) seedColor.apply(time_percent, self.flower.get_array())
def __init__(self, flower, props): FlowerAnimation.__init__(self, flower, props) self.effects = [] self.effects.append(FireEffect(self.flower.line_front)) self.effects.append(FireEffect(self.flower.line_back)) self.effects.append(FireEffect(self.flower.leaf_right_front)) self.effects.append(FireEffect(self.flower.leaf_right_back)) self.effects.append(FireEffect(self.flower.leaf_left_front)) self.effects.append(FireEffect(self.flower.leaf_left_back)) # for col in self.flower.bottom_to_top_cols: # self.effects.append(FireEffect(col)) for leaf in self.flower.top_leaves_arr: # split to 2 chunks size = len(leaf)/2 arr = [leaf[i:i + size] for i in xrange(0, len(leaf), size)] up = arr[0] down = arr[1] self.effects.append(FireEffect(up)) self.effects.append(FireEffect(down[::-1])) self.effects.append(AlwaysOnEffect(self.flower.seeds, [200, 0, 0]))
def __init__(self, lake, props): LakeAnimation.__init__(self, lake, props) self.effects = [] leds_percent_per_beat = 0.4 fade_factor = 0.9 only_waves = True brightness = 1.0 if self.props != None: if 'leds_percent_per_beat' in self.props: leds_percent_per_beat = self.props['leds_percent_per_beat'] if 'only_waves' in self.props: only_waves = self.props['only_waves'] if 'brightness' in self.props: brightness = self.props['brightness'] if 'fade_factor' in self.props: fade_factor = self.props['fade_factor'] if only_waves == True: self.effects.append( ConfettiEffect(self.lake.waves, leds_percent_per_beat, brightness, fade_factor=fade_factor)) self.effects.append(AlwaysOnEffect(self.lake.contour, [0, 0, 30])) else: self.effects.append( ConfettiEffect(self.lake.whole_lake, leds_percent_per_beat, brightness, fade_factor=fade_factor))
def apply(self, time_percent): if (time_percent < self.previous_time): self.effects = [] if self.frame_counter % 2 == 0: hue = self.previous_hue + 0.1 + random.random() * 0.8 if hue > 1: hue -= 1 self.previous_hue = hue self.previous_color = self.color self.color = Colors.hls_to_rgb(hue, 1, 1) self.effects.append( AdvanceEffect.initColor(self.tree.get_right_stem(), self.previous_color, self.color)) self.effects.append( AdvanceEffect.initColor(self.tree.get_left_stem(), self.previous_color, self.color)) for leaf in self.tree.get_leaves_array(): self.effects.append( AlwaysOnEffect(leaf[0], self.previous_color)) self.effects.append( AlwaysOnEffect(leaf[1], self.previous_color)) if self.frame_counter % 2 == 1: self.effects.append( AlwaysOnEffect(self.tree.get_right_stem(), self.color)) self.effects.append( AlwaysOnEffect(self.tree.get_left_stem(), self.color)) for leaf in self.tree.get_leaves_array(): self.effects.append( AdvanceEffect.initColor(leaf[0][::-1], self.previous_color, self.color)) self.effects.append( AdvanceEffect.initColor(leaf[1][::-1], self.previous_color, self.color)) self.frame_counter += 1 for effect in self.effects: effect.apply(time_percent, self.tree.get_array()) self.previous_time = time_percent
def _start_spike(self): self.effects = [] self.last_hue += self.hue_speed if self.last_hue > 1: self.last_hue -= 1 rand_color = Colors.hls_to_rgb(self.last_hue, 1.0, 1.0) self.effects.append( AlwaysOnEffect(self.flower.get_leaves_array()[self.last_leaf], rand_color)) self.effects.append(AlwaysOnEffect(self.flower.seeds, rand_color)) self.effects.append( AlwaysOnEffect(self.flower.bottom_parts, rand_color)) self.last_leaf += 1 if self.last_leaf >= len(self.flower.get_leaves_array()): self.last_leaf = 0
def apply(self, time_percent): for i in range(0, self.grass.num_of_leaves()): leaf = self.grass.get_leaves_array()[i] loc = self.grass.leaf_loc_percent(i) c = self.timed_color.get_color(time_percent, loc) brightness = self.loc_to_brightness(time_percent, loc) * self.global_brightness(time_percent) c = Colors.change_rgb_lightness(c, Colors.fix_lightness_percent(brightness)) AlwaysOnEffect(leaf[0] + leaf[1], c).apply(time_percent, self.grass.get_array())
class NaturalLakeAnimation(LakeAnimation): def __init__(self, lake, props): LakeAnimation.__init__(self, lake, props) self.effects = [] self.previous_time = 1 self.hue = 0.67 if self.props != None: if 'hue_start' in self.props: self.hue = self.props['hue_start'] self.base_effect = AlwaysOnEffect(self.lake.whole_lake, Colors.hls_to_rgb(self.hue, 1, 1)) self.start_times = [] self.speeds = [] self.create_effects() def create_effects(self): self.effects = [] self.start_times = [] self.speeds = [] for i in range(len(self.lake.waves_arr)): start_time = random.uniform(0, 0.2) speed = 0.8 self.start_times.append(start_time) self.speeds.append(speed) wave = self.lake.waves_arr[i] self.effects.append(DarkPointEffect(wave, 10)) def apply(self, time_percent): if (time_percent < self.previous_time): self.create_effects() self.previous_time = time_percent self.base_effect.apply(time_percent, self.lake.get_array()) for i in range(len(self.lake.waves_arr)): if (time_percent < self.start_times[i] or time_percent > self.start_times[i]+self.speeds[i]): continue relative_pos = (time_percent - self.start_times[i]) / self.speeds[i] self.effects[i].apply(relative_pos, self.lake.get_array())
def __init__(self, tree, props): TreeAnimation.__init__(self, tree, props) self.effects = [] self.effects.append( AlwaysOnEffect(self.tree.get_stem(), [184, 134, 11])) for leaf in self.tree.get_leaves_array(): self.effects.append(GreenFireEffect(leaf[0][::-1])) self.effects.append(GreenFireEffect(leaf[1][::-1]))
def create_effects(self): self.effects = [] color1 = Colors.hls_to_rgb(self.hue1, 1, 1) color2 = Colors.hls_to_rgb(self.hue2, 1, 1) self.effects.append( AlternateColorEvery3Effect(self.flower.bottom_parts, color1, color2)) self.effects.append( AlternateColorEvery3Effect(self.flower.get_leaves(), color1, color2)) self.effects.append(AlwaysOnEffect(self.flower.seeds, color1))
def apply(self, time_precent, parent_array): blinkBodyNum = math.floor(time_precent * self.sheep.get_num_of_body_parts()) if (self.currentBlinkBodyNum != blinkBodyNum): self.currentBlinkBodyNum = int(blinkBodyNum) headColor = [self.color[1], self.color[2],self.color[0]] legColor = [self.color[2], self.color[0],self.color[1]] bodyColor = [int(self.color[0]*0.1), int(self.color[1]*0.1), int(self.color[2]*0.1)] headEffect = AlwaysOnEffect(self.sheep.get_head_indexes(), headColor) legEffect = AlwaysOnEffect(self.sheep.get_legs_indexes(), legColor) bodyEffect = AlwaysOnEffect(self.sheep.get_body_indexes(), bodyColor) blinkEffect = BlinkEffect(self.sheep.get_body_part_indexes(self.currentBlinkBodyNum), 2, self.color) self.effects = [headEffect,legEffect, bodyEffect, blinkEffect] oneBodyPercent = 1.0 / self.sheep.get_num_of_body_parts() relativePercent = (time_precent - self.currentBlinkBodyNum * oneBodyPercent) * self.sheep.get_num_of_body_parts() for effect in self.effects: effect.apply(relativePercent, parent_array)
def apply(self, time_percent): spin = int(math.floor(time_percent * self.num_of_spins)) if (spin != self.current_spin): self.current_spin = spin self.hue = Colors.reduce_by_1(self.hue + 0.62) self.effects = [ AlwaysOnEffect(self.flower.get_all_indexes(), [30, 30, 30]), FibonacciEffect(self.flower.get_leaves(), self.hue) ] oneSpinTime = 1.0 / float(self.num_of_spins) relativePercent = (time_percent - oneSpinTime * self.current_spin) * self.num_of_spins for effect in self.effects: effect.apply(relativePercent, self.flower.get_array())
def _start_spike(self): self.effects = [] self.last_hue += self.hue_speed if self.last_hue > 1: self.last_hue -= 1 rand_color = Colors.hls_to_rgb(self.last_hue, 1.0, 1.0) new_animation = AlwaysOnEffect( self.grass.get_leaves_array()[self.last_leaf][0] + self.grass.get_leaves_array()[self.last_leaf][1], rand_color) self.effects.append(new_animation) self.last_leaf += 1 if self.last_leaf >= len(self.grass.get_leaves_array()): self.last_leaf = 0
def __init__(self, sheep, props): SheepAnimation.__init__(self, sheep, props) self.effects = [] self.effects.append( AlwaysOnEffect(self.sheep.get_ears_indexes(), [255, 0, 0])) self.effects.append( FireEffect(self.sheep.get_leg12_side1_indexes()[::-1])) self.effects.append(FireEffect(self.sheep.get_leg12_side2_indexes())) self.effects.append( FireEffect(self.sheep.get_leg34_side1_indexes()[::-1])) self.effects.append(FireEffect(self.sheep.get_leg34_side2_indexes())) self.effects.append(FireEffect(self.sheep.get_head_up1())) self.effects.append(FireEffect(self.sheep.get_head_up2())) for i in range(self.sheep.get_num_of_body_parts()): body_part = self.sheep.get_body_part_indexes(i) if i < 4: up = body_part[:len(body_part) / 2] down = body_part[len(body_part) / 2:] self.effects.append(FireEffect(up[::-1])) self.effects.append(FireEffect(down)) elif i == 4: continue elif i == 5: body_part4 = self.sheep.get_body_part_indexes(4) up = body_part[:len(body_part) / 2] up = body_part4 + up down = body_part[len(body_part) / 2:] self.effects.append(FireEffect(up)) self.effects.append(FireEffect(down[::-1])) elif i > 5: up = body_part[:len(body_part) / 2] down = body_part[len(body_part) / 2:] self.effects.append(FireEffect(up)) self.effects.append(FireEffect(down[::-1]))
def next_hue(self): self.effects = [] new_hue = self.hue + self.hue_speed if new_hue > 1: new_hue -= 1 if self.full_color == True: prev_color = Colors.hls_to_rgb(self.hue, 1.0, 1.0) new_color = Colors.hls_to_rgb(new_hue, 1.0, 1.0) else: prev_color = Colors.hls_to_rgb(self.hue, 0.5, 0.7) new_color = Colors.hls_to_rgb(new_hue, 0.5, 0.7) if self.animated == True: self.effects.append( GoToColorEffect(self.sign.whole_sign, prev_color, new_color)) else: self.effects.append(AlwaysOnEffect(self.sign.whole_sign, new_color)) self.hue = new_hue
def restart_effect(self): self.eyes_effect = AlwaysOnEffect(self.sheep.get_ears_indexes(), [255, 0, 0]) if self.hue == 'Rainbow': self.head_effect = FadeInOutEffect(self.sheep.get_head_indexes(), HueChangeTimedColor(0.0, 1.0)) self.legs_effect = FadeInOutEffect(self.sheep.get_legs_indexes(), HueChangeTimedColor(0.0, 1.0)) self.body_effect = ColorFillFadeEffect( self.sheep.get_body_indexes(), 0.5, HueChangeTimedColor(0.0, 1.0)) else: start_hue = self.hue - 0.05 end_hue = self.hue + 0.05 self.head_effect = FadeInOutEffect( self.sheep.get_head_indexes(), HueChangeTimedColor(start_hue, end_hue)) self.legs_effect = FadeInOutEffect( self.sheep.get_legs_indexes(), HueChangeTimedColor(start_hue, end_hue)) self.body_effect = ColorFillFadeEffect( self.sheep.get_body_indexes(), 0.5, HueChangeTimedColor(start_hue, end_hue))
def __init__(self, signs, color): self.signs = signs self.effects = [AlwaysOnEffect(self.signs.get_all_indexes(), color)]
def apply(self, time_percent): for effect in self.effects: effect.apply(time_percent, self.sheep.get_array()) leg12color = self.sheep.get_array( )[self.sheep.get_leg12_connection_index() * 3:self.sheep.get_leg12_connection_index() * 3 + 3] legs12Effect = AlwaysOnEffect(self.sheep.get_leg12_indexes(), leg12color) legs12Effect.apply(time_percent, self.sheep.get_array()) leg34color = self.sheep.get_array( )[self.sheep.get_leg34_connection_index() * 3:self.sheep.get_leg34_connection_index() * 3 + 3] legs34Effect = AlwaysOnEffect(self.sheep.get_leg34_indexes(), leg34color) legs34Effect.apply(time_percent, self.sheep.get_array()) inner_ear_color = self.sheep.get_array( )[self.sheep.get_inner_ear_connection_index() * 3:self.sheep.get_inner_ear_connection_index() * 3 + 3] inner_ear_effect = AlwaysOnEffect(self.sheep.get_inner_ear_indexes(), inner_ear_color) inner_ear_effect.apply(time_percent, self.sheep.get_array()) outer_ear_color = self.sheep.get_array( )[self.sheep.get_outer_ear_connection_index() * 3:self.sheep.get_outer_ear_connection_index() * 3 + 3] outer_ear_effect = AlwaysOnEffect(self.sheep.get_outer_ear_indexes(), outer_ear_color) outer_ear_effect.apply(time_percent, self.sheep.get_array())