def next_frame(self): while True: for x in range(self.width): w = (self.min_freq + x) / float( self.cycles) # pendulum frequency y_top = (cos(w * self.counter) + 1) * hex.HEX_SIZE / 2 for y in range(hex.HEX_SIZE): if self.up_down: c = change_color(self.color, x * self.gradient / 1500.0) if y < y_top else black() else: c = change_color(self.color, x * self.gradient / 1500.0) if y > y_top else black() h = x // hex.HEX_SIZE hex_x = x % hex.HEX_SIZE self.hexes.set_cell( (h, hex_x - hex.HEX_OFFSET, y - hex.HEX_OFFSET), dim_color(c, 0.5)) self.counter += 1 if self.counter % (int(2 * pi * self.cycles)) == 0: self.min_freq = up_or_down(self.min_freq, 1, 3, 10) self.gradient = up_or_down(self.gradient, 2, 5, 15) self.color = random_color_range(self.color, 0.007) self.up_down = not self.up_down yield self.speed # random time set in init function
def __init__(self, hexmodel): self.name = "Seasons" self.hexes = hexmodel self.treespot = [] # List that holds branch cells self.leaves = [] # List that holds leaf objects self.sky_color = black() # Set for each season self.ground_color = black() # Set for each season self.treecolor = rgb_to_hsv((54, 0, 0)) # Dark brown
def next_frame(self): for i in range(0, 1000): # number of steps per game # Calculate each hex's fate for cell in self.life_hexes.life_map: self.life_hexes.decide_fate(cell) # Push all at once the new fates into current state for cell in self.life_hexes.life_map: self.life_hexes.get(cell).push_state() # Draw the actual hexes, but only the ones in the display for cell in self.hexes.cellmap.keys(): mapped_cell = self.life_hexes.get(cell) if mapped_cell: color = self.on_color if mapped_cell.is_alive( ) else self.off_color self.hexes.set_cell(cell, color) # Slowly change the colors if helpfunc.one_in(10): self.on_color = change_color(self.on_color, 0.1) if helpfunc.one_in(5): if self.off_color != black(): # Black - keep as black self.off_color = change_color(self.off_color, -0.05) yield self.speed # random time set in init function
def test_named_colors(): for i in color_names: print(getattr(color, i)(i) + color.red('compare')) print( color.black(getattr(color, i + '_bg')(i + '_bg')) + color.red('compare')) print(getattr(color, i + '_hl')(i + '_hl') + color.red('compare'))
def report(worklog, config): lines = [] total = timedelta(seconds=0) rollup = dict() lines.append('{} {}'.format( color.bold('Worklog Report for'), color.purple(worklog.when.strftime('%F'), bold=True))) if len(worklog) == 0: lines.append(' no entries') else: for task, next_task in worklog.pairwise(): if isinstance(task, GoHome): continue if isinstance(next_task, DummyRightNow): colorize_end_time = color.yellow else: colorize_end_time = color.green delta = next_task.start - task.start if task.include_in_rollup(): total += delta if task.description not in rollup: rollup[task.description] = delta else: rollup[task.description] += delta if delta > timedelta(): if not task.logged: task.logged = False lines.append(' {:5s} {} {:5s} {}{!s:>7}{} {} {} {}'.format( color.green(task.start.strftime('%H:%M')), color.black('-', intense=True), colorize_end_time(next_task.start.strftime('%H:%M')), color.black('(', intense=True), Duration(delta).colorized(), color.black(')', intense=True), { True: color.green('*'), False: color.red('*') }[task.logged], task.ticket, task.description)) lines.append('\n {!s:>7} {}'.format( Duration(total).colorized(underline=True), color.colorize('TOTAL', bold=True, underline=True))) for key in sorted(rollup.keys()): lines.append(' {!s:>7} {}'.format( Duration(rollup[key]).colorized(), color.bold(key))) print('\n'.join(lines))
def __init__(self, hexmodel): self.name = "Game of Life" self.hexes = hexmodel # Actual visualized hexes self.life_hexes = self.create_life_model(size=8) # Virtual life hexes self.speed = 0.2 + (random() * 2) self.on_color = random_color() # Most of the time set the background to black # Some of the time choose a colored background self.off_color = black()
def __init__(self, hexmodel): self.name = "Driving" self.hexes = hexmodel self.stuffs = [] # List that holds stuffs objects self.sky_color = black() # Set for each season self.ground_color = rgb_to_hsv((255, 255, 0)) # Set for each season self.cars_speed = 1.0 # How fast the scene moves self.clock = 0 self.scene = 0 self.max_scene = 6
def __init__(self, hexmodel): self.name = "Volcano" self.hexes = hexmodel self.rocks = [] # List that holds rocks self.rock_intense = [randint(3, 8) for _ in helpfunc.all_hexes() ] # Lower = more rocks self.lava_color = random_color(reds=True) self.volcano_color = rgb_to_hsv((100, 100, 100)) # Grey: (x,x,x) self.background_color = black() self.speed = 0.05 * randint(1, 5) self.clock = 0
def set_black(self): self.set_color(color_func.black())
def __init__(self, x, y): self.x, self.y = x, y self.s, self.led = self.get_led() self.curr_frame = color_func.almost_black() self.next_frame = color_func.black() self.interp_frame = color_func.black()
def __init__(self, hexmodel, h): super(Bird, self).__init__(hexmodel, h) self.y_coord = randint(-6, 6) self.color = black() self.x_dir = randint(-1, 1) self.y_dir = randint(-1, 1)
def __init__(self, h, x, y): self.h, self.x, self.y = h, x, y # h = hex number = strip = universe self.led = self.get_led() self.curr_frame = color_func.almost_black() self.next_frame = color_func.black() self.interp_frame = color_func.black()