示例#1
0
 def step(self, direction):
     """LIFO data structure ensures shape preservation"""
     lead = self.pixels[0]
     new_p = Pixel(lead.x, lead.y)
     new_p.step(direction)
     self.pixels.insert(0, new_p)
     self.last_popped = self.pixels.pop()
示例#2
0
    def lost_state(self):
        pixels = []

        for x in range(8):
            pixels.append(Pixel(x, x))
            diff = 7 - x
            pixels.append(Pixel(diff, x))

        return pixels
示例#3
0
    def move(self):
        for dot in self.dots:
            dot.move(0, 1)

        # add new dots
        if len(self.dots) < self.count:
            self.dots.append(Pixel(randint(0, 7), 0, color=(0, 0, 100)))
示例#4
0
    def move(self, dx=0, dy=1):
        now = time()
        if now - self.last_move < self.interval:
            return

        self.last_move = now
        for dot in self.dots:
            dot.move(dx, dy)

        # add new dots
        if len(self.dots) < self.count:
            self.dots.append(Pixel(randint(0, 7), 0, color=self.color))
示例#5
0
            self.factor[1] = -self.factor[1]

        self.decorated.move(dx * self.factor[0], dy * self.factor[1])


sense = SenseHat()
sense.low_light = True
sense.height = 8
sense.width = 8

atexit.register(sense.clear)


b = (0, 0, 155)
g = (0, 155, 0)
r = (155, 0, 0)

pixels = [Reflect(Pixel(5, 1, color=b)),
          Reflect(Pixel(4, 4, color=g)),
          Reflect(Pixel(1, 6, color=r))]

try:
    while True:
        for pixel in pixels:
            pixel.move(1, 1)
            pixel.refresh(sense)
        sleep(0.1)

except KeyboardInterrupt:
    exit(0)
示例#6
0

def lost():
    # if hit the falling dot
    sense.set_pixels(sad)
    sleep(3)


sense = SenseHat()
atexit.register(sense.clear)

sense.low_light = True
sense.width = 8
sense.height = 8
scene = Scene(conunt=5, interval=0.5)
pad = EdgeStop(Pixel(4, 7, color=r), sense)
gyro = Gyro(sense, threshold=0.03)

try:
    for cnt in range(3):
        sense.clear()
        scene.clear()

        while True:
            so = gyro.get_orientation()

            scene.move()
            scene.refresh(sense)

            if scene.has_colision(pad):
                lost()
示例#7
0
    def __init__(self, start):
        self.pixels = []

        for p in range(4):
            self.pixels.append(Pixel(start[0], start[1]))
            start = Pixel.add_step(start, Pixel.RIGHT)
示例#8
0
 def get_next_dot(self):
     pxs = [(p.x, p.y) for p in self.player.pixels]
     free_pixels = [(x, y) for x in range(self.COLUMNS)
                    for y in range(self.ROWS) if (x, y) not in pxs]
     choice = random.choice(free_pixels)
     return Pixel(choice[0], choice[1])
示例#9
0
 def consume(self, point):
     pixels.insert(Pixel(point[0], point[1]), 0)