This code was originally meant for user input, however I want it to randomly create a polygon rather than manually selecting points myself. I'll probably make it a for loop rather than a while loop so you needn't mention that. 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()
What I am attempting to do is make a coordinate point randomiser, however it isn't compatible with this code for some reason. I have tried other things as well, and remnants of those attempts may be visible. The segment I changed goes from the for event in pygame.event.getto the screen.fill((255,255,255)). The original code there went like this:
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
exit()
if event.type == MOUSEBUTTONDOWN:
points.append(event.pos)
screen.fill((255,255,255))
When I run the program I get a
Traceback (most recent call last):
File "H:/Documents/it/Python/manual_box drawer.py", line 26, in <module>
pygame.draw.circle(screen, (0,0,255), point, 5)
TypeError: must be 2-item sequence, not int
error report.
Aucun commentaire:
Enregistrer un commentaire