示例#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 __init__(self):
     dcfurs.clear()
     self.interval = 15
     self.rows = 18
     self.columns = 7
     self.center_x = 9
     self.center_y = 3
     self.colorIndex = 0
     self.throbStep = 0
     self.throbIncrease = True
     self.angle = 360
     self.iterations = 0
     self.boopLock = False
     self.moveDirection = True
     self.boopIndex = 0
     self.boopAngles = [360, 120, 300, 180]
     self.angleCycleIterations = 4
     self.boopEasterEggIndex = 0
     self.boopEasterEggMax = 25
     self.throb_x = self.center_x - 1
     self.throb_y = self.center_y - 1
     self.evilPixels = [[0, 2], [0, 15], [0, 16], [1, 2], [1, 3], [1, 14],
                        [1, 15], [2, 3], [2, 4], [2, 13], [2, 14], [3, 3],
                        [3, 4], [3, 5], [3, 12], [3, 13], [3, 14], [4, 2],
                        [4, 3], [4, 4], [4, 5], [4, 6], [4, 11], [4, 12],
                        [4, 13], [4, 14], [4, 15], [5, 3], [5, 6], [5, 11],
                        [5, 14]]
示例#3
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
示例#4
0
def trysuspend():
    global evtime

    ## Do nothing if sleep is disabled
    timeout = settings.sleeptimeout
    if not timeout:
        return False

    ## Detect motion via the accelerometer
    dx = imu.x() - xyz[0]
    dy = imu.y() - xyz[1]
    dz = imu.z() - xyz[2]
    delta = (dx * dx) + (dy * dy) + (dz * dz)
    xyz[0] += dx
    xyz[1] += dy
    xyz[2] += dz
    if delta > (sensitivity * sensitivity):
        evtime = pyb.millis()
        return False

    ## Never suspend when USB VBus is present
    if vbus.value():
        evtime = pyb.millis()
        return False
    ## Don't sleep unless a timeout has elapsed.
    if (evtime + timeout) > pyb.millis():
        return False
    ## Turn off the display and go to deep sleep, with PA0 wakeup enabled.
    ble_enable.value(0)
    dcfurs.clear()
    pyb.standby(True)  # NOTE: pyb.standby API modified to enable PA0 wakeup.
示例#5
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()
示例#6
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)
示例#7
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()
示例#8
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
示例#9
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
示例#10
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
示例#11
0
 def __init__(self):
     dcfurs.clear()
     self.interval = 60
     self.rows = 18
     self.columns = 7
     self.colorIndex = 0
     self.sparkleStep = 0
     self.sparkleIncrease = True
     self.pinkAngle = 300
     self.blueAngle = 180
     self.iterations = 0
     self.sparkleStep = 0
     self.whiteDuration = 5
     self.boopType = 0
     self.boopSwipe = False
     self.boopSwipeInterval = 0
     self.initGrid()
示例#12
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()
示例#13
0
 def __init__(self):
   dcfurs.clear()
   self.interval=20
   self.rows=18
   self.columns=7
   self.center_x = 9
   self.center_y = 3
   self.eye_radius = 3
   self.colorIndex = 0
   self.superdark = [None] * 6
   self.dark = [None] * 6
   self.mid = [None] * 6
   self.bright = [None] * 6
   self.superdark[0] = self.mkColor(32, 0, 0)
   self.dark[0] = self.mkColor(64, 0, 0)
   self.mid[0] = self.mkColor(128, 0, 0)
   self.bright[0] = self.mkColor(255, 0, 0)
   self.superdark[1] = self.mkColor(32, 0, 32)
   self.dark[1] = self.mkColor(64, 0, 64)
   self.mid[1] = self.mkColor(128, 0, 128)
   self.bright[1] = self.mkColor(255, 0, 255)
   self.superdark[2] = self.mkColor(0, 32, 32)
   self.dark[2] = self.mkColor(0, 64, 64)
   self.mid[2] = self.mkColor(0, 128, 128)
   self.bright[2] = self.mkColor(0, 255, 255)
   self.superdark[3] = self.mkColor(0, 32, 0)
   self.dark[3] = self.mkColor(0, 64, 0)
   self.mid[3] = self.mkColor(0, 128, 0)
   self.bright[3] = self.mkColor(0, 255, 0)
   self.superdark[4] = self.mkColor(0, 32, 32)
   self.dark[4] = self.mkColor(0, 64, 64)
   self.mid[4] = self.mkColor(0, 128, 128)
   self.bright[4] = self.mkColor(0, 255, 255)
   self.superdark[5] = self.mkColor(32, 0, 32)
   self.dark[5] = self.mkColor(64, 0, 64)
   self.mid[5] = self.mkColor(128, 0, 128)
   self.bright[5] = self.mkColor(255, 0, 255)
   self.initGrid()
   self.x = self.center_x
   self.y = self.center_y
   self.iteration = 0
   self.maxIteration = 1
   self.direction = True
   self.drawEye(self.x, self.y)
