![](https://csdnimg.cn/release/download_crawler_static/10290821/bg6.jpg)
if event.type== pygame.QUIT:
sys.exit()
2
2
2
2 、连接多个点形成线
pygame.draw.lines() 方法可以将多个点连接成为线。该方法有 5 个参数: surface 表面 、 颜
色、闭合线或者非闭合线(如果闭合 为 True, 否则为 False ) ,点的列表,线宽。
pygame.draw.lines(surface, [color],False/True , plotpoints,1) 。下面的例子画出了一条马路,具
体如下:
#@ 小五义 http://www.cnblogs.com/xiaowuyi
import pygame,sys
def lineleft(): # 画马路左边界
plotpoints= []
for x in range(0,640 ):
y =-5*x+1000 plotpoints.append([x,y])
pygame.draw.lines(screen,[0,0,0],False,plotpoints, 5 )
pygame.display.flip()
def lineright(): # 画马路右边界
plotpoints= []
for x in range(0,640 ):
y =5*x-2000 plotpoints.append([x,y])
pygame.draw.lines(screen,[0,0,0],False,plotpoints, 5 )
pygame.display.flip()
def linemiddle(): # 画马路中间虚线
plotpoints= []
x =300
for y in range(0,480,20 ):
plotpoints.append([x,y])
if len(plotpoints)==2 :
pygame.draw.lines(screen,[0,0,0],False,plotpoints, 5 )
plotpoints = []
pygame.display.flip()
pygame.init()
screen =pygame.display.set_caption( 'hello world!' )
screen =pygame.display.set_mode([640,480 ])
screen.fill([ 255,255,255 ])
lineleft()
lineright()
linemiddle()
while True:
for event in pygame.event.get():
if event.type== pygame.QUIT:
sys.exit()
3
3
3
3 、引用图像