def fill(self): self.bound_attrs() # cooling_down for idx in range(self.strip_length): cooldown = randint( 0, ceil(((self.cooldown_list[idx] * 10) / self.strip_length)) + self.cooling()) self.cooldown_list[idx] = bound_sub(self.cooldown_list[idx], cooldown, minimum=0) for idx in range(self.strip_length - 1, self.mid, -1): v = (self.cooldown_list[idx - 1] + 2 * self.cooldown_list[idx - 2]) / 3 self.cooldown_list[idx] = v for idx in range(0, self.mid - 1, +1): v = (self.cooldown_list[idx + 1] + 2 * self.cooldown_list[idx + 2]) / 3 self.cooldown_list[idx] = v if randint(0, 255) < self.sparking(): # sparking starting point y = randint(self.mid - 3, self.mid + 3) self.cooldown_list[y] = self.cooldown_list[y] + randint(160, 255) for idx in range(self.strip_length): self.pixels[idx]['color'] = heat_to_rgb(self.cooldown_list[idx])
def fill(self): # copy original dict center_copy = deepcopy(self.centers) # bound the rnadom point to the maximum self.point_number.value = min(self.point_number(), self.strip_length) # for every center in the list for a, attr in center_copy.items(): # get attributes color = attr["color"] alpha = attr['alpha'] delay = attr['delay'] increasing = attr['increasing'] done = False # if point has to wait more then wait if delay > 0: self.centers[a]['delay'] -= 1 continue # if increasing and there is still room for increasing do it if 0 <= alpha < 255 and increasing: alpha = bound_add(alpha, self.rate_start(inverse=True), maximum=255) # if not increasing and still in good range, decrease elif 0 < alpha <= 255 and not increasing: alpha = bound_sub(alpha, self.rate_end(inverse=True), minimum=0) # if zero and decreasing we're done elif alpha == 0 and not increasing: done = True # if 255 and increasing then start decreasing elif alpha == 255 and increasing: increasing = False # update and set color color.update_single(a=alpha) self.pixels[a]['color'] = color # update for original dict too self.centers[a]['alpha'] = alpha self.centers[a]['increasing'] = increasing # if is done if done: # pop center self.centers.pop(a) # if centers are less than supposed, add other if len(self.centers) < self.point_number(): # get a new one new_c = randint(0, self.strip_length - 1) while new_c in self.centers.keys(): new_c = randint(0, self.strip_length - 1) # add it to list self.centers[new_c] = self.empty_center()
def thunder_handler(idx): """ Handle thunder :param idx: :return: """ # if current index is a thunder center if idx in self.thunder_centers.keys(): # get the values start, end, alpha = self.thunder_centers[idx] # mimic thunder behavior to brighten up with random value if random() < 0.1: alpha = bound_add(alpha, thunder_loss * 2) else: alpha = bound_sub(alpha, thunder_loss) # update alpha self.thunder_centers[idx][2] = alpha # for every part of the thunder for jdx in range(start, end + 1): # copy the thunder color c = self.thunder_color.copy() # estimate the distance from center as a loss + a random term l = 200 * abs(jdx - idx) / self.thunder_size() // 2 + randint( 0, 50) # estimate new local alpha v = bound_sub(alpha, thunder_loss + l) # update in color c.update_single(a=v) # set # c.blend(self.pixels[jdx]['color']) self.pixels[jdx]['color'] = c # if alpha is zero then remove the center if alpha == 0: del self.thunder_centers[idx]
def fill(self): a = self.color.a if 0 <= a < 255 and self.increasing: a = bound_add(a, self.speed(), maximum=255) elif 0 < a <= 255 and not self.increasing: a = bound_sub(a, self.speed(), minimum=0) else: self.increasing = not self.increasing self.color.a = a for idx in range(self.strip_length): self.pixels[idx]['color'] = self.color
def rain_handler(idx): rn = self.pixels[idx]['rain'] if not rn: rn = 255 * random() if random() < self.rain() else 0 else: rn = bound_sub(rn, rain_loss) self.pixels[idx]['rain'] = rn if rn: c = self.rain_color.copy() c.blend(self.pixels[idx]['color']) c.update_single(a=rn) self.pixels[idx]['color'] = c
def fill(self): self.bound_attrs() loss_weight = 1.3 center_copy = deepcopy(self.centers) # for every center in the list for a, attr in center_copy.items(): # get the color and the tail color = attr["color"] step = attr["step"] has_popped = False # estimate the center intesity and update ci = bound_sub(255, loss_weight * self.loss() * step) color.update_single(a=ci) self.add_update_pixel(a, color) idx = 1 # if the intensity is more than zero, the the tail is still increasing if ci > 0: # for 1 to the current step for idx in range(idx, step + 1): # get previous and next led p = a - idx n = a + idx p %= self.strip_length n %= self.strip_length # estimate intensity and update # ci is= 255 - the loss times the current step and the index (farther points from center are newer) ci = bound_sub(255, self.loss() * (loss_weight * step + 1 - idx)) color.update_single(a=ci) self.add_update_pixel(p, color) self.add_update_pixel(n, color) # update tail attr["tail"].append((p, n, idx)) # remove duplicates attr["tail"] = list(set(attr["tail"])) # if the center has faded then the tails need to fade too else: # if there are some non zero tail if len(attr["tail"]) > 0: # for every tail for t in attr["tail"]: # get previous, next and index p = t[0] n = t[1] idx = t[2] # estimate ci as before ci = bound_sub(255, self.loss() * (loss_weight * step + 1 - idx)) # update color.update_single(a=ci) self.add_update_pixel(p, color) self.add_update_pixel(n, color) # if ci is zero remove point from tail if ci == 0: attr["tail"].pop(attr["tail"].index(t)) # if the center is faded and it has no more tail else: # remove the center self.centers.pop(a) if len(self.centers) < self.fires(): for _ in range(self.fires() - len(self.centers)): # get another one which is not in the center lists already rd = randint(0, self.strip_length - 1) while rd in self.centers.keys(): rd = randint(0, self.strip_length - 1) # put random color self.centers[rd] = self.empty_center() has_popped = True # is the center has been removed then dont update if not has_popped: try: self.centers[a]["tail"] = attr["tail"] step = circular_step(step, self.strip_length) self.centers[a]["step"] = step except KeyError: pass self.update_counter()