示例#1
0
 def draw(self):
     self.bounce()
     dcfurs.clear()
     dcfurs.set_pixel(self.x, self.y, 1)
     self.x += self.leftright
     self.y += self.updown
     dcfurs.set_pixel(self.x, self.y, 255)
示例#2
0
def render(str):
    ## Check for special cases
    if str == 'boop':
        boop()
        return
    if str == 'owo':
        owo()
        return
    if str == 'awoo':
        awoo()
        return

    ## Otherwise, generate from our character set.
    lbits = font7bit[str[0]]
    rbits = font7bit[str[-1]]
    dcfurs.clear()

    ## Draw the left character.
    column = int((8 - len(lbits)) / 2)
    for colbits in lbits:
        for y in range(0, dcfurs.nrows):
            if (colbits & (1 << y)) != 0:
                dcfurs.set_pixel(column, y, 0xff)
        column = column + 1

    ## Draw the right character.
    column = int((28 - len(rbits) + 1) / 2)
    for colbits in rbits:
        for y in range(0, dcfurs.nrows):
            if (colbits & (1 << y)) != 0:
                dcfurs.set_pixel(column, y, 0xff)
        column = column + 1
示例#3
0
 def draw(self):
     for row in range(0, dcfurs.nrows):
         for col in range(0, dcfurs.ncols / 2):
             color = ((self.shift - col - row) // 4) % len(self.color_map)
             dcfurs.set_pixel(col, row, self.color_map[color])
             dcfurs.set_pixel(dcfurs.ncols - col - 1, row,
                              self.color_map[color])
     self.shift += 1
示例#4
0
 def draw(self):
     self.checkButtons()
     dcfurs.clear()
     for i in range(self.rows):
         for j in range(self.columns):
             if self.grid[i][j] == 1:
                 dcfurs.set_pixel(i, j, 255)
     self.update()
示例#5
0
 def draw(self):
     dcfurs.clear()
     for x in range(0, dcfurs.ncols):
         colbits = self.scrollbuf[(self.shift + x) % len(self.scrollbuf)]
         for y in range(0, dcfurs.nrows):
             if (colbits & (1 << y)) != 0:
                 dcfurs.set_pixel(x, y, 0xFF)
     self.shift = (self.shift + 1) % len(self.scrollbuf)
示例#6
0
    def drawframe(self, frame):
        self.interval = int(frame['interval'])
        x = 0
        y = 0

        # Handle monochrome and legacy animations
        if 'frame' in frame:
            # Generate the animation color mapping.
            colormap = [0] * 16
            color = badge.color()
            c_red = (color & 0xff0000) >> 16
            c_green = (color & 0x00ff00) >> 8
            c_blue = (color & 0x0000ff) >> 0
            for i in range(0, 16):
                p_red = c_red * self.intensity[i] >> 8
                p_green = c_green * self.intensity[i] >> 8
                p_blue = c_blue * self.intensity[i] >> 8
                colormap[i] = (p_red << 16) + (p_green << 8) + p_blue

            # Set the pixel values.
            data = frame['frame']
            for ch in data:
                if ch == ':':
                    x = 0
                    y = y + 1
                else:
                    dcfurs.set_pix_rgb(x, y, colormap[int(ch, 16)])
                    x = x + 1
        # Handle 8-bit RGB data
        elif 'rgb' in frame:
            pix = 0
            even = True
            data = frame['rgb']
            for ch in data:
                if ch == ':':
                    x = 0
                    y = y + 1
                elif even:
                    even = False
                    pix = int(ch, 16) << 4
                else:
                    even = True
                    pix += int(ch, 16)
                    dcfurs.set_pixel(x, y, pix)
                    x = x + 1
        # Handle 4-bit palette data
        elif 'palette' in frame:
            data = frame['palette']
            for ch in data:
                if ch == ':':
                    x = 0
                    y = y + 1
                else:
                    dcfurs.set_pixel(x, y, self.xterm[int(ch, 16)])
                    x = x + 1
        # Otherwise, we couldn't make sense of it.
        else:
            dcfurs.clear()
示例#7
0
 def drawframe(self, frame):
     self.interval = int(frame['interval'])
     x = 0
     y = 0
     for ch in frame['frame']:
         if ch == ':':
             x = 0
             y = y + 1
         else:
             dcfurs.set_pixel(x, y, self.intensity[int(ch, 16)])
             x = x + 1
示例#8
0
 def drawframe(self, frame):
     self.interval = int(frame["interval"])
     x = 0
     y = 0
     for ch in frame["frame"]:
         if ch == ":":
             x = 0
             y = y + 1
         else:
             dcfurs.set_pixel(x, y, self.intensity[int(ch, 16)])
             x = x + 1
示例#9
0
    def draw(self):
        # refresh
        dcfurs.clear()
        # draw score
        draw_score(self.score)
        # draw floor
        create_floor()
        # draw dog
        draw_entity(self.dog)

        # reset to the regular interval
        self.interval = 80

        # jump handling
        # mid-jump
        if self.jumping:
            # ceiling hit: stop jumping, start falling
            if self.dog[8][1] <= -3:
                self.jumping = False
                self.falling = True
            # going up
            else:
                dog_move(self.dog, 1)
        # dog gravity
        elif self.falling:
            # floor hit: stop falling
            if self.dog[0][1] >= 4:
                self.falling = False
            # going down
            else:
                dog_move(self.dog, -1)

        # obstacle handling
        # create obstacle
        if not self.waiting:
            self.score = obstacle_move(self.obstacle, self.score)
        # draw obstacle
        draw_entity(self.obstacle)

        # check for collision
        for point in self.obstacle:
            for check in self.dog:
                if point[0] == check[0]:
                    if point[1] == check[1]:
                        dcfurs.set_pixel(point[0], point[1], dead_brightness)
                        self.obstacles = list()
                        self.dog = [(2, 4), (4, 4), (2, 3), (3, 3), (4, 3),
                                    (4, 2), (5, 2), (2, 2), (4, 1)]
                        self.obstacle = [(17, 4), (17, 3)]
                        self.jumping = False
                        self.waiting = True
                        self.interval = 1000
                        self.falling = False
示例#10
0
    def draw(self):
        self.bounce()
        dcfurs.clear()

        self.history = [(self.x, self.y)] + self.history[:-1]
        self.x += self.leftright
        self.y += self.updown

        dcfurs.set_pixel(self.x, self.y, self.color_map[0])
        index = 1
        for x,y in self.history:
            dcfurs.set_pixel(x, y, self.color_map[index])
            index += 1
示例#11
0
 def rain_fall(self):
     ## For each pixel in the buffer:
     y = len(self.fbuf)-1
     while y >= 0:
         row = self.fbuf[y]
         for x in range(0,len(row)):
             px = row[x]
             if ((px >= 255) and (y < (len(self.fbuf)-1))):
                 self.fbuf[y+1][x] = px
             row[x] = px >> 2
         y -= 1
     ## Redraw the display
     for y in range(0,len(self.fbuf)):
         row = self.fbuf[y]
         for x in range(0, len(row)):
             dcfurs.set_pixel(x, y, row[x])
示例#12
0
    def draw(self):
        global frameRate
        global decoder
        global videoFile
        global colorDepth

        if colorDepth == 8: frameSize = 112
        elif colorDepth == 24: frameSize = 336

        # Represents the positions of the missing pixels on the badge
        # These are used in the display algorithm to skip the missing pixels. Used to save ~14% on file size of the video.
        deadPixels0 = (0, 17)  # The missing pixels on the first row
        deadPixels5 = (7, 8, 9, 10)  # The missing pixels on row 5
        deadPixels6 = (0, 6, 7, 8, 9, 10, 11, 17
                       )  # The missing pixels on row 6

        framePos = 0

        frame = decoder.read(frameSize)  # The amount of bytes per frame

        # Reloads the video file if it reaches the end.
        if frame == b'':
            del decoder
            videoFile.close()
            videoFile = open("animations\\" + video_file_name, 'rb')
            decoder = uzlib.DecompIO(videoFile, 31)
            frame = decoder.read(frameSize)

        for y in range(0, 7,
                       1):  # A step for every vertical pixel on the badge
            for x in range(0, 18,
                           1):  # Step for every horizontal pixel on the badge
                if not (y == 0 and x in deadPixels0):  # Skips missing pixels
                    if not (y == 5 and x in deadPixels5):
                        if not (y == 6 and x in deadPixels6):
                            #testnum = ord(frame[framePos])
                            if colorDepth == 24:
                                dcfurs.set_pix_rgb(
                                    x, y,
                                    int.from_bytes(
                                        frame[framePos * 3:framePos * 3 + 3],
                                        "big"))
                            elif colorDepth == 8:
                                dcfurs.set_pixel(x, y, frame[framePos])
                            framePos += 1
示例#13
0
 def draw(self):
     if (self.count < self.reset):
         self.count += 1
         row = random.randint(0, 6)
         if row == 0:
             col = random.randint(1, 16)
         elif row == 5:
             col = random.choice(list(range(0, 8)) + list(range(11, 18)))
         elif row == 6:
             col = random.choice(list(range(1, 7)) + list(range(12, 17)))
         else:
             col = random.randint(0, 18)
         value = random.randint(50, 255)
         dcfurs.set_pixel(col, row, value)
         # print(col," ",row)
     else:
         self.count = 0
         dcfurs.clear()
示例#14
0
 def render(self, xpos, ypos):
     for y in range(0, dcfurs.nrows):
         zy = y + ypos
         if (zy < 0) or (zy >= self.height):
             dcfurs.set_row(y, 0)
             continue
         row = self.z[zy]
         for x in range(dcfurs.ncols):
             zx = x + xpos
             if (zx < 0) or (zx >= self.width):
                 dcfurs.set_pixel(x, y, 0)
             elif row[zx] == MAZE_WALL:
                 dcfurs.set_pixel(x, y, self.PX_WALL)
             elif row[zx] == MAZE_FINISH:
                 dcfurs.set_pixel(x, y, self.PX_FINISH if self.blink else 0)
             elif (zx == self.x) and (zy == self.y):
                 dcfurs.set_pixel(x, y, self.PX_PLAYER)
             else:
                 dcfurs.set_pixel(x, y, 0)
示例#15
0
    def __init__(self):
        self.fbuf = [
            bytearray(18),
            bytearray(18),
            bytearray(18),
            bytearray(18),
            bytearray(18),
            bytearray(18),
            bytearray(18),
        ]
        self.interval = 750
        self.watchdog = 0
        dcfurs.clear()

        ## populate the initial state of the game
        for y in range(0, len(self.fbuf)):
            row = self.fbuf[y]
            for x in range(0, len(row)):
                if random.randint(0, 2) == 0:
                    row[x] = 255
                    dcfurs.set_pixel(x, y, row[x])
示例#16
0
    def draw(self):
        ## Compute the next tick and draw it to the screen
        next = [
            bytearray(18),
            bytearray(18),
            bytearray(18),
            bytearray(18),
            bytearray(18),
            bytearray(18),
            bytearray(18),
        ]
        delta = 0
        for y in range(0, len(self.fbuf)):
            row = next[y]
            for x in range(0, len(row)):
                count = self.neighbors(x, y)
                if self.alive(x, y):
                    if count == 2 or count == 3:
                        row[x] = 255
                    else:
                        delta += 1
                        row[x] = 8
                else:
                    if count == 3 or count == 6:
                        delta += 1
                        row[x] = 255
                dcfurs.set_pixel(x, y, row[x])

        ## Save the game state
        self.fbuf = next

        ## The game can sometimes reach a stable configuration (or die), so
        ## restart the game if the activity drops too low for more than 5
        ## ticks.
        if delta > 4:
            self.watchdog = 0
        elif self.watchdog > 5:
            self.__init__()
        else:
            self.watchdog = self.watchdog + 1
示例#17
0
 def draw(self):
     dcfurs.clear()
     for row in range(0, 7):
         dcfurs.set_pixel(self.column - 1, row, 1)
         dcfurs.set_pixel(self.column, row, 200)
         dcfurs.set_pixel(self.column + 1, row, 1)
     if self.leftright:
         self.column += 1
         if self.column >= 17:
             self.leftright = False
     else:
         self.column -= 1
         if self.column <= 0:
             self.leftright = True
示例#18
0
def booptoggle():
    # Draw the text 'BP and part of an arrow'
    dcfurs.clear()
    dcfurs.set_row(0, 0x02066)
    dcfurs.set_row(1, 0x020aa)
    dcfurs.set_row(2, 0x02066)
    dcfurs.set_row(3, 0x0202a)
    dcfurs.set_row(4, 0x02026)

    # Toggle the boop selection.
    if settings.boopselect:
        settings.boopselect = 0
        badge.boop = dcfurs.boop(settings.boopselect)
        dcfurs.set_pixel(12, 1, 0xff)
        dcfurs.set_pixel(14, 1, 0xff)
        dcfurs.set_pixel(11, 2, 0xff)
        dcfurs.set_pixel(15, 2, 0xff)
    else:
        settings.boopselect = 1
        badge.boop = dcfurs.boop(settings.boopselect)
        dcfurs.set_pixel(12, 3, 0xff)
        dcfurs.set_pixel(14, 3, 0xff)
        dcfurs.set_pixel(11, 2, 0xff)
        dcfurs.set_pixel(15, 2, 0xff)
示例#19
0
def draw_entity(entity):
    for point in entity:
        if point[1] > 0:
            dcfurs.set_pixel(point[0], point[1], game_brightness)
示例#20
0
    def draw(self):
        drawTime = utime.ticks_ms()
        #    if utime.ticks_diff(drawTime, self.lastBeat) > self.ticksPerBeat:
        #      print("DEBUG BEAT: {} lastBeat: {}".format(utime.ticks_diff(drawTime, self.lastBeat), self.lastBeat))
        if self.lastTiltTimeout > 0:
            self.lastTiltTimeout -= 1
        else:
            self.checkButtons()
        if drawTime > self.djTicks:
            #      self.initGrid()
            self.djTicks = utime.ticks_add(utime.ticks_ms(), self.djDuration)
            self.djMode += 1
            if self.djMode > self.djMaxMode:
                self.djMode = 0
        # Process boops first
        if self.boopIndex > 0:
            # Do we have four boops?
            # If so, NOW should be the next downbeat
            if self.boops[3] > 0:
                # We have our 4 samples; let's average deltas and set the new internvalsPerBeat
                d1 = utime.ticks_diff(self.boops[1], self.boops[0])
                d2 = utime.ticks_diff(self.boops[2], self.boops[1])
                d3 = utime.ticks_diff(self.boops[3], self.boops[2])
                print(
                    "DJ MODE: Changing ticksPerBeat. Old: {} New: {} d1: {} d2: {} d3: {}"
                    .format(self.ticksPerBeat, int((d1 + d2 + d3) / 3), d1, d2,
                            d3))
                self.ticksPerBeat = int((d1 + d2 + d3) / 3)  # We tap slow?
                self.lastBeat = 0
                self.boops = [0] * 4
                self.boopIndex = 0
                self.lastBoop = 0
            else:  # OK; we don't have 4 boops. But has our window expired?
                if self.boopIndex > 0:
                    if utime.ticks_diff(drawTime,
                                        self.boops[self.boopIndex -
                                                   1]) > self.nextBoopTimeout:
                        # Yup; expired. Do we have 1, 2, or 3 boops?
                        if self.boopIndex == 3:
                            # Increase the speed by 5 ticks
                            print(
                                "DJ MODE: Increasing speed by 5 ticks.  Old: {} New: {}"
                                .format(self.ticksPerBeat,
                                        self.ticksPerBeat - 5))
                            self.ticksPerBeat -= 5
                            self.boops = [0] * 4
                            self.boopIndex = 0
                            self.lastBoop = 0
                        elif self.boopIndex == 2:
                            # Decrease the speed by 5 ticks
                            print(
                                "DJ MODE: Decreasing speed by 5 ticks.  Old: {} New: {}"
                                .format(self.ticksPerBeat,
                                        self.ticksPerBeat + 5))
                            self.ticksPerBeat += 5
                            self.boops = [0] * 4
                            self.boopIndex = 0
                            self.lastBoop = 0
                        elif self.boopIndex == 1:
                            # Just set the downbeat
                            print("DJ Mode: Downbeat!")
                            self.lastBeat = self.boops[0]
                            self.boops = [0] * 4
                            self.boopIndex = 0
                            self.lastBoop = 0

        angle = 0
        brightness = 0
        if self.djMode == 1:  # Dots!
            if utime.ticks_diff(drawTime,
                                self.lastBeat) > self.ticksPerBeat * 2:
                self.beatIteration = 0
                if self.lastBeat > 0:
                    self.lastBeat = utime.ticks_add(self.lastBeat,
                                                    2 * self.ticksPerBeat)
                else:
                    self.lastBeat = drawTime
                ri = randint(0, 2)
                if ri == 0:
                    self.angleGrid = [[-1 for col in range(self.columns)]
                                      for row in range(self.rows)]
                elif ri == 1:
                    self.angleGrid = [[
                        self.pinkAngle for col in range(self.columns)
                    ] for row in range(self.rows)]
                elif ri == 2:
                    self.angleGrid = [[
                        self.blueAngle for col in range(self.columns)
                    ] for row in range(self.rows)]
                self.brightnessGrid = [[255 for col in range(self.columns)]
                                       for row in range(self.rows)]
            else:
                for y in range(self.columns):
                    for x in range(self.rows):
                        if self.brightnessGrid[x][y] == -1:
                            self.brightnessGrid[x][y] = 255
                        self.brightnessGrid[x][y] -= 64
                        if self.brightnessGrid[x][y] < 0:
                            self.brightnessGrid[x][y] = 0
                rx = randint(0, self.rows - 1)
                ry = randint(0, self.columns - 1)
                for i in range(5):
                    angle = self.pinkAngle
                    if randint(0, 1) == 0:
                        angle = self.blueAngle
                    self.angleGrid[rx][ry] = angle
                    self.brightnessGrid[rx][ry] = randint(0, 255)
        elif self.djMode == 0:  # Strobe a color, halftime
            self.angleGrid = [[
                self.strobeAngle for col in range(self.columns)
            ] for row in range(self.rows)]
            self.strobeAngle += 1
            if self.strobeAngle > 360:
                self.strobeAngle = 0
            if utime.ticks_diff(drawTime,
                                self.lastBeat) > 2 * self.ticksPerBeat:
                # On the beat, we want our strobe to be the brightest
                self.beatIteration = 0
                if self.lastBeat > 0:
                    self.lastBeat = utime.ticks_add(self.lastBeat,
                                                    2 * self.ticksPerBeat)
                else:
                    self.lastBeat = drawTime
                self.brightnessGrid = [[255 for col in range(self.columns)]
                                       for row in range(self.rows)]
            else:
                pctThruBeat = utime.ticks_diff(
                    drawTime, self.lastBeat) / (2 * self.ticksPerBeat)
                brightness = 0
                if pctThruBeat > .5:
                    brightness = int(pctThruBeat * 255)
                else:
                    brightness = int(255 - (2 * pctThruBeat * 255))
                self.brightnessGrid = [[
                    brightness for col in range(self.columns)
                ] for row in range(self.rows)]
        elif self.djMode == 4:  # Circles Fade In
            if utime.ticks_diff(drawTime, self.lastBeat) > self.ticksPerBeat:
                # On the beat, Draw circles
                rr5 = 10 * 10
                rr4 = 6 * 6
                rr3 = 4 * 4
                rr2 = 2 * 2
                if self.lastCircleColor == 1:
                    self.lastCircleColor = 0
                else:
                    self.lastCircleColor = 1
                angle = self.pinkAngle
                if self.lastCircleColor == 1:
                    angle = self.blueAngle
                for y in range(self.columns):
                    ydist = y - self.throb_y + randint(-2, 2)
                    if ydist < 0:
                        ydist = 0 - ydist
                    yy = ydist * ydist
                    for x in range(self.rows):
                        xdist = x - self.throb_x + randint(-2, 2)
                        if xdist < 0:
                            xdist = 0 - xdist
                        xx = xdist * xdist
                        pctThruBeat = utime.ticks_diff(
                            drawTime, self.lastBeat) / self.ticksPerBeat
                        maxBright = int(255 * pctThruBeat)
                        penMaxBright = int(.5 * maxBright)
                        midBright = int(.25 * maxBright)
                        subMidBright = int(.05 * maxBright)
                        self.angleGrid[x][y] = angle
                        if xx + yy <= rr2:
                            self.brightnessGrid[x][y] = maxBright
                        elif xx + yy <= rr3:
                            self.brightnessGrid[x][y] = penMaxBright
                        elif xx + yy <= rr4:
                            self.brightnessGrid[x][y] = midBright
                        else:
                            self.brightnessGrid[x][y] = subMidBright
                self.beatIteration = 0
                if self.lastBeat > 0:
                    self.lastBeat = utime.ticks_add(self.lastBeat,
                                                    self.ticksPerBeat)
                else:
                    self.lastBeat = drawTime
            else:
                for y in range(self.columns):
                    for x in range(self.rows):
                        self.brightnessGrid[x][y] -= 4
        elif self.djMode == 3:  # Pink and blue star field
            if utime.ticks_diff(drawTime, self.lastBeat) > self.ticksPerBeat:
                # On the beat, draw stars
                self.beatIteration = 0
                if self.lastBeat > 0:
                    self.lastBeat = utime.ticks_add(self.lastBeat,
                                                    self.ticksPerBeat)
                else:
                    self.lastBeat = drawTime
                for y in range(self.columns):
                    for x in range(self.rows):
                        self.brightnessGrid[x][y] -= 4
                angle = self.pinkAngle
                if randint(0, 1) == 0:
                    angle = self.blueAngle
                for y in range(self.columns):
                    for x in range(self.rows):
                        if randint(0, 3) == 0:
                            self.brightnessGrid[x][y] = 255
                            self.angleGrid[x][y] = angle
            else:
                for y in range(self.columns):
                    for x in range(self.rows):
                        if self.brightnessGrid[x][y] > 0:
                            self.brightnessGrid[x][y] -= 8
        elif self.djMode == 2:  # Draw pink and blue lines
            if utime.ticks_diff(drawTime,
                                self.lastBeat) > (self.ticksPerBeat / 8):
                # On the beat, draw a new line
                self.beatIteration = 0
                if self.lastBeat > 0:
                    self.lastBeat = utime.ticks_add(self.lastBeat,
                                                    int(self.ticksPerBeat / 8))
                else:
                    self.lastBeat = drawTime


#        if randint(0, 5) == 0:
#          self.initGrid()
                if randint(0, 1) == 0:  # Let's do a row
                    y = randint(0, self.columns - 1)
                    if self.angleGrid[5][y] == self.pinkAngle:
                        for x in range(self.rows):
                            self.angleGrid[x][y] = self.blueAngle
                            self.brightnessGrid[x][y] = 255
                    elif self.angleGrid[5][y] == self.blueAngle:
                        for x in range(self.rows):
                            self.angleGrid[x][y] = self.pinkAngle
                            self.brightnessGrid[x][y] = 255
                    else:
                        if randint(0, 1) == 0:
                            for x in range(self.rows):
                                self.angleGrid[x][y] = self.pinkAngle
                                self.brightnessGrid[x][y] = 255
                        else:
                            for x in range(self.rows):
                                self.angleGrid[x][y] = self.blueAngle
                                self.brightnessGrid[x][y] = 255
                else:
                    x = randint(0, self.rows - 1)
                    if self.angleGrid[x][3] == self.pinkAngle:
                        for y in range(self.columns):
                            self.angleGrid[x][y] = self.blueAngle
                            self.brightnessGrid[x][y] = 255
                    elif self.angleGrid[x][3] == self.blueAngle:
                        for y in range(self.columns):
                            self.angleGrid[x][y] = self.pinkAngle
                            self.brightnessGrid[x][y] = 255
                    else:
                        if randint(0, 1) == 0:
                            for y in range(self.columns):
                                self.angleGrid[x][y] = self.pinkAngle
                                self.brightnessGrid[x][y] = 255
                        else:
                            for y in range(self.columns):
                                self.angleGrid[x][y] = self.blueAngle
                                self.brightnessGrid[x][y] = 255
            else:
                for y in range(self.columns):
                    for x in range(self.rows):
                        if self.brightnessGrid[x][y] > 16:
                            self.brightnessGrid[x][y] -= 16

        for y in range(self.columns):
            for x in range(self.rows):
                if self.angleGrid[x][y] == -1:
                    dcfurs.set_pixel(x, y, 0xff)
                else:
                    dcfurs.set_pix_hue(x, y, self.angleGrid[x][y],
                                       self.brightnessGrid[x][y])
示例#21
0
def create_floor():
    for point in range(18):
        dcfurs.set_pixel(point, 5, game_brightness)
示例#22
0
def draw_score(score):
    score_str = "{0:b}".format(score)
    start = (dcfurs.ncols - len(score_str)) - 1
    for i in range(len(score_str)):
        if score_str[i] == '1':
            dcfurs.set_pixel(start + i, 0, game_brightness)
示例#23
0
    def draw(self):
        if self.boopSwipe:
            if self.boopDirection == 0:
                for x in range(self.rows):
                    self.boopRow(x)
                self.boopSwipeInterval += 1
                if self.boopSwipeInterval >= self.columns:
                    self.boopSwipeInterval = 0
                    self.boopSwipe = False
                    self.interval = 60
            elif self.boopDirection == 1:
                for x in range(self.rows):
                    self.boopRow(x)
                self.boopSwipeInterval -= 1
                if self.boopSwipeInterval < 0:
                    self.boopSwipeInterval = 0
                    self.boopSwipe = False
                    self.interval = 60
            elif self.boopDirection == 2:
                for y in range(self.columns):
                    self.boopColumn(y)
                self.boopSwipeInterval += 1
                if self.boopSwipeInterval >= self.rows:
                    self.boopSwipeInterval = 0
                    self.boopSwipe = False
                    self.interval = 60
            elif self.boopDirection == 3:
                for y in range(self.columns):
                    self.boopColumn(y)
                self.boopSwipeInterval -= 1
                if self.boopSwipeInterval < 0:
                    self.boopSwipeInterval = 0
                    self.boopSwipe = False
                    self.interval = 60

        if self.sparkleIncrease:
            self.sparkleStep += 8
            if self.sparkleStep > 127:
                self.sparkleStep = 127
                self.sparkleIncrease = False

        else:
            self.sparkleStep -= 8
            if self.sparkleStep < 0:
                self.sparkleStep = 0
                self.sparkleIncrease = True
        for y in range(self.columns):
            for x in range(self.rows):
                if self.grid[x][y] == 1:
                    if randint(0, 2) == 0:
                        if self.boopSwipe:
                            dcfurs.set_pix_hue(x, y, self.pinkAngle, 255)
                        else:
                            dcfurs.set_pix_hue(x, y, self.pinkAngle,
                                               randint(64, 255))
                elif self.grid[x][y] == 2:
                    if randint(0, 2) == 0:
                        if self.boopSwipe:
                            dcfurs.set_pix_hue(x, y, self.blueAngle, 255)
                        else:
                            dcfurs.set_pix_hue(x, y, self.blueAngle,
                                               randint(64, 255))
                elif self.grid[x][y] >= 3:
                    dcfurs.set_pixel(x, y, 0xFF)
                    self.grid[x][y] += 1
                    if self.grid[x][y] > self.whiteDuration:
                        if randint(0, 1) == 0:
                            self.grid[x][y] = 1
                        else:
                            self.grid[x][y] = 2
                else:
                    dcfurs.set_pix_hue(x, y, 0, 0)

        if not self.boopSwipe:
            rx = randint(0, self.rows - 1)
            ry = randint(0, self.columns - 1)
            self.grid[rx][ry] = 3