当前位置: 首页>>代码示例>>Python>>正文


Python Window.clear方法代码示例

本文整理汇总了Python中pyglet.window.Window.clear方法的典型用法代码示例。如果您正苦于以下问题:Python Window.clear方法的具体用法?Python Window.clear怎么用?Python Window.clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyglet.window.Window的用法示例。


在下文中一共展示了Window.clear方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from pyglet.window import Window [as 别名]
# 或者: from pyglet.window.Window import clear [as 别名]
def main():
    # Create the main window
    window = Window(800, 600, visible=False,
                   caption="FF:Tactics.py", style='dialog')
    # Create the default camera and have it always updating
    camera = Camera((-600, -300, 1400, 600), (400, 300), 300, speed=PEPPY)
    clock.schedule(camera.update)

    # Load the first scene
    world = World(window, camera)
    world.transition(MainMenuScene)

    # centre the window on whichever screen it is currently on
    window.set_location(window.screen.width/2 - window.width/2,
                        window.screen.height/2 - window.height/2)
    # clear and flip the window
    # otherwise we see junk in the buffer before the first frame
    window.clear()
    window.flip()

    # make the window visible at last
    window.set_visible(True)

    # finally, run the application
    pyglet.app.run()
开发者ID:johnmendel,项目名称:python-tactics,代码行数:27,代码来源:tactics.py

示例2: Egg

# 需要导入模块: from pyglet.window import Window [as 别名]
# 或者: from pyglet.window.Window import clear [as 别名]
class Egg(object):
    def __init__(self, width, height):
        # display initializations
        self.__window = Window(width, height, vsync=True)
        self.__background_color = (0, 0, 0, 1.0)
        # self._fps_display = pyglet.clock.ClockDisplay()
        self.__key_state_handler = key.KeyStateHandler()
        self.__scene = None
        self.__window.event(self.on_draw)
        self.__window.push_handlers(self.__key_state_handler)
        self.__camera = None
        #schedule regular updates
        pyglet.clock.schedule_interval(self.update, 1 / 100.0)

    @property
    def window(self):
        return self.__window

    @property
    def background_color(self):
        return self.__background_color

    @background_color.setter
    def background_color(self, value):
        self.__background_color = value

    def register_scene(self, scene):
        self.__scene = scene
        self.__camera = Camera("main_camera", (0, 0), self.__window.height / 2.)
        self.__scene.root.add_child(self.__camera)
        self.__camera.target.x = self.__window.width / 2.
        self.__camera.target.y = self.__window.height / 2.
        self.__window.event(self.__scene.on_mouse_press)
        self.__window.event(self.__scene.on_mouse_release)
        self.__window.event(self.__scene.on_mouse_drag)
        self.__window.event(self.__scene.on_mouse_motion)


    def on_draw(self):
        self.__window.clear()
        glClearColor(*self.__background_color)
        if self.__scene is not None:
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)

            # draw batches
            self.__camera.focus(self.__window.width, self.__window.height)
            self.__scene.draw()
            # draw specific batches for the hud
            self.__camera.hud_mode(self.__window.width, self.__window.height)
            self.__scene.draw_head_display()

    def update(self, dt):
        if self.__scene is not None:
            self.__scene.update(dt)
            self.__scene.process_keyboard(self.__key_state_handler, dt)
            self.__camera.update(dt)
开发者ID:MrGecko,项目名称:pyromancy,代码行数:59,代码来源:egg.py

示例3: Gameloop

