以下是部分代码预览:
"""pygame和pymunk制作的单摆示例程序""" import sys import random import pygame import pymunk import pymunk.pygame_util from pygame.locals import * # 新建屏幕 size = width,height = 600,600 pygame.init() screen = pygame.display.set_mode(size) pygame.display.set_caption("单摆测试,Simple pendulum test by lixingqiu") # 重力空间 space = pymunk.Space() space.gravity = (0.0, -2000.0) center_x = width // 2 center_y = height //2 mass = 10 # 球的质量 radius = 25 # 球的半径 moment = pymunk.moment_for_circle(mass, radius ,radius ) body = pymunk.Body(mass, moment) body.position = (center_x,center_y-125) shape = pymunk.Circle(body, radius) shape.elasticity = 0.9999999 space.add(body, shape) body.force=(100000,0) # 给力 running = True clock = pygame.time.Clock() while running: for event in pygame.event.get(): if event.type in( QUIT,KEYDOWN,K_ESCAPE): running = False break space.step(1/50.0) screen.fill((255,255,255)) space.debug_draw(draw_options) # 重画重力空间内的shape pygame.display.flip() clock.tick(50) pygame.quit()
下载完整源代码与素材,请
需要浏览更多吗?
成为会员后,登陆才能继续浏览!联系微信scratch8即可办理会员。
(会员专属:能浏览所有文章,下载所有带链接的Python资源。)