学到《父与子编程之旅》的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()
时间: 2024-10-22 16:06:23