Пример #1
0
 def render(self):
     glEnable (GL_BLEND)
     glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
     w, h = self.current_anim.size
     glPushMatrix()
     glTranslatef(self.hotspot[0], self.hotspot[1], 0)
     get_screen().bind_texture(self.current_anim._id)
     glColor4f(self._color[0] / 255., self._color[1] / 255., self._color[2] / 255., self._alpha)
     glBegin(GL_QUADS)
     #glTexCoord2f(self._current_frame * 1.0 / self.nbframes, 0.0)
     glTexCoord2f(0.0, 0.0)
     glVertex2f(0, 0)
     #glTexCoord2f((self._current_frame + 1) * 1.0 / self.nbframes, 0.0)
     glTexCoord2f(1.0, 0.0)
     glVertex2f(w, 0)
     glColor4f(self._color[0] / 255., self._color[1] / 255., self._color[2] / 255., self._alpha)
     #glTexCoord2f((self._current_frame + 1)* 1.0 / self.nbframes, 1.0)
     glTexCoord2f(1.0, 1.0)
     glVertex2f(w, h)
     #glTexCoord2f(self._current_frame * 1.0 / self.nbframes, 1.0)
     glTexCoord2f(0.0, 1.0)
     glVertex2f(0, h)
     glEnd()
     #glTranslatef(-self.hotspot[0], -self.hotspot[1], 0)
     glPopMatrix()
Пример #2
0
 def render(self):
     glEnable(GL_BLEND)
     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
     w, h = self.current_anim.size
     glPushMatrix()
     glTranslatef(self.hotspot[0], self.hotspot[1], 0)
     get_screen().bind_texture(self.current_anim._id)
     glColor4f(self._color[0] / 255., self._color[1] / 255.,
               self._color[2] / 255., self._alpha)
     glBegin(GL_QUADS)
     #glTexCoord2f(self._current_frame * 1.0 / self.nbframes, 0.0)
     glTexCoord2f(0.0, 0.0)
     glVertex2f(0, 0)
     #glTexCoord2f((self._current_frame + 1) * 1.0 / self.nbframes, 0.0)
     glTexCoord2f(1.0, 0.0)
     glVertex2f(w, 0)
     glColor4f(self._color[0] / 255., self._color[1] / 255.,
               self._color[2] / 255., self._alpha)
     #glTexCoord2f((self._current_frame + 1)* 1.0 / self.nbframes, 1.0)
     glTexCoord2f(1.0, 1.0)
     glVertex2f(w, h)
     #glTexCoord2f(self._current_frame * 1.0 / self.nbframes, 1.0)
     glTexCoord2f(0.0, 1.0)
     glVertex2f(0, h)
     glEnd()
     #glTranslatef(-self.hotspot[0], -self.hotspot[1], 0)
     glPopMatrix()
Пример #3
0
 def load(self):
     if self.loaded: return
     self._size, self._data, self.__id, mode = self.pool.load_image(
         self.name)
     glBindTexture(self._id)
     get_screen().bind_texture(self._id)
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
                     GL_LINEAR_MIPMAP_NEAREST)
     if mode == GL_RGB:
         # Only this function works...
         gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, self._size[0],
                           self._size[1], GL_RGBA, GL_UNSIGNED_BYTE,
                           self.data)
         # glTexImage2D(GL_TEXTURE_2D, 1, 1, size[0], size[1], 0, GL_COLOR_INDEX, GL_UNSIGNED_BYTE, data)
         # gluBuild2DMipmaps(GL_TEXTURE_2D, 4, size[0], size[1], GL_COLOR_INDEX, GL_UNSIGNED_BYTE, data)
     else:
         gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, size[0], size[1],
                           GL_RGBA, GL_UNSIGNED_BYTE, self.data)
     self.frame_width = self._size[0] / self.nbframes
     self.loaded = True
     for i in xrange(self.nbframes):
         self.frames.append((self.size, self.data, self._id))
