淘先锋技术网

首页 1 2 3 4 5 6 7
import pyglet
from datetime import datetime

WIDTH = 960
HEIGHT = 720
window = pyglet.window.Window(WIDTH,HEIGHT)

background_pattern= pyglet.image.SolidColorImagePattern(color=(255,255,255,255))
background_image = background_pattern.create_image(WIDTH,HEIGHT)

pattern = pyglet.image.SolidColorImagePattern(color=(200,200,130,150))
image = pattern.create_image(150,150)
image.anchor_x = image.width//2
image.anchor_y = image.height//2
ball = pyglet.sprite.Sprite(image, x=100, y=200)
ball.opacity= 200

@window.event
def on_draw():
    window.clear()
    background_image.blit(0,0)
    image.blit(0,0)
    ball.draw()

@window.event
def on_mouse_release(x,y,button,modifier):
    print(x,y,button,modifier)

@window.event
def on_mouse_motion(x,y,dx,dy):
    ball.x=x
    ball.y=y

def callback(dt):
    #print(f"{dt} seconds since last callback")
    s = datetime.now().second
    ball.rotation += 1

pyglet.clock.schedule_interval(callback,1/60)

pyglet.app.run()