示例#1
0
bulbs = Bulbs(driver)

class Snake:
    def __init__(self, position, size, speed, color):
        self.start = position
        self.end = (position+size) % Bulbs.COUNT
        self.speed = speed
        self.color = color

    def move(self):
        self.start = (self.start + self.speed) % Bulbs.COUNT
        self.end = (self.end + self.speed) % Bulbs.COUNT

    def draw(self, bulbs):
        x = self.start
        while x != self.end:
            bulbs.add(x, self.color)
            x = (x + 1) % Bulbs.COUNT

plane = [Snake(0, 20, 1, Bulbs.RED),
         Snake(79, 20, -1, Bulbs.BLUE),
         Snake(45, 10, 2, Bulbs.GREEN)]

while not driver.stop_signal():
    bulbs.clear()
    for snake in plane:
        snake.move()
        snake.draw(bulbs)
    bulbs.render()
    sleep(0.05)
示例#2
0
bulbs = Bulbs(d)


# Start by drawing bumpers at the edge
bumpers = set()
for f in range(5):
	bulbs.frame[f] = Bulbs.BLUE
	bumpers.add(f)
for f in range(95,100):
	bulbs.frame[f] = Bulbs.BLUE
	bumpers.add(f)
field = set(range(100)) - bumpers

# Draw blank slate
blank_slate = list(bulbs.frame)
bulbs.render(force=True)
sleep(.1)

# Now add the balls
balls = zip(*[random.sample(range(10,90,2), NUM_BALLS),random.sample(set(Bulbs.COLORS)-set(Bulbs.BLUE), NUM_BALLS),[x*[-1,1][random.randint(0,1)] for x in [1]*NUM_BALLS]])


def ghost(ball, color, direction, initial=False):
	r,g,b,a = color

	a = a >> 1
	while (a > 0):
		ball -= direction
		if ball in bumpers or ball in zip(*balls)[0]:
			return