コード例 #1
0
ファイル: webapp.py プロジェクト: derchrisuk/flipdots
def png():
    from PIL import Image
    if request.method == 'POST':
        png = request.form['png']
        png = png.split(",", 1)[1]
        im = Image.open(BytesIO(base64.b64decode(png)))
        im.rotate(90)
        if im.format == "GIF":
            while True:
                try:
                    imageArray = [[0 for x in range(wandwidth)]
                                  for y in range(wandheight)]
                    for y in range(wandheight):
                        for x in range(wandwidth):
                            imageArray[y][x] = 1 if im.getpixel(
                                (x, y))[0] == 255 else 0
                    image = FlipdotImage(imageArray)
                    im.seek(im.tell() + 1)
                    matrix.show(image)
                except EOFError:
                    break
        else:
            imageArray = [[0 for x in range(wandwidth)]
                          for y in range(wandheight)]
            for y in range(wandheight):
                for x in range(wandwidth):
                    imageArray[y][x] = 1 if im.getpixel(
                        (x, y))[0] == 255 else 0
            image = FlipdotImage(imageArray)
            matrix.show(image)
        return ""
    else:
        return redirect("/")
コード例 #2
0
ファイル: pong.py プロジェクト: derchrisuk/flipdots
 def loop(self):
     playing = False
     while not self.stop:
         t = time()
         new_game = self.step()
         if new_game:
             playing = False
             self.ball.stop()
         image = self.generatePongImage()
         if not playing:
             playing = all([x.active for x in self.players])
             if playing:
                 self.ball.change_direction((1, 0))
         if self.invert:
             pass
         if self.flipdot_out:
             flipImage = FlipdotImage(image.T)
             score_string = "%d - %d" % (self.players[0].score,
                                         self.players[1].score)
             flipImage.blitTextAtPosition(score_string,
                                          xPos=self.get_center()[0] - 2 *
                                          (len(score_string) - 1),
                                          yPos=2 * round(self.size[1] / 12))
             total_score_string = "%d - %d" % (self.players[0].total_score,
                                               self.players[1].total_score)
             flipImage.blitTextAtPosition(total_score_string,
                                          xPos=self.get_center()[0] - 2 *
                                          (len(total_score_string) - 1),
                                          yPos=(round(self.size[1] / 12)))
             if not playing:
                 if not self.players[0].active:
                     flipImage.blitTextAtPosition(
                         "Press Left",
                         xPos=self.players[0].upper_right()[0] + 2,
                         yPos=self.size[1] -
                         self.players[0].upper_right()[1])
                 if not self.players[1].active:
                     flipImage.blitTextAtPosition(
                         "Press Left",
                         xPos=self.players[1].lower_left()[0] - 46,
                         yPos=self.size[1] -
                         self.players[1].upper_right()[1])
             self.flipmatrix.show(flipImage)
         if self.console_out:
             self.printImage(image)
         wait = (1. / self.speed) - (time() - t)
         if wait > 0:
             sleep(wait)
         else:
             print("Too slow!")
コード例 #3
0
ファイル: clock.py プロジェクト: muccc/flipdots
 def loop(self):
     oldImage = FlipdotImage(self.generateClockImage())
     try:
         while True:
             flipImage = FlipdotImage(self.generateClockImage())
             if (self.flipdot_out and
                 flipImage.serializeImageArray() != oldImage.serializeImageArray()):
                 self.matrix.show(flipImage)
                 oldImage = flipImage
             if self.run_once:
                 break
             sleep(self.update_interval)
     except KeyboardInterrupt:
         return
コード例 #4
0
def main_loop(sizex,
              sizey,
              udpHostsAndPorts=[],
              console_out=False,
              api_defaults=False,
              update_interval=0):
    if len(udpHostsAndPorts) != 0:
        flipdot_matrix = FlipdotMatrix(udpHostsAndPorts, (sizex, sizey))
        flipdot_out = True
    elif api_defaults:
        flipdot_matrix = FlipdotMatrix(imageSize=(sizex, sizey))
        flipdot_out = True
    else:
        flipdot_matrix = None
        flipdot_out = False

    pixel_matrix = generateEmptyMatrix(sizex, sizey)

    try:
        while True:
            pixel_matrix = step(pixel_matrix, sizex, sizey)
            if console_out:
                printToConsole(pixel_matrix, sizex, sizey)
            if flipdot_out:
                flipImage = FlipdotImage(
                    prepareMatrixForAPI(pixel_matrix, sizex, sizey))
                matrix.show(flipImage, sizex, sizey)
            sleep(update_interval)
    except KeyboardInterrupt:
        return
コード例 #5
0
def show(pixel_matrix, flipdot_matrix, flipdot_out, console_out, sizex, sizey):
    if flipdot_out:
        flipImage = FlipdotImage(
            prepareMatrixForAPI(pixel_matrix, sizex, sizey))
        addText(flipImage, sizex, sizey)
        flipdot_matrix.show(flipImage)
    if console_out:
        printToConsole(pixel_matrix, sizex, sizey)
