当前位置:   article > 正文

PYGAME - 简单图形绘制_pygame poly

pygame poly

绘制简单的图形:

语法格式:Pygame.draw.XXX(*params)

矩形: rect(Surface, color, Rect, width=0) (Rect是范围,边框=0(填充),1边框大小(向外扩展边框))

多边形: polygan(Surface, color, pointlist, width=0)

圆形: circle(Surface, color, pos, radius, width=0) (pos圆心位置, radius 半径)

椭圆: ellipse(Surface, color, Rect, width=0)(Rect表示一个限定矩形)

弧线: arc(Surface, color, Rect, start_angle, stop_angle, width=1) (不能填充)

线段: line(Surface, color, start_pos, end_pos, widht=1) (只能表示宽度)

         Lines(Surface, color, closed, pointlist, width=1) (closed表示是否闭合,不能填充)

抗锯齿: aaline(Surface, color, startpos, endpos, blend=1)

           aalines(Surface, color, closed, pointlist, blend=1) (blend表示是否开启抗锯齿,pygame2.2后默认都是true)

EG: 绘制一条小鱼儿:

 

 

  1. import pygame
  2. import sys
  3. from pygame.locals import *
  4. import math
  5. size = width, height = 800, 600
  6. bg = (255, 255, 255)
  7. clock = pygame.time.Clock()
  8. screen = pygame.display.set_mode(size)
  9. pygame.display.set_caption('Simple Figures')
  10. pos = (50,251)
  11. moving = False
  12. while True:
  13. for event in pygame.event.get():
  14. if event.type == QUIT:
  15. sys.exit()
  16. if event.type == MOUSEBUTTONDOWN:
  17. if event.button == 1:
  18. moving = True
  19. if event.type == MOUSEBUTTONUP:
  20. if event.button == 1:
  21. moving = False
  22. screen.fill(bg)
  23. # drawing a fish
  24. pygame.draw.rect(screen, (0, 255, 0), (250, 150, 300, 200), 0)
  25. pygame.draw.aalines(screen, (255,0,0),1,((80,250),(250,150),(250,350)), 1)
  26. pygame.draw.polygon(screen, (0,0,255),((550,150),(650,350),(650,150),(550,350)), 0)
  27. pygame.draw.ellipse(screen, (255,0,0), (110, 210, 75, 75), 0)
  28. pygame.draw.arc(screen, (125,125,125), (250, 150, 30, 200), -math.pi/2, -3 * math.pi / 2, 2 )
  29. # a moving ball that you can move with left button of mouse
  30. if moving:
  31. pos = pygame.mouse.get_pos()
  32. pygame.draw.circle(screen, (200, 200, 0), pos, 20.0, 0)
  33. pygame.display.flip()
  34. clock.tick(120)

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/154450?site
推荐阅读
相关标签
  

闽ICP备14008679号