复习的时候好好看看,都是基础
import pygame
import math
"""
0.初始化
1.创建窗口
2.设置窗口标题
3.设置窗口背景颜色
4.添加图片,修改图片大小,角度
5.添加文字
6.画图
"""
def main():
pygame.init()
window = pygame.display.set_mode((400, 600))
pygame.display.set_caption('第一个窗口')
window.fill((255, 255, 255))
image = pygame.image.load('images/wo.jpg')
image1 = pygame.transform.rotozoom(image, 0, 0.5)
print(image.get_size())
window.blit(image1, (0, 0))
new_image1 = pygame.transform.scale(image, (200, 200))
window.blit(new_image1, (200, 100))
new_image2 = pygame.transform.rotozoom(image, 180, 0.5)
window.blit(new_image2, (100, 400))
# window.fill((255, 255, 255))
font = pygame.font.Font('images/font2.ttf', 50)
text = font.render('hello ming!', True, (12, 122, 232))
window.blit(text, (0, 300))
# window.fill((255, 255, 255))
pygame.draw.line(window, (100, 0, 33), (400, 0), (200, 500), 5)
pygame.draw.lines(window, (23, 100, 34), True, [(100, 100), (150, 100), (200, 150), (50, 150)], 4)
pygame.draw.circle(window, (40, 20, 200), (200, 300), 50, 3)
pygame.draw.polygon(window, (0, 240, 44), [(75, 50), (200, 50), (250, 200), (25, 200)], 7)
pygame.draw.rect(window, (200, 100, 50), (50, 400, 20, 40), 4)
pygame.draw.arc(window, (255, 0, 0), (100, 500, 80, 50), math.pi/4, math.pi, 6)
# window.fill((255, 255, 255))
pygame.display.flip()
point_list = []
flag = False
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
exit()
if event.type == pygame.MOUSEBUTTONDOWN:
point_list = []
flag = True
elif event.type == pygame.MOUSEBUTTONUP:
flag = False
elif event.type == pygame.MOUSEMOTION:
if flag:
point_list.append(event.pos)
if len(point_list) < 2:
break
pygame.draw.lines(window, (200, 0, 0), False, point_list, 3)
pygame.display.flip()
if __name__ == '__main__':
main()
网友评论