此代码最初是供用户输入的,但我希望它随机创建一个多边形,而不是自己手动选择点。
也许我不需要你说一个循环。在import pygame
from pygame.locals import *
from sys import exit
import random
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:
pygame.quit()
exit()
point1 = randint(0,639)
point2 = randint(0,479)
points = (str(randint(0,639)), str(randint(0,479)))
screen.fill((255,255,255))
if len(points) >= 3:
pygame.draw.polygon(screen, (0,255,0), points)
for point in points:
pygame.draw.circle(screen, (0,0,255), point, 5)
pygame.display.update()
我要做的是做一个坐标点随机发生器。
但是,由于某些原因,它与此代码不兼容。我也尝试了其他方法,这些尝试的残余可能会被看到。
我更改的段从for event in pygame.event.get到{}。
最初的代码是这样的:
^{pr2}$
当我运行程序时,我得到一个Traceback (most recent call last):
File "H:/Documents/it/Python/manual_box drawer.py", line 26, in
pygame.draw.circle(screen, (0,0,255), point, 5)
TypeError: must be 2-item sequence, not int
错误报告。在