方法二:画个直径为1的圆


importpygame,sys

pygame.init()

screen=pygame.display.set_caption('helloworld!')

screen=pygame.display.set_mode([640,480])

screen.fill([255,255,255])

pygame.draw.circle(screen,[0,0,0],[150,200],1,1)

pygame.display.flip()

whileTrue:

foreventinpygame.event.get():

ifevent.type==pygame.QUIT:

sys.exit()


方法三:这种方法并不是画上去的,而是改变了surface上某个点的颜色,这样看上去像是画了一个点screen.set_at()。另外,如果要得到某个像素的颜色,可以使用screen.get_at()。

importpygame,sys

pygame.init()

screen=pygame.display.set_caption('helloworld!')

screen=pygame.display.set_mode([640,480])

screen.fill([255,255,255])

screen.set_at([150,150],[255,0,0])#将150,150改为红色。

pygame.display.flip()

whileTrue:

foreventinpygame.event.get():

ifevent.type==pygame.QUIT:

sys.exit()

2、连接多个点形成线

pygame.draw.lines()方法可以将多个点连接成为线。该方法有5个参数:surface表面、颜色、闭合线或者非闭合线(如果闭合为True,否则为False),点的列表,线宽。pygame.draw.lines(surface,[color],False/True,plotpoints,1)。下面的例子画出了一条马路,具体如下:


importpygame,sys

deflineleft():#画马路左边界

plotpoints=[]

forxinrange(0,640):

y=-5*x+1000

plotpoints.append([x,y])

pygame.draw.lines(screen,[0,0,0],False,plotpoints,5)

pygame.display.flip()

deflineright():#画马路右边界

plotpoints=[]

forxinrange(0,640):

y=5*x-2000

plotpoints.append([x,y])

pygame.draw.lines(screen,[0,0,0],False,plotpoints,5)

pygame.display.flip()

deflinemiddle():#画马路中间虚线

plotpoints=[]

x=300

foryinrange(0,480,20):

plotpoints.append([x,y])

iflen(plotpoints)==2:

pygame.draw.lines(screen,[0,0,0],False,plotpoints,5)

plotpoints=[]

pygame.display.flip()

pygame.init() screen=pygame.display.set_caption('helloworld!') screen=pygame.display.set_mode([640,480]) screen.fill([255,255,255]) lineleft() lineright() linemiddle() whileTrue: foreventinpygame.event.get(): ifevent.type==pygame.QUIT: sys.exit()

热门推荐

1 虎年新年专属祝福语简短
2 恋爱很久的祝福语简短
3 单位搬迁新楼祝福语简短
4 新年祝福语给婆婆简短
5 简短媳妇的生日祝福语
6 相恋人回去祝福语简短
7 新人给朋友祝福语简短
8 结婚给姐妹祝福语简短
9 结婚对白誓言简短祝福语
10 八一幼儿祝福语大全简短
11 公司乔迁食堂祝福语简短
12 婚礼结束聚餐祝福语简短
13 儿媳买车妈妈祝福语简短
14 毕业送礼老师祝福语简短
15 同事辞职正常祝福语简短
16 恭贺新婚文案祝福语简短
17 金店立秋祝福语简短英文
18 婆婆高寿祝福语大全简短