def rotate(cw=True): "Rotate the bar pattern, clockwise (if cw is True) or anticlockwise." global fps, duration, fast t,i = 0,0 while i != duration: p1 = time.time() # time measuring point 1 if cw: x_offset = t else: x_offset = t * (-1) panel_pattern(x_offset) # Theoretically, the arena should be able to render all eight # panels simultaneously. However, on at least one arena, one panel # develops problems with this approach. Therefore, I here revert to # only updating half the panels at once. If speed is off the essence, # this behaviour can be turned off using the `fast` flag. if not fast: for p in range(8): if p < 4: arena.toggle_panel(p, True) else: arena.toggle_panel(p, False) arena.render() panel_pattern(x_offset) for p in range(8): if p < 4: arena.toggle_panel(p, False) else: arena.toggle_panel(p, True) arena.render() p2 = time.time() # time measuring point 2 sleep_time = (1.0/fps) - (p2-p1) if sleep_time > 0: time.sleep(sleep_time) if t < 7: t = t+1 else: t = 0 i = i + 1
def plot(coords, colour="green", flush=False): ''' Draw a shape from a list of coordinates (as produced by the shape functions). colour: The colour to use flush: If true, will output the result immediately ''' for c in coords: arena.set_pixel(c[0], c[1], colour) if flush: arena.render()
def draw_house(): arena.clear("blue", show=False) #sky # Note the order of drawing! (Some shapes overlap) shape.plot(shape.rectangle(24,15,72,15,72,7,24,7), colour="orange") #main house shape.plot(shape.rectangle(20,7,24,3,72,3,76,7), colour="red") #roof shape.plot(shape.rectangle(58,15,58,10,64,10,64,15), colour="magenta") #door arena.set_pixel(63,12,"red") #doorknob shape.plot(shape.rectangle(32,9,44,9,44,12,32,12), colour="cyan") #window shape.plot(shape.rectangle(98,11,100,11,100,15,98,15), colour="magenta") #tree trunk shape.plot(shape.circle(99,6,5), colour="green") #tree foliage shape.plot(shape.circle(122,3,2), colour="yellow") #sun shape.plot(shape.line(0,15,127,15), colour="green") #grass arena.render()
def animate(ticks=-1): ''' Animate the elements at the given framerate for a set time ticks: number of ticks to run the animation for (-1 -> forever) fps: framerate in ticks per second (default: 21fps = 60deg/s) ''' global bg_col, fps arena.clear(bg_col, show=False) i = 0 while i != ticks: i = i + 1 # infinity loop if ticks = -1 draw_bar(i) draw_dot(i) arena.render() time.sleep(1.0/fps)
def flow(fw=True): "Show the optic flow pattern, forward (if fw is True) or backward." global fps, duration t,i = 0,0 while i != duration: p1 = time.time() # time measuring point 1 if fw: x_left, x_right = t*(-1)+4, t else: x_left, x_right = t+4, t*(-1) panel_pattern(x_right) for p in range(8): if p < 4: arena.toggle_panel(p, True) else: arena.toggle_panel(p, False) arena.render() panel_pattern(x_left) for p in range(8): if p < 4: arena.toggle_panel(p, False) else: arena.toggle_panel(p, True) arena.render() p2 = time.time() # time measuring point 2 sleep_time = (1.0/fps) - (p2-p1) if sleep_time > 0: time.sleep(sleep_time) if t < 7: t = t+1 else: t = 0 i = i + 1