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


Python Window.draw方法代码示例

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


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

示例1: setup

# 需要导入模块: from window import Window [as 别名]
# 或者: from window.Window import draw [as 别名]
class Revisao:
    """Calsse que executa o programa criado na aula de revisão."""

    def setup(self, width, height, bg=color.BLACK):
        self.window = Window(width, height)
        self.objects = []
        self.background = bg

    def add_object(self, object):
        self.objects.append(object)

    def run(self):
        clock = pygame.time.Clock()
        running = True
        while running:
            # handle events
            for evt in pygame.event.get():
                if evt.type == pygame.QUIT:
                    running = False
                    continue
            # update objects
            for obj in self.objects:
                obj.update(self.window.size)
            # clear window.
            self.window.clear(self.background)
            # draw objects
            for obj in self.objects:
                self.window.draw(obj)
            # update window
            self.window.update()
            # ensure maximum speed
            clock.tick(240)
开发者ID:rafasgj,项目名称:algoritmos2,代码行数:34,代码来源:revisao.py

示例2: GlutWindow

# 需要导入模块: from window import Window [as 别名]
# 或者: from window.Window import draw [as 别名]
class GlutWindow(object):
    def __init__(self, width, height, title):
        super(GlutWindow, self).__init__()
        self.width = width
        self.height = height
        self.title = title

        self.texture_id = 0
        self.vertices = None

        self.pixels = np.zeros(self.width * self.height)
        self.window = Window(self.width, self.height, self.pixels)

        self.setup()

    def mouse_event(self, button, state, x, y):
        self.window.mouse_event(button, state, x, y)

    def key_event(self, key, key_is_down, x, y):
        key = ord(key)
        self.window.key_event(key, key_is_down)

    def key_down(self, key, x, y):
        self.key_event(key, True, x, y)

    def key_up(self, key, x, y):
        self.key_event(key, False, x, y)

    def setup(self):
        self.setup_glut()
        self.setup_gl()

    def setup_glut(self):
        # glutInit(sys.argv)
        glutInit()
        glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA)
        glutInitWindowSize(self.width, self.height)

        glutCreateWindow(self.title)
        glutDisplayFunc(self.show)

        glutMouseFunc(self.mouse_event)

        glutKeyboardFunc(self.key_down)
        glutKeyboardUpFunc(self.key_up)
        # glutSetKeyRepeat(GLUT_KEY_REPEAT_ON)

    def setup_gl(self):
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

        glClearColor(0, 0, 0, 1)
        glViewport(0, 0, self.width, self.height)

        self.texture_id = glGenTextures(1)
        glEnable(GL_TEXTURE_2D)
        glBindTexture(GL_TEXTURE_2D, self.texture_id)
        # glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
        # glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)

        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, self.width, self.height,
                     0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, self.pixels)

        self.vertices = [
            # (u, v), (x, y, z)
            (0, 0), (-1, -1, 0),
            (1, 0), (1, -1, 0),
            (1, 1), (1, 1, 0),
            (0, 1), (-1, 1, 0),
        ]

    def update(self, dt=100):
        # clear
        self.clear()

        # update
        delta = dt / 1000.0
        self.window.update(delta)

        # draw
        self.window.draw()

        # show
        glutPostRedisplay()
        glutTimerFunc(dt, self.update, dt)

    def run(self):
        self.update()
        glutMainLoop()

    def clear(self):
        glClear(GL_COLOR_BUFFER_BIT)
        self.window.clear()

    def show(self):
        # update texture and render
        glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, self.width, self.height,
                        GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, self.pixels)
#.........这里部分代码省略.........
开发者ID:happlebao,项目名称:rendererpy,代码行数:103,代码来源:glutwindow.py

示例3: Pong

