標籤:
學到《父與子編程之旅》的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 = True16 while running:17 for event in pygame.event.get():18 if event.type == pygame.QUIT:19 running = False20 ## 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()
Python中的畫圖初體驗