pygame入门之四:线的艺术 发表于 2021-09-29 | 更新于: 2021-09-29 | 分类于 pygame | | 阅读数 字数统计: 354 | 阅读时长 ≈ 2 太极 123456789101112131415161718192021222324252627282930import mathimport pygamewhite=255,255,255black=0,0,0pygame.init()pygame.display.set_caption("TaiChi")screen = pygame.display.set_mode([800,800])screen.fill(white)def draw(): pygame.draw.circle(screen,black,[400,400],300,0) pygame.draw.rect(screen, white,[100,400,700,400],0) pygame.draw.circle(screen,black,[250,400],150,0) pygame.draw.circle(screen,white,[550,400],150,0) pygame.draw.circle(screen,white,[225,400],50,0) pygame.draw.circle(screen,black,[575,400],50,0) pygame.draw.arc(screen,black,[100,100,600,600],math.pi,2*math.pi,1)is_running = Truewhile is_running: for event in pygame.event.get(): if event.type == pygame.QUIT: is_running = False if event.type == pygame.KEYDOWN and event.key == ord('s'): # 按s保存图片 pygame.image.save(screen, 'TaiChi.jpg') draw() pygame.display.update()pygame.quit() 分形树 123456789101112131415161718192021222324252627282930313233343536373839import pygameimport mathimport randomwhite=255,255,255black=0,0,0pygame.init()pygame.display.set_caption("Tree")pygame.display.set_mode([600,600])screen = pygame.display.get_surface()clock = pygame.time.Clock()def draw(depth=10,angle=-90, x=300, y=600): if depth: x1,y1=x,y x2,y2 = x1 + int(math.cos(math.radians(angle)) * depth * 10.0),y1 + int(math.sin(math.radians(angle)) * depth * 10.0) color=(random.randint(0,255),random.randint(0,255),random.randint(0,255)) pygame.draw.line(screen, color, (x1, y1), (x2, y2), 2) draw(depth - 1,angle - 20, x2, y2,) draw(depth - 1,angle + 20, x2, y2, )is_running = Truedepth=1while is_running: for event in pygame.event.get(): if event.type == pygame.QUIT: is_running = False if event.type == pygame.KEYDOWN and event.key == ord('s'): # 按s保存图片 pygame.image.save(screen, 'Tree.jpg') depth+=1 if depth>10: depth%=10 screen.fill(black) # 清屏 draw(depth) clock.tick(5) pygame.display.update()pygame.quit() 不要打赏,只求关注呀QAQ 打赏 微信支付 支付宝 本文作者: cheungducknew 本文链接: http://ducknew.cf/posts/c138c5a8/ 版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 3.0 许可协议。转载请注明出处!