Python中的画图初体验

时间:2015-05-28 14:00:08   收藏:0   阅读:202

学到《父与子编程之旅》的16章了,跟书上的例子进行学习,学会了画圆,我又找到了画线的方法,于是就可以在screen上画日本国旗了:

技术分享

手动画的不好看,也可以不手动画,直接画线:

技术分享

代码如下:

 1 import pygame,sys  
 2 from pygame.locals import * 
 3 print pygame.ver
 4 pygame.init()
 5 screen = pygame.display.set_mode([640,480])
 6 color=(200,156,64)  
 7 points=[] 
 8 screen.fill([255,255,255])
 9 pygame.draw.circle(screen,[255,0,0],[200,200],70,0)
10 pygame.draw.line(screen,color,(20,20),(400,20),1)
11 pygame.draw.line(screen,color,(20,20),(20,400),1)
12 pygame.draw.line(screen,color,(20,400),(400,400),1)
13 pygame.draw.line(screen,color,(400,400),(400,20),1)
14 pygame.display.flip()
15 running = True
16 while running:
17     for event in pygame.event.get():
18         if event.type == pygame.QUIT:
19             running = False
20 ##        if event.type==MOUSEBUTTONDOWN:  
21 ##            points.append(event.pos)
22 ##    if len(points)>1:  
23 ##        pygame.draw.lines(screen,color, False, points, 5)
24 ##    pygame.display.update()  
25 pygame.quit()
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!