Exemplo n.º 1
0
def vmd_prepare_scene():
    """Change the lighting and background so it is the same for each image when rendering."""
    VMD.evaltcl("light 1 off")
    VMD.evaltcl("display shadows off")
    color_display = color.get_colormap("Display")
    color_display["Background"] = "white"
    color.set_colormap("Display", color_display)
    display.set(depthcue=0)
    display.update()
    display.update_ui()
Exemplo n.º 2
0
def vmd_render_scene(image_out,
                     image_size=[2000, 2000],
                     renderer="TachyonLOptiXInternal",
                     frame_idx=0):
    """
    Render the image using renderer with resolution image_size.
    """
    disp_default_size = display.get("size")
    # higher resolution
    display.set(size=image_size)
    display.update()
    display.update_ui()
    VMD.evaltcl("light 0 off")
    render.render(renderer, "{}.ppm".format(image_out))
    VMD.evaltcl("light 0 on")
    image = Image.open("{}.ppm".format(image_out))
    image.save("{}.png".format(image_out), format="PNG")
    #display.set(size=disp_default_size)
    display.update()
    display.update_ui()
    os.remove("{}.ppm".format(image_out))
Exemplo n.º 3
0
#!/usr/bin/env python3

import pygame, display, controls
from pygame.locals import *
from objectmanager import ObjectManager
#from gameobject import GameObject, Player

FPS = 60

# initialisation
fpsClock = pygame.time.Clock()
pygame.init()
objectmanager = ObjectManager()
window = display.initialise((None, None))
gameOver = False

# game loop
while (gameOver == False):
    #test for quit event
    for event in pygame.event.get():
        controls.handleEvent(event, objectmanager)
    #update the gameobjects
    objectmanager.update()
    #update graphics
    display.update(window, objectmanager.gameObjects)
    gameOver = objectmanager.gameOver()
    fpsClock.tick(FPS)
Exemplo n.º 4
0
def ioloop(dt):
    while True:
        time.sleep(dt / 1000)
        display.update(dt)
Exemplo n.º 5
0
    def play(self, level):
        self.load_level(level)
        self.init_display()
        display = self.display
        self._quit = False
        self._win = False
        self._ended = False
        timer = pygame.time.Clock()
        fcnt = 0

        while not self._quit:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    self._quit = True
                elif event.type == pygame.KEYDOWN:
                    key = event.key
                    if key == pygame.K_q:
                        self._quit = True
                    #elif key == pygame.K_r:
                    #    config.ENABLE_REFLECT = not config.ENABLE_REFLECT
                    #elif key == pygame.K_s:
                    #    config.ENABLE_SHADOW = not config.ENABLE_SHADOW
                elif event.type == pygame.MOUSEBUTTONDOWN:
                    if event.button == 4:
                        # scroll up, zoom in
                        self.camera.zoom_in()
                    elif event.button == 5:
                        # scroll down, zoom out
                        self.camera.zoom_out()
            # update logic
            if not self._ended and fcnt % config.DD == 0:
                # update player pos
                pressed = pygame.key.get_pressed()
                if self.player.is_ready():
                    for key in config.Dirs:
                        if pressed[key]:
                            direction = config.Dirs[key]
                            self.move_player(self.player, direction)
                            break
                    else:
                        self.player.rest()
                # recalculate lights
                for emitter in self.emitters:
                    emitter.calculate(self.field)
                    end = emitter.light.end
                    if end and not end.dying:
                        end.die()
                self.emitters = [x for x in self.emitters if x.alive]
                self.lights.redraw(self.emitters)
                for sp in display.sprites:
                    if hasattr(sp, 'update2'):
                        sp.update2()
                if self.player.dying:
                    self.end_game(False)
            # update display
            display.update(self.field)
            # tick
            timer.tick(config.FPS)
            clock.tick()
            if fcnt % config.FPS == 0: print clock.get_fps()
            fcnt += 1
