Esempio n. 1
0
def run():
    screen = bbxrun.screen
    screen.fill_screen(0x337733)

    xpos = 20
    image = Image(screen.screen_ctx)
    image.load(IMAGE_PATH)
    image.draw(xpos, 15, screen.screen_buf, scale=1/4)

    color = 0xff5511
    fontsize = 48
    leading = 70
    ypos = 200
    for text in [
        'BBX-Python!',
        'The time is %s' % datetime.datetime.now(),
        'Python ' + sys.version.split('\n', 1)[0],
        'Visit http://microcode.ca/bbx-python/ to learn more.',
        ]:
        draw_text(xpos, ypos, text, fontsize=fontsize, color=color)
        ypos += leading
        fontsize = 36
        color = 0xffffff

    time.sleep(3)
Esempio n. 2
0
def run():
    import bbxrun
    screen = bbxrun.screen

    image = Image(screen.screen_ctx)
    image.load(IMAGE_PATH)

    # prepare window to receive image in blit
    screen_buf = screen.screen_buf

    rect = (c_int * 4)()
    rc = screen_get_window_property_iv(screen.screen_win, SCREEN_PROPERTY_BUFFER_SIZE,
        cast(byref(rect, 2 * sizeof(c_int)), POINTER(c_int)))
    print('rect', list(rect))
    if rc: raise RuntimeError(rc)

    start = time.time()
    prev = time.time()
    blits = posts = 0
    scale = 1/4
    DURATION = 3.5
    while time.time() - start < DURATION:
        x = random.randint(0, rect[2] - int(image.width * scale))
        y = random.randint(0, rect[3] - int(image.height * scale))
        image.draw(x, y, screen_buf, scale=scale)

        blits += 1

        # max refresh rate 60Hz
        if time.time() - prev >= 1/60:
            prev = time.time()
            rc = screen_post_window(screen.screen_win, screen_buf, 1, rect, 0)
            if rc: raise RuntimeError(rc)
            posts += 1

    print('blits=%s posts=%s fps=%.1f' % (blits, posts, posts / DURATION))
Esempio n. 3
0
def run():
    import bbxrun

    screen = bbxrun.screen

    global _sound_thread, _sound_event
    if not _sound_thread:
        _sound_thread = threading.Thread(target=_sound_thread_run)
        _sound_thread.daemon = True
        _sound_event = threading.Event()
        _sound_thread.start()

    image = Image(screen.screen_ctx)
    image.load(IMAGE_PATH)

    # find size of window
    rect = (c_int * 4)()
    rc = screen_get_window_property_iv(
        screen.screen_win, SCREEN_PROPERTY_BUFFER_SIZE, cast(byref(rect, 2 * sizeof(c_int)), POINTER(c_int))
    )
    print("rect", list(rect))
    if rc:
        raise RuntimeError(rc)

    start = time.time()
    framecount = 0
    scale = 1 / 4
    DURATION = 10.0

    xmin = 0
    xmax = rect[2] - int(image.width * scale)
    ymin = 50
    ymax = rect[3] - int(image.height * scale)

    x = 0
    y = ymin

    vx = 15
    # ~ gravity = 9.98
    GFACTOR = 70

    timebase = start
    while time.time() - start < DURATION:
        screen.fill_screen(0xFF0000FF)
        image.draw(x, ymax if y > ymax else y, screen.screen_buf, scale=scale)

        rc = screen_post_window(screen.screen_win, screen.screen_buf, 1, rect, 0)
        if rc:
            raise RuntimeError(rc)
        framecount += 1

        # update based on current values
        x += vx

        # account for physics
        elapsed = time.time() - timebase

        delta = math.pow(abs(elapsed) * GFACTOR, 2)
        # ~ print('> %.3fs: %d pow %.1f %.1f' % (elapsed, y, elapsed * gravity, delta))
        y = ymin + delta

        if x > xmax:
            x = xmax - (x - xmax)
            vx = -vx

        elif x < xmin:
            x = xmin + (xmin - x)
            vx = -vx

        if y > ymax and elapsed > 0:
            timebase += elapsed * 2
            sound()

    print("fps=%.1f" % (framecount / DURATION))