# 需要导入模块: from pyglet.window import Window [as 别名]
# 或者: from pyglet.window.Window import clear [as 别名]
class Gameloop(object):

    def __init__(self):
        self.window = None

    def init(self):
        self.world = World()
        self.world.init()
        populate(self.world)

        bitmaps = Bitmaps()
        bitmaps.load()
        self.render = Render(bitmaps)
        self.camera = Camera(zoom=10.0)

        self.window = Window(fullscreen=False, visible=False)
        self.window.set_exclusive_mouse(True)
        self.window.on_draw = self.draw
        self.window.on_resize = self.render.resize

        self.controls = Controls(self.world.bat)
        self.window.set_handlers(self.controls)

        self.render.init()
        clock.schedule(self.update)
        self.hud_fps = clock.ClockDisplay()

        self.window.set_visible()


    def update(self, dt):
        # scale dt such that the 'standard' framerate of 60fps gives dt=1.0
        dt *= 60.0
        # don't attempt to compensate for framerate of less than 30fps. This
        # guards against huge explosion when game is paused for any reason
        # and then restarted
        dt = min(dt, 2)
        self.controls.update()
        self.world.update()
        self.window.invalid = True

    def draw(self):
        self.window.clear()
        self.camera.world_projection(self.window.width, self.window.height)
        self.camera.look_at()
        self.render.draw(self.world)

        self.hud_fps.draw()

        return EVENT_HANDLED

    def stop(self):
        if self.window:
            self.window.close()
开发者ID:tartley,项目名称:pyong,代码行数:56,代码来源:gameloop.py

示例4: Gameloop

# 需要导入模块: from pyglet.window import Window [as 别名]
# 或者: from pyglet.window.Window import clear [as 别名]
class Gameloop(object):
    def __init__(self):
        self.camera = None
        self.projection = None
        self.render = None
        self.window = None
        self.world = None
        self.fpss = []

    def prepare(self, options):
        self.window = Window(fullscreen=options.fullscreen, vsync=False, visible=False, resizable=True)
        self.window.on_draw = self.draw
        self.projection = Projection(self.window.width, self.window.height)
        self.window.on_resize = self.projection.resize

        self.world = World()

        self.camera = Camera()
        self.world.add(GameItem(camera=self.camera, position=Origin, move=WobblyOrbit(32, 1, speed=-0.5)))

        self.render = Render(self.world)
        self.render.init()
        pyglet.clock.schedule(self.update)
        self.clock_display = pyglet.clock.ClockDisplay()

        vs = VertexShader(join("flyinghigh", "shaders", "lighting.vert"))
        fs = FragmentShader(join("flyinghigh", "shaders", "lighting.frag"))
        shader = ShaderProgram(vs, fs)
        shader.use()

    def update(self, dt):
        # self.fpss.append(1/max(1e-3, dt))
        dt = min(dt, 1 / 30)
        self.world.update(dt)
        self.window.invalid = True

    def draw(self):
        self.window.clear()

        self.projection.set_perspective(45)
        self.camera.look_at(Origin)
        self.render.draw()

        self.projection.set_screen()
        self.camera.reset()
        self.render.draw_hud(self.clock_display)

        return EVENT_HANDLED

    def stop(self):
        if self.window:
            self.window.close()
开发者ID:tartley,项目名称:flyinghigh-opengl-from-python,代码行数:54,代码来源:gameloop.py

示例5: Gameloop