Пример #4
0
    def build(self):
        if self.loaded: return
        frames = []
        for i in self.filenames:
            size, data, _id, mode = self.pool.load_image(i)
            frames.append((size, data, _id))
            get_screen().bind_texture(_id)
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
                            GL_LINEAR_MIPMAP_NEAREST)
            if mode == GL_RGB:
                gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, size[0], size[1],
                                  GL_RGBA, GL_UNSIGNED_BYTE, data)
                #glTexImage2D(GL_TEXTURE_2D, 1, 1, size[0], size[1], 0, GL_COLOR_INDEX, GL_UNSIGNED_BYTE, data)
                #gluBuild2DMipmaps(GL_TEXTURE_2D, 4, size[0], size[1], GL_COLOR_INDEX, GL_UNSIGNED_BYTE, data)
            else:
                gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, size[0], size[1],
                                  GL_RGBA, GL_UNSIGNED_BYTE, data)
        self.loaded = True
        self.frames = frames
        self.nbframes = len(self.filenames)
        self.nb_frames = len(self.filenames)

        for i in xrange(self.virtual_frames - len(self.orders)):
            if self.nb_frames:
                self.orders.append(i % self.nb_frames)
            else:
                self.orders.append(0)

        for i in xrange(self.virtual_frames - len(self.delays)):
            self.delays.append(100)

        for i in xrange(self.virtual_frames - len(self.hotspots)):
            self.hotspots.append(Point(0, 0))

        for i in xrange(self.virtual_frames - len(self.move_offsets)):
            self.move_offsets.append(Point(0, 0))
Пример #5
0
def find_game2(rgb, res=200, mode='x'):
    """Find a game using lines of color. Primarily for black.
    """
    lines = color.find_lines(rgb, 0, screen.get_screen(None, False, True),
                             res, mode)
    d = []
    dAvg = 0
    for l in lines:
        val = dist(l[0], l[1])
        if val > 1:
            d.append(val)
            dAvg += val
    dAvg /= float(len(d))
    begin = 0
    end = 0
    for i in xrange(len(lines)):
        if dist(lines[i][0], lines[i][1]) > dAvg:
            begin = lines[i][0]
            break
    for i in reversed(xrange(len(lines))):
        if dist(lines[i][0], lines[i][1]) > dAvg:
            end = lines[i][1]
            break
Пример #6
0
def main(argv):
    locale.setlocale(locale.LC_ALL, 'de_DE.UTF-8')

    if "--webserver" in argv:
        run_webserver()
        return 0

    if "--stats" in argv:
        stats_send()
        return 0

    screen = get_screen()
    clock = pygame.time.Clock()

    drinks_manager = DrinksManager()
    DrinksManager.set_instance(drinks_manager)

    global screen_manager
    screen_manager = ScreenManager(screen)
    ScreenManager.set_instance(screen_manager)

    init_db()

    # Barcode Scanner #
    barcode_worker = BarcodeWorker()
    barcode_thread = threading.Thread(
        target=run_barcode_reader,
        args=(barcode_worker,)
    )
    barcode_thread.daemon = True
    barcode_thread.start()

    # webserver needs to be a main thread #
    web_thread = subprocess.Popen([sys.argv[0], "--webserver"])

    event_thread = threading.Thread(
        target=handle_events
    )
    event_thread.daemon = True
    event_thread.start()

    stats_thread = threading.Thread(
        target=stats_loop
    )
    stats_thread.daemon = True
    stats_thread.start()

    if env.is_pi():
        os.system("rsync -a sounds/ pi@pixelfun:sounds/ &")

    t = 0
    done = False

    while not done:
        dt = clock.tick(config.FPS) / 1000.0
        t += dt

        current_screen = screen_manager.get_active()

        screen.fill((0, 0, 0))
        current_screen.render(dt)

        pygame.display.flip()

        events = pygame.event.get()
        for e in events:
            e.t = t
            e.dt = dt
            if e.type == pygame.QUIT or (e.type == pygame.KEYDOWN and e.key == pygame.K_ESCAPE):
                done = True
                break
            event_queue.put(e, True)

    web_thread.terminate()
    web_thread.wait()

    return 0
