Beispiel #1
0
#Sends webcam feed to flaschen-taschen
#writen by Sean Gray
#Questions?Comments? Email:[email protected]

#requires intailation of opencv library for webcam processing
import numpy as nb
import cv2
import flaschen
import sys

UDP_IP= 'localhost'
UDP_PORT= 1337
ft = flaschen.Flaschen(UDP_IP,UDP_PORT,45,35)
cam=cv2.VideoCapture(0)
cam.set(3, 45)
cam.set(4, 35)

while(True):
    work,frame=cam.read() # work is a boolean if it worked, frame has data
    #Scales image to flaschen size
    r = 35.0 / frame.shape[1]
    dim = (35, int(frame.shape[0] * r))
    resized=cv2.resize(frame, dim,interpolation = cv2.INTER_AREA);
    #opencv stores in 3 dimention lists of bgr
    #converts to rgb and sets each pixel
    for x in xrange(0,ft.height):
        for y in xrange(0,dim[1]):
            b = (resized[y][x][0]);
            g = (resized[y][x][1]);
            r = (resized[y][x][2]);
            color=(r,g,b)
                currTS = float(entry["ts"])        
            
                if(self.lastTS<currTS):
                    self.lastTS=currTS
                    self.cmdQueue.put(entry)
            time.sleep(0.25)            
    def getCommands(self):
        return self.cmdQueue

host = os.getenv("FT_HOST","ft")
port = int(os.getenv("FT_PORT","1337"))
display_width = int(os.getenv("FT_WIDTH","45"))
display_height = int(os.getenv("FT_HEIGHT","35"))

flaschen_conn = flaschen.Flaschen(host,port,display_width,display_height, layer=15)

shouldExit=False
importlib.import_module("commands.color")
foo =commands.color.Command(display_width,display_height)
commandClasses = {}
for importer, modname, ispkg in pkgutil.walk_packages(path=commands.__path__,
                                                      prefix=commands.__name__+'.',
                                                      onerror=lambda x: None):
    mod = importlib.import_module(modname)
    classType = getattr(mod, "Command")
    commandClasses[modname] = classType(display_width,display_height)


slackThread = SlackThread()
slackThread.start()
Beispiel #3
0
import flaschen
import sounddevice as sd
import numpy
import time
import sys

ROWS = 32
COLS = 512
MAX = 0.25
ON = (255, 255, 255)
OFF = (1, 1, 1)

sd.default.samplerate = 44100
sd.default.channels = 1

ft = flaschen.Flaschen('10.1.253.237', 1337, 512, 32, transparent=False)