# 需要导入模块: from pyglet.window import Window [as 别名]
# 或者: from pyglet.window.Window import clear [as 别名]
class Gameloop(object):

    def __init__(self, options):
        self.options = options
        self.window = None
        self.fpss = []
        self.time = 0.0
        self.level = None


    def prepare(self, options):
        self.window = Window(
            fullscreen=options.fullscreen,
            vsync=options.vsync,
            visible=False,
            resizable=True)
        self.window.on_draw = self.draw_window

        self.world = World()
        self.player = Player(self.world)
        self.camera = GameItem(
            position=origin,
            update=CameraMan(self.player, (3, 2, 0)),
        )
        self.level_loader = Level(self)
        success = self.start_level(1)
        if not success:
            logging.error("ERROR, can't load level 1")
            sys.exit(1)

        self.update(1/60)

        self.window.push_handlers(KeyHandler(self.player))

        self.render = Render(self.world, self.window, self.camera)
        self.render.init()

        self.music = Music()
        self.music.load()
        self.music.play()


    def run(self):
        pyglet.clock.schedule(self.update)
        self.window.set_visible()
        self.window.invalid = False
        pyglet.app.run()


    def update(self, dt):
        if self.options.print_fps:
            self.fpss.append(1/max(1e-6, dt))
        dt = min(dt, 1 / 30)
        self.time += dt

        for item in self.world:
            if hasattr(item, 'update'):
                item.update(item, dt, self.time)

        if self.player_at_exit():
            self.world.remove(self.player)
            pyglet.clock.schedule_once(
                lambda *_: self.start_level(self.level + 1),
                1.0
            )

        self.window.invalid = True


    def start_level(self, n):
        success = self.level_loader.load(self.world, n)
        if not success:
            logging.info('No level %d' % (n,))
            self.stop()
            return False
               
        self.level = n
        pyglet.clock.schedule_once(
            lambda *_: self.world.add(self.player),
            2.0,
        )
        return True


    def player_at_exit(self):
        items = self.world.collision.get_items(self.player.position)
        if any(hasattr(item, 'exit') for item in items):
            dist2_to_exit = dist2_from_int_ords(self.player.position)
            if dist2_to_exit < EPSILON2:
                return True
        return False


    def draw_window(self):
        self.window.clear()
        self.render.draw_world()
        if self.options.display_fps:
            self.render.draw_hud()
        self.window.invalid = False
        return EVENT_HANDLED
#.........这里部分代码省略.........
开发者ID:mjs,项目名称:pyweek11-cube,代码行数:103,代码来源:gameloop.py

示例6: Client

# 需要导入模块: from pyglet.window import Window [as 别名]
# 或者: from pyglet.window.Window import clear [as 别名]
class Client( object ):
    def __init__(self, app):
		self.app = app
		self.window = Window(	width=self.app.size[0],
		        				height=self.app.size[1], 
		        				style='dialog',
		        				resizable=False )

		self.window.set_caption("ASTAR MAZE")
		self.window.on_close = sys.exit
		self.ctrl = InputHandler(self)
		self.window.push_handlers(self.ctrl)

		self.clock = Clock()
		self.clock.set_fps_limit(30)
		self.window.push_handlers(self.clock)

		self.grid = ClientGrid( self.app.grid )

		# S q u a r e s
		self.entities = {}
		self.setup()


    def setup(self):
		glClearColor( .113, .121, .1289, 1 )
		glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA )
		glDisable( GL_LIGHTING )
		glCullFace( GL_BACK )
		glDisable( GL_DEPTH_TEST )

		self.runner = None
		self.goal = None
		self.isSearching = False
		self.found = False
		self.solution = []
		self.prev = None

		self.entitiesBatch = pyglet.graphics.Batch()
		group = ClientGroup()
		for k,v in self.app.squares.iteritems():
			verts = self.entitiesBatch.add( 4, GL_QUADS, group, 'v2i/static', 'c4B/dynamic' )
			verts.vertices 		= v.vertices['positions']
			verts.colors 		= v.vertices['colors']
			self.entities[k] 	= ClientSquare( v, verts )


    def draw(self):
		self.grid.draw()
		self.entitiesBatch.draw()
		if self.found: 
			curr = None
			if self.prev:
				self.setVisited( self.entities[self.prev] )
			if len(self.solution):
				curr = self.solution.pop()
				self.entities[curr].update( SquareType.RUNNER )
				self.prev = curr


    def update(self):
        self.clock.tick()
        self.window.dispatch_events()
        self.window.clear()
        self.draw()
        self.window.flip()


    def reset(self):
    	self.app.setup()
    	self.setup()


    def astar(self):
		startState = ASState( self.runner.pos, self.goal.pos, self )
		nodesGenerated = 1
		frontier = Heap()
		expanded = set()
		frontier.push( 0, ASNode( startState ) )

		while len(frontier):
			n = frontier.pop()

			if n.state.isGoal():
				self.solution = n.execute()
				print "%d node(s) generated.\n" % nodesGenerated
				return True

			successors = n.state.expand()
			for succ in successors:
				if succ['successor'] not in expanded:
					nodesGenerated = nodesGenerated + 1
					nprime = ASNode( succ['successor'], succ['action'], n )
					frontier.push( nprime.hCost, nprime )
					expanded.add( succ['successor'] )
		return False


    def search(self):
    	if not self.runner or not self.goal:
#.........这里部分代码省略.........
开发者ID:brandonl,项目名称:a-maze,代码行数:103,代码来源:astar.py

示例7: Application

# 需要导入模块: from pyglet.window import Window [as 别名]
# 或者: from pyglet.window.Window import clear [as 别名]
class Application(object):
    '''
    This class creates a window with an OpenGL context, and contains hooks for components to call to request updates as apart of the 'game loop.'

    :param size: is a tuple representing the default size of the window (width, height).
    :type size: 2-tuple of integers

    :param title: is the title text at the top of the window.
    :type title: str

    :param fullscreen: tells the window to start fullscren or not.
    :type fullscreen: boolean
    '''
    def __init__(self, size=(DEFAULT_WIDTH, DEFAULT_HEIGHT),
            title='MegaMinerAI Bland Title Text', fullscreen=False):
        self.window = Window(width=size[0], height=size[1], caption=title,
                visible=True, fullscreen=fullscreen, resizable=True,
                style=Window.WINDOW_STYLE_DEFAULT, vsync=False, display=None,
                context=None, config=None)
        self.updates = []

        # Set up the event dispatcher
        self.ed = EventDispatcher()
        self.ed.register_class_for_events(self)

        # Build the game loader
        self.loader = gameloader.GameLoader(self.ed)

        #Build the renderer
        self.renderer = renderer.Renderer()

        # Request updates
        self.request_update_on_draw(self.renderer.init_frame, 0)
        self.request_update_on_draw(self.renderer.draw_frame, 100)


    @event_handler
    def on_run_gamelog(self, data):
        print('handler')
        game_name = data['gameName'].lower()

        path = os.path.join(config.setting['plugin directory'], game_name,
            'main.py')

        self.game = imp.load_source(game_name, path)
        self.game.load(self, data)

        return True


    def request_update_on_draw(self, procedure, order=50):
        '''
        This method tells the application that whenever a draw occurs for the application, that *procedure* should be called.

        :param order: specifies when *procedure* should be called.  All procedures with the same *order* will execute in a semi-random fashion after the previous *order* and before the next *order* value in the update queue.  In general, all procedures should be called sometime before the :mod:`renderer`'s update() function is called.  Procedures will be called with *order* from least to greatest.
        :type order: float or integer

        :param procedure: should not expect any arguments or an exception will be thrown.
        :type procedure: function or class method

        Example gameloop::

            >>> app.request_update_on_draw(game.update_objects)
            >>> app.request_update_on_draw(game.do_input_stuff, 10)
            >>> app.request_update_on_draw(game.render_frame, 100)
            >>> app.run()
            'processing user input'
            'updating game objects'
            'rendering frame'
        '''

        self.updates += [(order, procedure)]
        self.updates.sort(key=lambda x: x[0])

    def _update(self, dt):
        '''
        This function is called at the start of every loop in the 'game loop.'

        It calls all the procedures that requested updates in the game loop.

        *dt* is the time since the last call.
        '''
        # Forces a redraw
        # Trigger everything

        self.window.clear()

        for order, procedure in self.updates:
            procedure()

    def run(self, glog_list=[]):
        '''
        This method starts the 'game loop.'  It is a blocking function so at this, point all modules should have requested updates from the application or another thread should have been started.
        '''

        self.ed.dispatch_event('on_load_gamelog_file', glog_list)

        pyglet.clock.schedule(self._update)
        pyglet.app.run()
开发者ID:NortySpock,项目名称:PyVis,代码行数:101,代码来源:application.py

示例8: InputManager

