Public Group

# Randomly generated circles in pygame.

This topic is 2077 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello I'm back and need more help what I was planning to do was to have little circles randomly places on my screen. How would I go about doing that? Sorry if this is a stupid question still a beginner.

##### Share on other sites
pygame.draw.circle? Give it a randomized pos and radius, and boom.

##### Share on other sites

pygame.draw.circle? Give it a randomized pos and radius, and boom.

Ah, Ok sorry didn't know it was so simple.

##### Share on other sites

pygame.draw.circle? Give it a randomized pos and radius, and boom.

Ah, Ok sorry didn't know it was so simple.

Can you show me some code?

##### Share on other sites

Hmmm, I have this code:

And get this error:

TypeError: must be 2-item sequence, not int

##### Share on other sites

pygame.draw.circle() wants both an x and a y coordinate.

random.randint(0, 1600) gives you 1 integer (which in this case translates to 1 coordinate).

You need to generate 2 coordinates, and feed them into the draw function.

I don't know the syntax of pygame more than what a minute of googling tells me, but at a guess something like:

pygame.draw.circle(screen, WHITE, (random.randint(0, 1600), random.randint(0, 1600)), radius)

##### Share on other sites

pygame.draw.circle() wants both an x and a y coordinate.

random.randint(0, 1600) gives you 1 integer (which in this case translates to 1 coordinate).

You need to generate 2 coordinates, and feed them into the draw function.

I don't know the syntax of pygame more than what a minute of googling tells me, but at a guess something like:

pygame.draw.circle(screen, WHITE, (random.randint(0, 1600), random.randint(0, 1600)), radius)

I think it worked, but how do I make it appear over another shape?

##### Share on other sites

The pygame draw function returns a Rect, so blit the Rect onto the screen Surface after the other shape has been blitted.

Edited by PeterF

##### Share on other sites

The pygame draw function returns a Rect, so blit the Rect onto the screen Surface after the other shape has been blitted.

And to blit them what do I do? I am sincerely sorry for my lack of knowledge in programming.

• 18
• 29
• 11
• 23
• 16