def display(data):
    pixels = []
    data = [x * ROWS / MAX for x in data]
    for y in range(ROWS // 2):
        for x in range(COLS):
            if data[x] + ROWS // 2 <= y:
                pixels.append(True)
            else:
                pixels.append(False)

    for y in range(ROWS // 2, ROWS):
        for x in range(COLS):
            if y <= data[x] + ROWS // 2:
Beispiel #4
0
import flaschen
import time
import random
import copy

UDP_IP = 'localhost'
UDP_PORT = 1337

ft = flaschen.Flaschen(UDP_IP, UDP_PORT, 45, 35,transparent=True)
piecePattern=[[' ','x','x','x',' '],
              ['x','x','x','x','x'],
              ['x','x','x','x','x'],
              ['x','x','x','x','x'],
              [' ','x','x','x',' ']]

def main():
    board=[[0 for col in range(7)] for row in range(6)]
    winner = False
    player=1
    while(True):
        bPrint(board)
        fPrint(board)
        winLoc=check(board)
        if(winLoc != (0,0,-1)):
            break
        player=opponent(player)
        if player==2:
            board=move(board,player)
        else:
            board=aiMove(board,player)
    won(board,winLoc)
Beispiel #5
0
import alsaaudio
import numpy as np
import collections
import sys
import time
import math
import flaschen

rows = 32
cols = 512

ON = (0,255,0)
RED = (255,0,0)
OFF = (0,0,0)

ft = flaschen.Flaschen('10.1.255.209', 1337, 512, 32, transparent=True, layer=2)

plotMax = 3
offset = 9
plotStart = 0
plotEnd = 1024
periodsize = 1500
bufferLength = 4800
sampleRate = 44100
buffer = collections.deque(bufferLength*[0], bufferLength)

inp = alsaaudio.PCM(alsaaudio.PCM_CAPTURE, alsaaudio.PCM_NORMAL, device='default')
inp.setchannels(1)
inp.setrate(sampleRate)
inp.setformat(alsaaudio.PCM_FORMAT_S16_LE)
periodsize = inp.setperiodsize(periodsize)
Beispiel #6
0
    async def onJoin(self, details):
        """
        WAMP calls this after successfully joining the realm.
        :param details: Provides information about
        :return: None
        """

        self.screen = flaschen.Flaschen('scootaloo.hackafe.net', 1337, WIDTH,
                                        HEIGHT, 16, True)
        self.powerups = []
        self.entities = []

        # Subscribe to all necessary things
        await self.subscribe(self.on_player_join,
                             'game.' + GAME_ID + '.player.join')
        await self.subscribe(self.on_player_leave,
                             'game.' + GAME_ID + '.player.leave')
        await self.subscribe(self.game_register, 'game.request_register')
        await self.game_register()

        while True:
            # Wait until there are two players
            while len(self.players) < 2:
                for player in self.players.values():
                    player.draw(self.screen)
                self.screen.send()
                await asyncio.sleep(.5)

            # Draw out everyone's dots for a couple seconds
            for player in self.players.values():
                player.brightness = .1
                await self.set_lights(player)
                player.draw(self.screen)
            self.screen.send()

            await asyncio.sleep(2)
            self.screen.clear()

            next_powerup = 0
            powerup_count = len(self.players) + 5
            # Move players until only one (or none) are left
            while sum((not p.dead for p in self.players.values())) > 1:
                # approx every 10 seconds
                if time.time() >= next_powerup:
                    next_powerup = time.time() + 5
                    for _ in range(powerup_count):
                        x, y = random.randrange(WIDTH), random.randrange(
                            HEIGHT)
                        self.powerups.append(random.choice(POWERUPS)(x, y))
                    powerup_count = 1

                for player in self.players.values():
                    player.draw(self.screen)
                    for _ in range(player.moves):
                        await player.move(self.players.values(), self.powerups,
                                          self.entities)
                    #self.publish(target, 0, 2, "Power: " + (str(player.powerup) if player.powerup else 'None'))
                    if player.dead and player.brightness is not None:
                        await self.set_lights(player)
                        player.brightness = None

                for powerup in self.powerups:
                    powerup.draw(self.screen)

                for entity in self.entities:
                    entity.draw(self.screen)

                self.screen.send()
                self.screen.clear()

                await asyncio.sleep(1 / TICK_RATE)

            # Flash the winner's strings
            while any((not player.nommed() for player in self.players.values()
                       if player.dead)):
                for on in (True, True, True, False, False, False, False):
                    self.screen.clear()
                    for player in list(self.players.values()):
                        if not player.dead:
                            player.brightness = .1 if on else 0

                            if on:
                                self.publish('badge.' + str(player.badge_id) +
                                             '.text',
                                             0,
                                             24,
                                             "You win!!!",
                                             style=1)
                                await self.set_lights(player)
                                player.draw(self.screen)
                            else:
                                self.publish('badge.' + str(player.badge_id) +
                                             '.text',
                                             0,
                                             24,
                                             "          ",
                                             style=1)
                                await self.set_lights(player)

                        else:
                            player.nom()
                            player.draw(self.screen)

                    self.screen.send()
                    await asyncio.sleep(1 / TICK_RATE)

            # Update the players' text
            for player in self.players.values():
                if not player.dead:
                    player.wins += 1

                player.plays += 1
                target = 'badge.{}.text'.format(player.badge_id)
                self.publish(target, 0, 0, "Plays: " + str(player.plays))
                self.publish(target, 0, 1, "Wins:  " + str(player.wins))

            self.screen.clear()
            self.screen.send()

            for player in self.players.values():
                player.reset()

            self.powerups = []
            self.entities = []
Beispiel #7
0
            print(fileobj.name, end=' ')
        print(image.format, f"{image.size} x {image.mode}")
        image.thumbnail(size, Image.ANTIALIAS)
        background = Image.new('RGBA', size, (0, 0, 0, 0))
        background.paste(image, (int(
            (size[0] - image.size[0]) / 2), int(
                (size[1] - image.size[1]) / 2)))
        return background


# Load default image
DEFAULT_IMAGE = createMatrixImage(default_image_file)
print(DEFAULT_IMAGE)

# FIXME: handle netword errors better
flaschen_client = flaschen.Flaschen(FLASCHEN_SERVER, FLASCHEN_PORT,
                                    FLASCHEN_COLS, FLASCHEN_ROWS)

# Configure MQTT broker connection
mqttc = mqtt.Client()

# register callbacks
mqttc.on_connect = on_connect
mqttc.on_message = on_message

if MQTT_CONF.get("use_tls"):
    tls_conf = MQTT_CONF.get("tls")
    print("Using TLS config", tls_conf)
    # assumes full valid TLS configuration for paho lib
    if tls_conf:
        mqttc.tls_set(
            ca_certs=tls_conf["ca_certs_path"],