sleep(.1) print "Starting with %d balls at positions:" % (NUM_BALLS) for ball,color,direction in balls: print "\t%d: %s going %d" % (ball, str(color), direction) bulbs.frame[ball] = color bulbs.render() sleep(.1) ghost(ball, color, direction, True) # Blink balls before starting motion cache = bulbs.frame for blinks in range(3): bulbs.frame = blank_slate bulbs.render(force=True) d.busy_wait(.5) bulbs.frame = cache bulbs.render(force=True) d.busy_wait(.5) def advance(ball_tuple): ball, color, direction = ball_tuple r,g,b,a = color if ball+direction in bumpers: print "%d Hit bumper." % (ball) direction = -direction ball = ball + direction a = a >> 1 elif ball+direction in zip(*balls)[0]:
return tmp_idx def quicksort(self, left, right): if left < right: pivot_idx = (left + right)/2 # play with different pivot selection pivot_new_idx = self.partition(left, right, pivot_idx) self.quicksort(left, pivot_new_idx - 1) self.quicksort(pivot_new_idx + 1, right) def sort(self): self.quicksort(0, 99) if __name__=="__main__": print 'waiting...' import sys if len(sys.argv) > 1 and sys.argv[1] == "emulator": driver = RemoteDriver("QuickSort", "localhost") else: d = RemoteDriver("QuickSort") print 'our turn' sorter = QuickSort(Bulbs(d)) sorter.sort() # Leave the sorted list up d.busy_wait()
# This will block until it is your turn print 'Waiting for our turn...' d = RemoteDriver("UnitTest") print 'Our turn!' # Turn off all the LEDs for i in range(100): d.write_led(i, 0, 0, 0, 0) # Turn them back on from the top, with some delay (100*.05 = 5s) for i in range(100): d.write_led(i, 200, 13, 0, 13) time.sleep(.05) # Turn them off in chunks of 10 (10*2 = 20s) # Note that busy_wait must be used for delays >= 1s for i in range(100, 0, -10): for j in range(i, i-10, -1): d.write_led(j-1, 0, 0, 0, 0) d.busy_wait(2) # Turn on all the LEDs for i in range(100): d.write_led(i, 200, 13, 13, 13) # Send NOP keep-alives until our 30-second time expires # Alternatively, you can close the connection with # d.done() (or wait for it to time you out) d.busy_wait()