Exemplo n.º 6
0
def start(task_name):
    """
    Display a timer counting up in minutes.
    Handle controls for when the user wants to store the task, exit without
    storing, or pause

    task_name -- a user defined string to identify task
    """

    # ensure directories exist
    database.init_directories()

    # To keep track of time spent
    last_time = 0
    delta = 0
    timer = 0

    # Create text elements
    header = "You have been doing " + task_name + " for "
    header_text = display.TextElement(header, 0)
    date_text = "0"
    time_text = display.TextElement(date_text, 1)
    break1 = display.TextElement("", 2)
    status = display.TextElement("RECORDING", 3)
    break2 = display.TextElement("", 4)

    # user control information
    instr_text_enter = "Press ENTER to end task and save"
    instr_text_p = "Press p to pause task"
    instr_text_q = "Press q to exit without saving task"
    instr1 = display.TextElement(instr_text_enter, 5)
    instr2 = display.TextElement(instr_text_p, 6)
    instr3 = display.TextElement(instr_text_q, 7)

    elements = [header_text, time_text, break1, status, break2, instr1, instr2, instr3]
    elements.sort()

    screen = display.init_display()

    display.update(screen, elements)

    paused = False

    last_time = datetime.now()

    # will loop until user exit
    while True:

        delta = datetime.now() - last_time
        last_time = datetime.now()
        if not paused:
            timer += delta.total_seconds()

        time_text.txt = make_time_string(timer)

        # Update the text
        display.update(screen, elements)

        # Get user input, if any
        inp = display.run(screen)

        if inp in ('q', 'Q'):
            display.end(screen)
            sys.exit(0)
        elif inp in ('p', 'P'):
            if paused:
                status.txt = 'RECORDING'
                paused = False
            else:
                status.txt = 'PAUSED'
                paused = True
        # ENTER key could be any one of these based on system
        elif inp in ('KEY_ENTER', '\n', '\r'):

            # Commit to file
            task_obj = database.TaskData(task_name, timer)
            database.store_task(task_obj)
            display.end(screen)
            sys.exit(0)

        # Let's not overwork the CPU
        sleep(0.01)

    display.end(screen)
Exemplo n.º 7
0
def show(date_str=None):
    """
    Shows each task done on a day and the total time spent
    doing it. Multiple recordings of the same task are
    cumulative.

    date_str -- a string in the format DD/MM/YYYY of the day to show. If
    not supplied, it defaults to today.
    """

    # ensure directories exist
    database.init_directories()

    if date_str is None:
        # Today
        date = datetime.now().date()
    else:
        try:
            date = datetime.strptime(date_str, "%d/%m/%Y").date()
        except ValueError as err:
            print("Date format must be as follows: DD/MM/YYYY")
            sys.exit(1)

    today = date == datetime.now().date()

    tasks = database.get_date_tasks(date)

    # Will hold text elements
    elements = []
    # Lower priority elements will be further up the screen
    prio = 0

    # Context sensitive header
    if today:
        header_start = "Today "
    else:
        header_start = "On " + date.strftime("%d/%m/%Y") + " "

    # there are tasks to display
    if len(tasks) > 0:
        header = header_start + "you did the following tasks: "
    # there are no tasks to display
    else:
        header = header_start + "you did no tasks."

    header_text = display.TextElement(header, prio)
    prio += 1
    elements.append(header_text)

    break1 = display.TextElement("", prio)
    prio += 1
    elements.append(break1)

    # get total time spent on all tasks
    total_time = sum([t.time for t in tasks])

    for t in tasks:
        # Time taken as percentage of total
        # spent on all tasks this day
        percent = round(t.time / total_time * 100)

        txt = t.name + " for "
        txt += make_time_string(t.time)
        txt += " - " + str(percent) + "%"
        elements.append(display.TextElement(txt, prio))
        prio += 1

    break2 = display.TextElement("", prio)
    prio += 1
    elements.append(break2)

    instr_text_enter = "Press q or ENTER to exit"
    instr1 = display.TextElement(instr_text_enter, prio)
    elements.append(instr1)

    elements.sort()

    screen = display.init_display()

    display.update(screen, elements)

    # loop until user quits
    while True:

        display.update(screen, elements)

        inp = display.run(screen)

        if inp in ('KEY_ENTER', '\n', '\r', 'q', 'Q'):
            display.end(screen)
            sys.exit(0)

        # Lets not overwork the CPU
        sleep(0.01)

    display.end(screen)
Exemplo n.º 8
0
def update(dt:int=30):
    display.update(dt)
Exemplo n.º 9
0
def test_update():
    screen = curses.initscr()
    elements = [display.TextElement("test", 0)]
    display.update(screen, elements)
    assert screen.is_wintouched()
Exemplo n.º 10
0
playing = True

def quit(e):
	global playing
	if e.type == pygame.QUIT:
		playing = False
	elif e.type == pygame.KEYUP:
		if ((e.key == pygame.K_F4) and
		   (e.mod and pygame.KMOD_ALT)):
			playing = False

player = units.player(500, 500)
display.register(player)

event.register(player.handler)
event.register(quit)
event.register(audio.handler)
event.register(display.handler)

audio.init()
clock = pygame.time.Clock()
while(playing):

	clock.tick(30)

	event.update()
	player.update()
	display.update()
	