# 需要导入模块: from window import Window [as 别名]
# 或者: from window.Window import draw [as 别名]
class Pong(Game):
    """Implements the pong game."""

    def __init__(self, player1, player2):
        """Initialize the game."""
        Game.__init__(self)
        self.__ball = GameBall(400, 300, 10)
        self.__restart_ball()
        self.__paddles = [Paddle((20, 150), (5, 260), (200, 200, 200)),
                          Paddle((20, 150), (775, 260), (200, 200, 200))]
        self.window = Window(800, 600)
        self.window.set_title("Pong")
        self.add_object(self.__ball)
        for p in self.__paddles:
            self.add_object(p)
        self.__scores = [0, 0]
        self.digits = [Text(i, 48) for i in range(10)]

    def __restart_ball(self):
        self.__ball.position = (400, 300)
        self.__ball.movement = (choice([-0.5, 0.5]), choice([-0.5, 0.5]))

    def __ball_collision(self):
        c = collider.wall_circle_collision(self.window.bounds,
                                           self.__ball.bounds)
        dx, dy = self.__ball.movement
        dy *= -1 if {Wall.NORTH, Wall.SOUTH} & c else 1
        # paddles
        sx = -1 if dx < 0 else 1
        for p in self.__paddles:
            if collider.circle_rect_colision(self.__ball.bounds, p.bounds):
                dx = -1 * sx * (abs(dx) + 0.1)
        self.__ball.movement = (dx, dy)
        # walls
        if Wall.WEST in c:
            self.__scores[0] += 1
            self.__restart_ball()
        if Wall.EAST in c:
            self.__scores[1] += 1
            self.__restart_ball()

    def __paddle_collision(self):
        for p in self.__paddles:
            dx, dy = p.movement
            if collider.wall_rect_collision(self.window.bounds, p.bounds):
                dy *= -1
            p.movement = (dx, dy)

    def _update(self):
        """Update objects."""
        self.__ball_collision()
        self.__paddle_collision()
        Game._update(self)

    def _draw(self):
        self.window.clear()
        third = self.window.width // 3
        for i, s in enumerate(self.__scores):
            x = (2 - i)*third
            for c in str(s):
                d = self.digits[int(c)]
                d.position = (x, 5)
                x += d.rect.width + 2
                self.window.draw(d)
        Game._draw(self, False)
开发者ID:rafasgj,项目名称:algoritmos2,代码行数:67,代码来源:pong.py

示例4: Engine

# 需要导入模块: from window import Window [as 别名]
# 或者: from window.Window import draw [as 别名]

#.........这里部分代码省略.........
    def newgame(self):
        self.load('%s/default.save' % config.save_path)

    def loadgame(self, f='%s/savegame.save' % config.save_path):
        try:
            #sf = file(f)
            #close(f)
            self.load(f)
        except:
            self.newgame()


    def Run(self):
        self.title.show()
        self.newgame() #only comment out if not showing title
        self.hud.resize()
        self.automap.update_room()
        time = ika.GetTime()
        done = False
        self.music = ika.Music('%s/00_-_zaril_-_close_to_the_core.xm' %
                               config.music_path)
        self.music.loop = True
        self.music.Play()
        while not done:
            t = ika.GetTime()
            while t > time:
                # Uncomment for slow motion.
                #ika.Delay(2)
                self.tick()
                time += 1
            time = ika.GetTime()
            self.update_time()
            self.camera.update()
            self.draw()
            print >> fonts.one(0, 40), 'FPS:', ika.GetFrameRate()

            #for i, e in enumerate(self.entities):
            #    print >> fonts.one(0, 50 + 10*i), 'sprite', e.sprite

            ika.Input.Update()
            if controls.pause.Pressed():
                self.pause.menu()
                ika.Input.Unpress()
                # Make sure the engine doesn't have to play 'catchup'.
                time = ika.GetTime()
            #screenshot key
            if False:  #controls.confirm.Pressed(): #screenshot
                #self.text('This is a textbox.')
                ika.Input.Unpress()
                time = ika.GetTime()
                c = ika.Video.GrabCanvas(0, 0, ika.Video.xres, ika.Video.yres)
                c2 = ika.Image(c)
                c2.Blit(0, 0)
                c.Save('blah1.png')
            ika.Video.ShowPage()

    def draw(self):
        for thing in self.background_things:
            thing.draw()
        #if self.background:
        #    ika.Video.Blit(self.background, 0, 0)
        for i in range(ika.Map.layercount):
            ika.Map.Render(i)
            for ent in self.entities:
                if ent.layer == i and ent.visible:
                    ent.draw()
开发者ID:Hatchet2k4,项目名称:mannux,代码行数:70,代码来源:__init__.py


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