pygame系列_draw游戏画图

前端之家收集整理的这篇文章主要介绍了pygame系列_draw游戏画图前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

说到画图,pygame提供了一些很有用的方法进行画图。

pygame.draw.rect

下面是我做的demo

hongten_pygame

有鼠标在窗口中点击的时候,系统会自动画出一个矩形,按键盘任意键,清屏

代码部分:

pygame.locals * sys random * = { : : : : SCREEN_DEFAULT_SIZE = (500,500 SCREEN_DEFAULT_COLOR = screen = pygame.display.set_mode(SCREEN_DEFAULT_SIZE,32 1 event event.type == event.type == event.type == rect_color = (randint(0,255),randint(0,255 rect_pos = (randint(0,500),500 rect_pos_end = (500 - randint(rect_pos[0],500 - randint(rect_pos[1],500 pygame.display.update()
pygame.draw.circle

demo:

hongten_pygame

当鼠标在窗口中移动的时候,单击鼠标,即可在窗口中产生一个随机圆,按下键盘任意键,清屏

代码部分:

pygame.locals * sys random * = { : 1 event event.type == event.type == event.type == c_color = (randint(0,255 c_pos = (randint(0,500 c_r = randint(10,100 pygame.display.update()
pygame.draw.line

demo:

hongten_pygame

鼠标在窗口中移动的时候,总是有一些线和鼠标汇聚,当鼠标被点击的时候,就会记录下此时的形状

按下键盘任意键,清屏

当然你也可以取消这个功能

RECORD = False #取消记录鼠标轨迹

代码部分:

pygame.locals * sys random * = { : : SCREEN_WIDTH = 500 SCREEN_HEIGHT = 500 SCREEN_DEFAULT_SIZE = SCREEN_DEFAULT_COLOR = RECORD = screen = pygame.display.set_mode(SCREEN_DEFAULT_SIZE,32 point ps = points = [(0,0),(250,(500 (0,250),(0,500 (500,(500,500 1 event event.type == event.type == event.type == line_color = (randint(0,255 ps = c_p draw_lines(screen,c_p[0],c_p[1 event.type == x,y = line_color = (randint(0,255 pygame.display.update()

更多信息:

========================================================

More reading,and english is important.

I'm Hongten

大哥哥大姐姐,觉得有用打赏点哦!多多少少没关系,一分也是对我的支持和鼓励。谢谢。Hongten博客排名在100名以内。粉丝过千。Hongten出品,必是精品。

E | hongtenzone@foxmail.com  B | 

========================================================

猜你在找的Python相关文章