### 學習總結-《父與子的編程之旅》chapter 16

``````import  sys,pygame
pygame.init()
screen = pygame.display.set_mode([640,480])
screen.fill([255,255,255])
x = 0
y = 0
x_speed = 10
#y_speed = 3

running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False

pygame.time.delay(20)
pygame.draw.rect(screen, [255, 255, 255], [x, y, 800, 500], 0)
x = x + x_speed
# y = y + y_speed
if x>screen.get_width()-350 or x <0:
#x_speed = -x_speed
x = -10
# if y>screen.get_height() -350 or y<0:
# y_speed = -y_speed
screen.blit(mytag,[x,y])
pygame.display.flip()
pygame.quit()``````

``````import pygame,sys
pygame.init()

dots = [[221,432],[43,264],[123,200],[12,300],[200,126]]

screen = pygame.display.set_mode([640,480])
screen.fill([255,255,255])
pygame.draw.lines(screen,[255,0,0],True,dots,2)
screen.set_at([43,264],[0,0,0])

pixel_color = screen.get_at([43,264])
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.display.flip()
pygame.time.delay(3)
pygame.quit()
print(pixel_color)``````

``````import  pygame,sys,random
from pygame.color import THECOLORS
pygame.init()
screen = pygame.display.set_mode([640,480])
screen.fill([255,255,255])
for i in range (100):
width = random.randint(0,250)
heigh = random.randint(0,100)
top = random.randint(0,400)
left = random.randint(0,500)
color_name_list = list(THECOLORS.keys()) #python3要先把字典轉化為列表 python2則 color_name = random.choice(THECOLORS.keys())
color_name = random.choice(color_name_list)
color = THECOLORS[color_name]
line_width = random.randint(1,3)
pygame.draw.rect(screen,color,[left,top,width,heigh],line_width)
#pygame.draw.rect(screen,[200,0,0],[100,50,200,200],10)
#在哪個表面畫，顏色RGB，位置，半徑單位像素，線寬
#pygame.display.flip()#顯示“下一屏”
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False

pygame.quit()``````