pygame.display.quit()
Exemplo n.º 11
0
def redraw():
	display.clear((64,64,64))
	# Draw the map
	display.fill_rect((0,0, 400,400), (0,0,0))

	Player.cur_level.recalc_light()

	for x,y in box2d(-12, -12, 25, 25):
		# for each tile in the player's map range:
		ax, ay = x+Player.x, y+Player.y
		if Player.cur_level.in_bounds(ax, ay):
			cur_tile = Player.cur_level.tiles[ax][ay]
			seen = Player.can_see(ax, ay)
			if seen == 1: # Illuminated and in LoS
				cur_tile.memorized = True
				# draw the terrain
				display.draw_sprite(cur_tile.img, ((x+12)*16, (y+12)*16))
				# draw each item, starting with the ones on the bottom of the pile
				for i in cur_tile.items:
					display.draw_sprite(i.img, ((x+12)*16, (y+12)*16))
			elif seen == 2: # In night vision range
				cur_tile.memorized = True
				display.draw_sprite(cur_tile.img, ((x+12)*16, (y+12)*16), sheet=display.sprites_blue)
				# draw each item, starting with the ones on the bottom of the pile
				for i in cur_tile.items:
					display.draw_sprite(i.img, ((x+12)*16, (y+12)*16), sheet=display.sprites_blue)
			elif cur_tile.memorized:
				display.draw_sprite(cur_tile.img, ((x+12)*16, (y+12)*16), sheet=display.sprites_grey)
				for i in cur_tile.items:
					if not i.holdable:
						display.draw_sprite(i.img, ((x+12)*16, (y+12)*16), sheet=display.sprites_grey)

	# Draw creatures, including the player
	for c in Player.cur_level.creatures:
		sx, sy = c.x-Player.x+12, c.y-Player.y+12
		if 0 <= sx < 25 and 0 <= sy < 25 and Player.can_see(c.x, c.y):
			display.draw_sprite(c.img, (sx*16, sy*16))
			if c != Player:
				# health bar
				display.fill_rect((sx*16, sy*16, 16*(float(c.hp)/c.maxhp), 1), (255,0,0))

	# Message log
	display.fill_rect((5,405, 790,190), (32,32,32))
	display.msg_log.draw((10, 410), 160)

	# Player text entry
	if Player.entering_text:
		display.fill_rect((9,575, 782,16), (64,64,64))
		display.draw_text(Player.entered_text, (12,576))

	# Draw player's health bar
	display.fill_rect((400,0, 400,16), (128,0,0))
	display.fill_rect((400,0, 400*(float(Player.hp)/Player.maxhp), 16), (255,0,0))
	display.draw_text('HP: %d/%d' % (Player.hp, Player.maxhp), (405, 1))
	# energy bar
	display.fill_rect((400,16, 400,16), (192,192,192))
	display.fill_rect((400,16, 400*(float(Player.mp)/Player.maxmp), 16), (255,255,0))
	display.draw_text('ENERGY: %d/%d' % (Player.mp, Player.maxmp), (405, 17), (0,0,0))
	
	# Player's wealth and inventory
	display.draw_text('Gold: %d' % (Player.gold), (405, 40), (255,255,0))
	display.draw_text('Inventory', (410, 156))
	INV_X = 420
	INV_Y = 190
	INV_W = 10
	INV_H = 10
	# inventory slot boxes
	for i in xrange(INV_W*INV_H):
		x,y = i%INV_W, i//INV_W
		display.draw_rect((INV_X+x*21, INV_Y+y*21, 20, 20), (255,255,255))
	# inventory axis labels (for EZ-dropping/selling)
	for i in xrange(INV_W):
		display.draw_text('%d' % i, (INV_X+i*21+6, INV_Y-15))
	for i in xrange(INV_H):
		display.draw_text('%d' % i, (INV_X-9, INV_Y+i*21+3))
	# actual items
	for i,item in enumerate(Player.inv):
		x,y = i%INV_W, i//INV_W
		display.draw_sprite(item.img, (INV_X+2+x*21, INV_Y+2+y*21))

	# Equipment (garb)
	EQ_X = 640
	EQ_Y = 200
	display.draw_text('Your equipment:', (EQ_X, EQ_Y))
	if Player.equipment:
		for i,item in enumerate(Player.equipment):
			EQ_Y += 16
			if item.equip_slot:
				display.draw_text('%d: %s (%s)' % (i,item.name,item.equip_slot), (EQ_X, EQ_Y))
			else:
				display.draw_text('%d: %s' % (i,item.name), (EQ_X, EQ_Y))
	else:
		EQ_Y += 16
		display.draw_text('None!', (EQ_X, EQ_Y))

	EQ_Y += 16
	# also write empty slots under garb
	for slot in Player.equip_slots.iterkeys():
		fs = Player.equip_slots[slot] - Player.equipped[slot]
		if fs:
			EQ_Y += 16
			if fs == 1: pl = ''
			else: pl = 's'
			display.draw_text('%d free slot%s (%s)' % (fs,pl,slot), (EQ_X, EQ_Y))

	# Stats
	display.draw_text('Attack damage: %d-%d' % (Player.min_atk, Player.max_atk), (420, 60))
	display.draw_text('Attack speed: %d' % (10000/Player.attack_time), (420, 76))
	display.draw_text('Move speed: %d' % (10000/Player.move_time), (420, 92))

	display.update()
