points=[(100,30),(200,30),(250,130),(50,130)]
pygame.draw.polygon(screen, (0, 144, 0), points)
绘制顺序是从左上开始,右上,右下,左下
如果是左上,右上,左下,右下就会变成两个三角形
实验程序 转载
https://blog.csdn.net/justperseve/article/details/79170787
实验程序 转载
import pygame
from pygame.locals import *
from sys import exit
from random import *
pygame.init()
screen = pygame.display.set_mode((640, 480), 0, 32)
points = []
while True:
for event in pygame.event.get():
if event.type == QUIT:
exit()
if event.type == MOUSEBUTTONDOWN:
# add the position to points
points.append(event.pos)
# refresh the screen
screen.fill((255,255,255))
# draw the polygon
if len(points) >= 3:
pygame.draw.polygon(screen, (0,255,0), points)
# draw the point
for point in points:
pygame.draw.circle(screen, (0,0,255), point, 5)
# display on screen
pygame.display.update()
————————————————
版权声明:本文为CSDN博主「季科」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/justperseve/article/details/79170787