コード例 #1
0
def blerx(args):
    for x in args:
        ## Locate an optional value given by an '='
        nv = x.split('=', 1)
        name = nv[0]
        value = nv[1] if len(nv) > 1 else None

        ## Handle the received stuff.
        if name == 'emote':
            ## Select a random emote.
            if (not value) or (value == 'random'):
                emote.random()
                pyb.delay(2500)
            ## Parse a specific emote to draw.
            else:
                emstr = ubinascii.unhexlify(value).decode("ascii")
                emote.render(emstr)
                pyb.delay(2500)
        if name == 'awoo':
            ## Someone started a howl
            msg = animations.scroll(" AWOOOOOOOOOOOOOO")
            delay = 0
            while delay < 5000:
                msg.draw()
                pyb.delay(msg.interval)
                delay += msg.interval
コード例 #2
0
ファイル: main.py プロジェクト: josephyi/dcfurs-badge-dc27
def check_ble():
    if not badge.ble:
        return
    
    flags = badge.ble.read(badge.ble.REG_FLAGS)
    if flags & badge.ble.FLAG_EMOTE:
        ## Remote emote extravaganza!
        value = badge.ble.read16(badge.ble.REG_EMOTE)
        color = badge.ble.color()
        if (value):
            try:
                emote.render(chr(value & 0xff) + chr(value >> 8), color)
            except Exception:
                emote.random(color)
        else:
            emote.random(color)
        pyb.delay(2500)

    if flags & badge.ble.FLAG_AWOO:
        ## Someone started a howl
        msg = animations.scroll(" AWOOOOOOOOOOOOOOOO")
        delay = 0
        while delay < 5000:
            msg.draw()
            pyb.delay(msg.interval)
            delay += msg.interval
コード例 #3
0
    def draw(self):
        ## Check for a win condition
        if (self.z[self.y][self.x] == MAZE_FINISH):
            if not self.wincount:
                emote.render("^.^")
                return
            else:
                self.wincount -= 1
        ## Automatically solve the maze
        elif self.autosolve:
            if (self.counter & 3) == 3:
                ## Move once every 4 ticks.
                dx, dy = dirxy(self.z[self.y][self.x], magnitude=1)
                self.x += dx
                self.y += dy
        ## Let the user solve it with the accelerometer.
        elif ((self.counter & 1) == 0):
            ## Read and translate the accelerometer orientation
            ax = -badge.imu.y()
            ay = badge.imu.x()

            ## Move the cursor if a sufficiently assertive tilt is detected.
            if (ax * ax + ay * ay) > 75:
                dx, dy = (0, 0)
                if (ax > 4):
                    dx = 1
                elif (ax < -4):
                    dx = -1
                if (ay > 4):
                    dy = 1
                elif (ay < -4):
                    dy = -1

                ## Prefer movement along the X-axis
                if (abs(ax) > abs(ay)):
                    if (self.z[self.y][self.x + dx] != MAZE_WALL):
                        self.x += dx
                    elif (self.z[self.y + dy][self.x] != MAZE_WALL):
                        self.y += dy
                ## Prefer movement on the Y-axis
                else:
                    if (self.z[self.y + dy][self.x] != MAZE_WALL):
                        self.y += dy
                    elif (self.z[self.y][self.x + dx] != MAZE_WALL):
                        self.x += dx

        ## Redraw
        self.counter += 1
        self.blink = not self.blink
        self.render(self.x - 3, self.y - 3)
コード例 #4
0
ファイル: maze.py プロジェクト: TheSkorm/dc26-fur-scripts
    def draw(self):
        ## Check for a win condition
        if self.z[self.y][self.x] == MAZE_FINISH:
            if not self.wincount:
                emote.render("^.^")
                return
            else:
                self.wincount -= 1
        ## Automatically solve the maze
        elif self.autosolve:
            if (self.counter & 3) == 3:
                ## Move once every 4 ticks.
                dx, dy = dirxy(self.z[self.y][self.x], magnitude=1)
                self.x += dx
                self.y += dy

        ## Redraw
        self.counter += 1
        self.blink = not self.blink
        self.render(self.x - 3, self.y - 3)