Пример #7
0
def get_rgb(pos):
    display = screen.get_screen(None, False, True)
    return display.getpixel(pos)
Пример #8
0
 # coding=utf-8
import pygame
from threading import Thread

from pygame.locals import *
from screen import get_screen
from screens.screen_manager import ScreenManager


from drinks_log.log import Log as DrinksLog

from webserver.webserver import run as run_webserver


screen = get_screen()
screen_manager = ScreenManager(screen)
ScreenManager.set_instance(screen_manager)


##### Drinks log #####

def append_label(text):
    print text

log = DrinksLog()
log.register_handler(append_label)

webserver_thread = Thread(
    target=run_webserver,
    args=(log,)
)
Пример #9
0
import pygame
import screen
img = pygame.image.load("mr_brown.png")

screen = screen.get_screen()

i = 0


def goldencut(base):
    return base * 0.382


def middle(base):
    return round(base * 0.5, 0)


while True:
    events = pygame.event.get()
    mouse_pos = pygame.mouse.get_pos()

    screen.fill((246, 198, 0))  # fill screen with an rgb color

    screen.blit(img, (middle(480) - 20, goldencut(800) - 20))

    for event in events:
        print event
        if event.type == pygame.MOUSEBUTTONDOWN:
            if pygame.Rect((middle(480) - 20, goldencut(800) - 20),
                           (40, 40)).collidepoint(
                               mouse_pos
Пример #10
0
import pygame
import screen
img = pygame.image.load("mr_brown.png")

screen = screen.get_screen()

i=0

def goldencut (base):
    return base * 0.382

def middle (base):
    return round (base * 0.5, 0)

while True:
    events = pygame.event.get()
    mouse_pos = pygame.mouse.get_pos()

    screen.fill( (246, 198, 0) ) # fill screen with an rgb color

    screen.blit(
        img,
        (middle(480)-20, goldencut(800)-20)
    )

    for event in events:
        print event
        if event.type == pygame.MOUSEBUTTONDOWN:
            if pygame.Rect(
                (middle(480)-20, goldencut(800)-20),
                (40, 40)
Пример #11
0
def main(argv):
    locale.setlocale(locale.LC_ALL, 'de_DE.UTF-8')

    if "--webserver" in argv:
        run_webserver()
        return 0

    if "--stats" in argv:
        stats_send()
        return 0

    screen = get_screen()
    clock = pygame.time.Clock()

    drinks_manager = DrinksManager()
    DrinksManager.set_instance(drinks_manager)

    global screen_manager
    screen_manager = ScreenManager(screen)
    ScreenManager.set_instance(screen_manager)

    init_db()

    ##### Barcode Scanner #####
    barcode_worker = BarcodeWorker()
    barcode_thread = threading.Thread(target=run_barcode_reader,
                                      args=(barcode_worker, ))
    barcode_thread.daemon = True
    barcode_thread.start()

    ##### webserver needs to be a main thread #####
    web_thread = subprocess.Popen([sys.argv[0], "--webserver"])

    event_thread = threading.Thread(target=handle_events)
    event_thread.daemon = True
    event_thread.start()

    stats_thread = threading.Thread(target=stats_loop)
    stats_thread.daemon = True
    stats_thread.start()

    os.system("rsync -a sounds/ pi@pixelfun:sounds/ &")

    t = 0
    dt = 0
    done = False
    while not done:
        dt = clock.tick(config.FPS) / 1000.0
        t += dt

        current_screen = screen_manager.get_active()

        screen.fill((0, 0, 0))
        current_screen.render(t, dt)

        pygame.display.flip()

        events = pygame.event.get()
        for e in events:
            e.t = t
            e.dt = dt
            if e.type == pygame.QUIT or (e.type == pygame.KEYDOWN
                                         and e.key == pygame.K_ESCAPE):
                done = True
                break
            event_queue.put(e, True)
    web_thread.terminate()
    web_thread.wait()
    return 0