• pyglet--旋转的矩形


    展示怎么制作动画。。。。

    #-*- coding:utf-8 -*-
    from pyglet.gl import *
    from pyglet import clock
    
    def draw_rect(x, y,z,width, height,ang):
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        glLoadIdentity()
        glTranslatef(x+width/2,y+height/2,0.0)
        glRotatef(ang,0.0,0.0,1.0)
        glBegin(GL_LINE_LOOP)
        glColor3f(1.0,0.0,0.0)
        glVertex3f(x, y,z)
        glColor3f(1.0,0.0,0.0)
        glVertex3f(x + width, y,z)
        glColor3f(1.0,0.0,0.0)
        glVertex3f(x + width, y + height,z)
        glColor3f(1.0,0.0,0.0)
        glVertex3f(x, y + height,z)
        glEnd()
        
    
    class Button():
        x=y=z=0
        width=height=10.0
        ang=0
        def draw(self):
            draw_rect(self.x,self.y,self.z,self.width,self.height,self.ang)
            
    class MyWindow(pyglet.window.Window):
        def __init__(self):
            super(MyWindow,self).__init__()
            #按钮
            self.button=Button()
            self.button.x=10
            self.button.y=10
            self.button.z=0
            self.button.width=self.width/2
            self.button.height=self.height/2
            self.button.ang=0
    
            self.need_draw=[
                    self.button,
                                ]
        def on_draw(self):
            self.clear()
            for draw_object in self.need_draw:
                draw_object.draw()
        def value_change(self,dt):
            self.button.ang+=0.5
            
    
    if __name__ == "__main__":
        wn=MyWindow()
        clock.schedule_interval(wn.value_change,0.5)
    pyglet.app.run()
        
            
  • 相关阅读:

    模块
    序列化模块
    time模块、os模块、sys模块
    re模块、collections模块、random模块
    正则表达式
    递归函数和二分查找
    匿名函数
    推推导式和内置函数
    Java引用类型与值类型——Java面向对象基础(7)
  • 原文地址:https://www.cnblogs.com/yinwei-space/p/4604756.html
Copyright © 2020-2023  润新知