コード例 #6
0
ファイル: webapp.py プロジェクト: derchrisuk/flipdots
def chess():
    imageArray = [[0 for x in range(wandwidth)] for y in range(wandheight)]
    for y in range(wandheight):
        for x in range(wandwidth):
            imageArray[y][x] = (x + y) % 2

    image = FlipdotImage(imageArray)
    matrix.show(image)
    return minipage("chess!")
コード例 #7
0
 def run(self):
     collision = False
     while not collision and not self.stop:
         if self.pause:
             sleep(1. / self.speed)
             continue
         collision = self.step()
         image = self.generateRaceImage()
         if self.invert:
             self.invertImage(image)
         if self.flipdot_out:
             flipImage = FlipdotImage(self.transpose(image))
             self.flipmatrix.show(flipImage)
         if self.console_out:
             self.printImage(image)
         sleep(1. / self.speed)
     self.lost = True
コード例 #8
0
ファイル: tron.py プロジェクト: muccc/flipdots
 def start(self):
     print("resetting game")
     self.image = FlipdotImage.newWhiteFlipdotImage(
         self.width, self.height)
     self.reset_white()
     for x in range(self.width):
         for y in range(TOP):
             self.set_pixel(x, y)
         self.set_pixel(x, self.height-1)
     for y in range(self.height):
         self.set_pixel(0,  y)
         self.set_pixel(self.width - 1, y)
     for player in self.players.values():
         player.reset()
         player.draw()
     self.image.blitTextAtPosition("join this game by dividuum", xPos=5, yPos=2)
     self.image.blitTextAtPosition("http://%s:%d/" % (MYIP, PORT), xPos=5, yPos=9)
     self.flush()
コード例 #9
0
 def start(self):
     print "resetting game"
     self.image = FlipdotImage.newWhiteFlipdotImage(
         self.width, self.height)
     self.reset_white()
     for x in xrange(self.width):
         for y in xrange(TOP):
             self.set_pixel(x, y)
         self.set_pixel(x, self.height-1)
     for y in xrange(self.height):
         self.set_pixel(0,  y)
         self.set_pixel(self.width - 1, y)
     for player in self.players.itervalues():
         player.reset()
         player.draw()
     self.image.blitTextAtPosition("join this game by dividuum", xPos=5, yPos=2)
     self.image.blitTextAtPosition("http://%s:%d/" % (MYIP, PORT), xPos=5, yPos=9)
     self.flush()
コード例 #10
0
 def loop(self):
     oldImage = FlipdotImage(self.generateClockImage())
     try:
         while True:
             flipImage = FlipdotImage(self.generateClockImage())
             if (self.flipdot_out and flipImage.serializeImageArray() !=
                     oldImage.serializeImageArray()):
                 self.matrix.show(flipImage)
                 oldImage = flipImage
             if self.run_once:
                 break
             sleep(self.update_interval)
     except KeyboardInterrupt:
         return
コード例 #11
0
ファイル: tron.py プロジェクト: muccc/flipdots
 def reset_white(self):
     black = FlipdotImage.newBlackFlipdotImage(self.width, self.height)
     self.matrix.show(black)
     white = FlipdotImage.newWhiteFlipdotImage(self.width, self.height)
     self.matrix.show(white)
コード例 #12
0
ファイル: tron.py プロジェクト: somakeit/flipdots
 def reset_white(self):
     black = FlipdotImage.newBlackFlipdotImage(self.width, self.height)
     self.matrix.show(black)
     white = FlipdotImage.newWhiteFlipdotImage(self.width, self.height)
     self.matrix.show(white)
コード例 #13
0
ファイル: webapp.py プロジェクト: derchrisuk/flipdots
def white():
    whiteImage = FlipdotImage.newWhiteFlipdotImage(wandwidth, wandheight)
    matrix.show(whiteImage)
    return minipage("whited all!")
コード例 #14
0
ファイル: webapp.py プロジェクト: derchrisuk/flipdots
def black():
    blackImage = FlipdotImage.newBlackFlipdotImage(wandwidth, wandheight)
    matrix.show(blackImage)
    return minipage("blacked all")
コード例 #15
0
ファイル: print_text.py プロジェクト: somakeit/smib-commands
from FlipdotAPI.FlipdotMatrix import FlipdotMatrix
from FlipdotAPI.FlipdotMatrix import FlipdotImage

WIDTH = 60
HEIGHT = 32

matrix = FlipdotMatrix(
    udpHostsAndPorts = [
        ("flipdot", 2323),
    ],
    imageSize = (WIDTH, HEIGHT),
    transposed = False,
)

while True:
    text = sys.stdin.readline().decode('utf-8')
    if text == "":
        break
    else:
        text = text.strip()
    
    textLength = FlipdotImage.getTextLength(text)
    if textLength > WIDTH:
        scroll = (WIDTH * 2) + textLength + 2
        for y in xrange(0, scroll, 2):
            matrix.showText(text, False, WIDTH - y, 1 )
            matrix.Send()
    else:
        matrix.showText(text, False, 0, 1 )
        matrix.Send()