# 需要导入模块: from pyglet.window import Window [as 别名]
# 或者: from pyglet.window.Window import clear [as 别名]
        if state:
            print "\tspace is pushed"
        if not state:
            print "\tspace is released"

# Utworzenie InputManagera i włączenie go do pygleta            
manager = InputManager()
window = Window()
window.on_key_press = manager.key_pressed
window.on_key_release = manager.key_released

# Tworzymy 3 obiekty obserwujące
ops1 = ConcreteInputObserver('ops1')
ops2 = ConcreteInputObserver('ops2')
ops3 = ConcreteInputObserver('ops3')

# dodajemy obserwatorów
manager.register_observer(ops1)
manager.register_observer(ops2)
manager.register_observer(ops3)

# usuwamy obserwatorów
manager.unregister_observer(ops1)
manager.unregister_observer(ops2) 

# zostaje tylko trzech obserwatorów
# uruchamiamy aplikację
print "Możesz sprawdzić działanie klawszy wsad, strzałek oraz spacji"
window.clear()
pyglet.app.run()
开发者ID:mmilewski,项目名称:pyWorm,代码行数:32,代码来源:inputManagerTest.py

示例9: Game

# 需要导入模块: from pyglet.window import Window [as 别名]
# 或者: from pyglet.window.Window import clear [as 别名]
class Game(object):

    INITIAL_UPDATE_INTERVAL = UPDATE_INTERVAL

    def __init__(self):
        impl.funcs.load_resources()
        self.gameInfo = GameInfo()
        self.win = Window(FIELD_WIDTH, FIELD_HEIGHT)
        self.win.set_caption("snake")
        impl.funcs.setup_background_color()
        impl.funcs.setup_opengl_blend_func()
        self.gameField = GameField(self.gameInfo, self.win)
        self.menu = Menu(FIELD_WIDTH//2, FIELD_HEIGHT//2, self.game_start_callback, self.game_exit_callback, self.win)
        self._overlay = None
        self._update_interval = Game.INITIAL_UPDATE_INTERVAL

        @self.gameField.event
        def on_restart_snake():
             unschedule(func=self.update)
             self._setup_overlay("restart")
             schedule_once(func=self.run_snake, delay=DELAY_FOR_NEW_RUN)

        @self.gameField.event
        def on_rerun_menu():
            unschedule(func=self.update)

            #reset current handler
            self.win.pop_handlers()
            #and setup update handler
            self.win.push_handlers(self.menu)
            self.menu.start_bgrn_animation()

        @self.gameField.event
        def on_game_over():
            unschedule(func=self.update)
            self._setup_overlay('game over...')
            schedule_once(func=self.game_exit_callback, delay=DELAY_FOR_EXIT)

        @self.gameField.event
        def on_score_up():
            if self._update_interval > MAX_UPDATE_SPEED_INTERVAL:
                self._update_interval -= UPDATE_INTERVAL_SPEED_DX
                unschedule(func=self.update)
                schedule_interval(func=self.update,interval=self._update_interval)

    def _setup_overlay(self, text):
        self._overlay = BouncingLabel(FIELD_WIDTH//2,FIELD_HEIGHT//2,text,DEFAULT_OVERLAY_COLOR)
        self.win.pop_handlers()
        def on_draw():
            self.win.clear()
            self._overlay.draw()
        self.win.push_handlers(on_draw)

        schedule_interval(func=self._overlay.update, interval=OVERLAY_UPDATE_INTERVAL)

    def game_start_callback(self):
        self._setup_overlay("start")
        schedule_once(func=self.run_snake, delay=DELAY_FOR_NEW_RUN)

    def game_exit_callback(self, *args):
        if self._overlay:
            unschedule(self._overlay.update)
            self._overlay = None

        self.win.pop_handlers()
        self.win.close()

    def start(self):
         self.win.push_handlers(self.menu)
         pyglet.app.run()

    def update(self, dt):
        if not self.gameInfo.pause:
            self.gameField.update(dt)

    def run_snake(self, *args):
        if self._overlay:
            unschedule(self._overlay.update)
            self._overlay = None

        #reset current handlers
        self.win.pop_handlers()

        self.gameInfo.pause = False
        self.gameField.reset()

        #setup new handlers
        self.win.push_handlers(self.gameField)

        #and setup update handler
        self._update_interval = Game.INITIAL_UPDATE_INTERVAL
        schedule_interval(func=self.update,interval=self._update_interval)
开发者ID:varnie,项目名称:snake,代码行数:94,代码来源:Game.py

示例10: Camera_test

# 需要导入模块: from pyglet.window import Window [as 别名]
# 或者: from pyglet.window.Window import clear [as 别名]
class Camera_test(MyTestCase):

    def setUp(self):
        self.window = Window(
            width=200, height=100, visible=False, caption="Camera_test setup")
        self.window.dispatch_events()
        glClearColor(0, 0, 0, 1)
        self.window.clear()
        self.world = World()
        self.camera = Camera((0, 0), 1)


    def tearDown(self):
        self.window.close()


    def test_constructor(self):
        camera = Camera((1, 2), 3, 4)
        self.assertEquals(camera.x, 1, "should init x")
        self.assertEquals(camera.y, 2, "should init y")
        self.assertEquals(camera.scale, 3, "should init scale")
        self.assertEquals(camera.angle, 4, "should init angle")


    def test_constructor_defaults_angle(self):
        camera = Camera((10, 20), 30)
        self.assertEquals(camera.angle, 0.0, "should init angle")


    def _draw_rect(self, backColor, polyColor, left, bottom, right, top):
        glClearColor(
            backColor[0]/255,
            backColor[1]/255,
            backColor[2]/255,
            1.0)
        self.window.clear()

        verts = [
            (left, bottom),
            (right, bottom),
            (right, top),
            (left, top),
        ]
        glColor3ub(*polyColor)
        glBegin(GL_TRIANGLE_FAN)
        for vert in verts:
            glVertex2f(*vert)
        glEnd()


    def test_world_projection_default(self):
        rect = (-0.2, -0.4, +0.6, +0.8)
        expectedRect = (90, 10, 129, 69)
        self.assert_world_projection(rect, expectedRect)


    def test_defect_pyglet_get_color_buffer_for_resized_windows(self):
        self.window.set_size(111, 222)
        self.window.dispatch_events()
        mgr = get_buffer_manager()
        col_buf = mgr.get_color_buffer()
        col_buf_size = col_buf.width, col_buf.height
        self.assertEquals(col_buf_size, (111, 222), "pyglet bug regression")


    def test_world_projection_strange_aspect(self):
        # create a new window, since
        # resizing the existing window doesn't work for some reason
        # even if we dispatch events. Default handlers?
        self.window.close()
        self.window = Window(
            width=100, height=200, visible=False,
            caption="world.test_projection_strange_aspect")
        self.window.dispatch_events()
        rect = (-0.2, -0.4, +0.6, +0.8)
        expectedRect = (40, 60, 79, 119)
        self.assert_world_projection(rect, expectedRect)


    def test_world_projection_offset(self):
        self.camera.x, self.camera.y = (+0.5, +0.3)
        rect = (-0.2, -0.4, +0.6, +0.8)
        expectedRect = (65, 25, 104, 84)
        self.assert_world_projection(rect, expectedRect)


    def test_world_projection_scale(self):
        self.camera.scale = 10
        rect = (-1, -2, +3, +4)
        expectedRect = (95, 30, 114, 59)
        self.assert_world_projection(rect, expectedRect)


    def test_world_projection_angle(self):
        self.camera.angle = pi/2
        rect = (-0.2, -0.4, +0.6, +0.8)
        expectedRect = (60, 20, 119, 59)
        self.assert_world_projection(rect, expectedRect)


#.........这里部分代码省略.........
开发者ID:tartley,项目名称:sole-scion,代码行数:103,代码来源:camera_test.py


注:本文中的pyglet.window.Window.clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。