Exemplo n.º 12
0
    def play(self, level):
        self.load_level(level)
        self.init_display()
        display = self.display
        self._quit = False
        self._win = False
        self._ended = False
        timer = pygame.time.Clock()
        fcnt = 0

        while not self._quit:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    self._quit = True
                elif event.type == pygame.KEYDOWN:
                    key = event.key
                    if key == pygame.K_q:
                        self._quit = True
                    #elif key == pygame.K_r:
                    #    config.ENABLE_REFLECT = not config.ENABLE_REFLECT    
                    #elif key == pygame.K_s:
                    #    config.ENABLE_SHADOW = not config.ENABLE_SHADOW
                elif event.type == pygame.MOUSEBUTTONDOWN:
                    if event.button == 4:
                        # scroll up, zoom in
                        self.camera.zoom_in()
                    elif event.button == 5:
                        # scroll down, zoom out
                        self.camera.zoom_out()
            # update logic
            if not self._ended and fcnt % config.DD == 0:
                # update player pos
                pressed = pygame.key.get_pressed()
                if self.player.is_ready():
                    for key in config.Dirs:
                        if pressed[key]:
                            direction = config.Dirs[key]
                            self.move_player(self.player, direction)
                            break
                    else:
                        self.player.rest()
                # recalculate lights
                for emitter in self.emitters:
                    emitter.calculate(self.field)
                    end = emitter.light.end
                    if end and not end.dying:
                        end.die()
                self.emitters = [x for x in self.emitters if x.alive]
                self.lights.redraw(self.emitters)
                for sp in display.sprites:
                    if hasattr(sp, 'update2'):
                        sp.update2()
                if self.player.dying:
                    self.end_game(False)
            # update display
            display.update(self.field)
            # tick
            timer.tick(config.FPS)
            clock.tick()
            if fcnt % config.FPS== 0: print clock.get_fps()
            fcnt += 1
Exemplo n.º 13
0
Arquivo: base.py Projeto: gdos/parole
    # Init done
    info('Parole ready. Entering main loop.')

    #if not len(uiEventHandlers):
    #    warn('There is no handler to receive ui events.')
    
    # Main Engine loop
    while not __paroleShutdown:
        pygame.event.pump()

        try:
            # Update the display for this frame
            if haveModule['display']:
                t = time()
                display.update()
                t = time() - t
                if parole.conf.general.logFrameTime:
                    debug('Display update time: %sms', t)
                if parole.conf.general.printFrameTime:
                    sys.stderr.write('Display update time: %sms\n' % t)
                    sys.stderr.flush()

                # Show the splash screen/animation on engine startup
                if haveModule['shader'] and haveModule['resource'] and \
                        parole.conf.general.engineSplash:
                    if not splash.doneSplash:
                        if not splash.splash:
                            splash.doSplash()
                        continue
Exemplo n.º 14
0
def main():
    init()
    show_counter_screen()
    while True:
        time.sleep_ms(30)
        display.update(30)
Exemplo n.º 15
0
    width = display.width
    height = display.width

    # Get drawing object to draw on image.
    draw = ImageDraw.Draw(image)

    # Draw a black filled box to clear the image.
    draw.rectangle((0,0,width,height), outline=0, fill=0)

    #padding = 0
    font22 = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', 22)
    font9  = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', 9)
    font25 = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', 25)
    #Draw Mot2Bot
    draw.text((10,20), 'mot2bot', font=font25, fill=255)
    display.update(image)

    #draw.text((0, -5), 'Warten auf',  font=font22, fill=255)
    #draw.text((0, 25), 'Netzwerk ...', font=font22, fill=255)
    #draw.text((0,55), str(300), font=font9, fill=255)

    # Display image.
    #disp.image(image)
    #idata = image.tostring()
    #pgimage = pygame.image.fromstring(idata, image.size, image.mode)
    #surf.blit(pgimage, (0,32))
    display.update(image)
    #disp.display()

    #Center Camera:
    tVal = tCenter
Exemplo n.º 16
0
def setInput(r):
    msg = "angle: %s°" % angleText  #"; light is %s" % (angleText, "on" if light else "off")
    di.update(r, msg)