示例#14
0
def trysuspend():
    global evtime

    ## Do nothing if sleep is disabled
    timeout = settings.sleeptimeout
    if not timeout:
        return False

    ## Never suspend when USB VBus is present
    if vbus.value():
        evtime = pyb.millis()
        return False
    ## Don't sleep unless a timeout has elapsed.
    if (evtime + timeout) > pyb.millis():
        return False
    ## Turn off the display and go to deep sleep, with PA0 wakeup enabled.
    ble_enable.value(0)
    dcfurs.clear()
    pyb.standby(True)  # NOTE: pyb.standby API modified to enable PA0 wakeup.
示例#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 __init__(self):
     dcfurs.clear()
     self.interval = 15
     self.rows = 18
     self.columns = 7
     self.center_x = 9
     self.center_y = 3
     self.colorIndex = 0
     self.throbStep = 0
     self.throbIncrease = True
     self.angle = 72
     self.iterations = 0
     self.boopLock = False
     self.moveDirection = True
     self.boopIndex = -1
     self.boopAngles = [360, 120, 300, 180]
     self.angleCycleIterations = 4
     self.boopEasterEggIndex = 0
     self.boopEasterEggMax = 25
     self.throb_x = self.center_x - 1
     self.throb_y = self.center_y - 1
示例#17
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)
示例#18
0
 def __init__(self):
     dcfurs.clear()
     self.interval = 10
     self.rows = 18
     self.columns = 7
     self.throb_x = 9
     self.throb_y = 2
     self.strobeAngle = 0
     self.pinkAngle = 300
     self.blueAngle = 180
     self.lastBeat = 0
     self.clearNext = False
     self.ticksPerBeat = 800
     self.boops = [0] * 4
     self.lastBoop = 0
     self.boopIndex = 0
     self.djMode = 0
     self.djMaxMode = 4
     self.djDuration = 25000
     self.lastTiltTimeout = 20
     self.lastCircleColor = 0
     self.djTicks = utime.ticks_add(utime.ticks_ms(), self.djDuration)
     self.nextBoopTimeout = 1500
     self.initGrid()
示例#19
0
from pyb import Timer
from pyb import Accel
from pyb import ExtInt
from pyb import I2C
from pyb import UART

##-----------------------------------------------
## LED Matrix Drivers
##-----------------------------------------------
import micropython
micropython.alloc_emergency_exception_buf(100)

## Bring up the LED matrix
pwmclk = Timer(1, freq=125000)
dcfurs.init(pwmclk)
dcfurs.clear()

##-----------------------------------------------
## Bluetooth Module
##-----------------------------------------------
ble_enable = Pin('BLE_EN', Pin.OUT_OD)
ble_enable.value(0)
pyb.delay(5)
ble_enable.value(1)
ble = UART(1, 115200)


##-----------------------------------------------
## Pushbutton Class
##-----------------------------------------------
class switch(Pin):