展示怎么制作动画。。。。
#-*- 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()
时间: 2024-10-03 15:14:51