import pygame
import sys
pygame.init()
WHITE = (255,255,255)
BLACK = (0,0,0)
size = width, height = 640, 200
screen = pygame.display.set_mode(size)
pygame.display.set_caption("图形")
clock = pygame.time.Clock()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
screen.fill(WHITE)
pygame.draw.rect(screen, BLACK, (50, 50, 150, 50), 0)
pygame.draw.rect(screen, BLACK, (250, 50, 150, 50), 1)
pygame.draw.rect(screen, BLACK, (450, 50, 150, 50), 10)
pygame.display.flip()
clock.tick(10)
函数pygame.draw.rect(screen, BLACK, (50, 50, 150, 50), 0)
总共四个参数,第三个参数是左上角坐标,宽度,深度
第四个是边框宽度,如果是0,就全部填充
import pygame
import sys
pygame.init()
WHITE = (255,255,255)
BLACK = (0,0,0)
POINTS = [(200, 75), (300, 25),(400, 75),(450, 25),(450, 125), (400, 75),(300,125)]
size = width, height = 640, 200
screen = pygame.display.set_mode(size)
pygame.display.set_caption("图形")
clock = pygame.time.Clock()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
screen.fill(WHITE)
pygame.draw.polygon(screen, BLACK, POINTS, 0)
pygame.display.flip()
clock.tick(10)
函数pygame.draw.polygon(screen, BLACK, POINTS, 0)
第三个参数是各个顶点的坐标
第四个依旧是边框宽度,0的时候填充
import pygame
import sys
pygame.init()
WHITE = (255,255,255)
BLACK = (0,0,0)
BLUE = (0,0,255)
RED = (255,0,0)
size = width, height = 640, 500
screen = pygame.display.set_mode(size)
pygame.display.set_caption("图形")
position = size[0]//2,size[1]//2
clock = pygame.time.Clock()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
screen.fill(WHITE)
pygame.draw.circle(screen, BLACK, position, 25, 0)
pygame.draw.circle(screen, BLUE, position, 75, 1)
pygame.draw.circle(screen, RED, position, 125, 1)
pygame.display.flip()
clock.tick(10)
函数pygame.draw.circle(screen, BLACK, position, 25, 0)
第三个参数是圆心
第四个是半径
第四个依旧是边框宽度,0的时候填充
import pygame
import sys
pygame.init()
WHITE = (255,255,255)
BLACK = (0,0,0)
BLUE = (0,0,255)
RED = (255,0,0)
size = width, height = 640, 500
screen = pygame.display.set_mode(size)
pygame.display.set_caption("图形")
clock = pygame.time.Clock()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
screen.fill(WHITE)
pygame.draw.ellipse(screen, BLACK, (100, 100, 440, 100), 1)
pygame.draw.ellipse(screen, BLACK, (220, 50, 200, 200), 0)
pygame.display.flip()
clock.tick(10)
函数pygame.draw.ellipse(screen, BLACK, (100, 100, 440, 100), 1)
第三个参数就是矩形的左上角,宽度和深度
第四个是边框宽度,0填充
import pygame
import sys
import math
pygame.init()
WHITE = (255,255,255)
BLACK = (0,0,0)
BLUE = (0,0,255)
RED = (255,0,0)
size = width, height = 640, 500
screen = pygame.display.set_mode(size)
pygame.display.set_caption("图形")
clock = pygame.time.Clock()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
screen.fill(WHITE)
pygame.draw.arc(screen, BLACK, (100, 100, 440, 100),0, math.pi, 1)
pygame.draw.arc(screen, BLACK, (220, 50, 200, 200), math.pi, math.pi * 2, 1)
pygame.display.flip()
clock.tick(10)
函数pygame.draw.arc(screen, BLACK, (100, 100, 440, 100),0, math.pi, 1)
第三个还是矩形的边界数据
第四个和第五个是指开始的角度和结束的角度
最后一个是边框宽度,但是0的时候不会填充
import pygame
import sys
import math
pygame.init()
WHITE = (255,255,255)
BLACK = (0,0,0)
BLUE = (0,0,255)
RED = (255,0,0)
size = width, height = 640, 500
screen = pygame.display.set_mode(size)
pygame.display.set_caption("图形")
POINTS = [(200, 75), (300, 25),(400, 75),(450, 25),(450, 125), (400, 75),(300,125)]
clock = pygame.time.Clock()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
screen.fill(WHITE)
pygame.draw.lines(screen, BLACK, 0, POINTS, 1)
pygame.display.flip()
clock.tick(10)
函数pygame.draw.lines(screen, BLACK, 0, POINTS, 1)
第三个是是否要闭合,0是不闭合,1是闭合
但是最后一个参数为0时不能填充
import pygame
import sys
import math
pygame.init()
WHITE = (255,255,255)
BLACK = (0,0,0)
BLUE = (0,0,255)
RED = (255,0,0)
size = width, height = 640, 500
screen = pygame.display.set_mode(size)
pygame.display.set_caption("图形")
POINTS = [(200, 75), (300, 25),(400, 75),(450, 25),(450, 125), (400, 75),(300,125)]
clock = pygame.time.Clock()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
screen.fill(WHITE)
pygame.draw.line(screen, BLACK, (100, 200),(540, 250), 1)
pygame.draw.aaline(screen, BLACK, (100, 250),(540,300), 1)
pygame.draw.aaline(screen, BLACK, (100, 300),(540,350), 0)
pygame.display.flip()
clock.tick(10)
函数pygame.draw.aaline(screen, BLACK, (100, 250),(540,300), 1)
最后一个参数是是否开启抗锯齿
1是开启,0是不开启