python - Making a random coordinate generator -


this code meant user input, want randomly create polygon rather manually selecting points myself.
i'll make loop, rather while loop don't need mention that.

import pygame pygame.locals import * sys import exit import random random import *  pygame.init() screen = pygame.display.set_mode((640, 480), 0, 32) points = []   while true:      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)         point in points:             pygame.draw.circle(screen, (0,0,255), point, 5)              pygame.display.update() 

what attempting make coordinate point randomizer.
however, isn't compatible code reason. tried other things well, , remnants of attempts may visible.
segment changed goes for event in pygame.event.getto screen.fill((255,255,255)).
original code this:

while true:     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 run program, 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 2-item sequence, not int 

error report.

i think

points = (str(randint(0,639)), str(randint(0,479))) 

should written (the comma makes tuple). need append points list rather re-assign variable.

points.append( (point1, point2,) ) 

then can loop on points , draw them trying do.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -