Jump to content
  • Advertisement
Sign in to follow this  
Crazylegs830

Randomly generated circles in pygame.

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement

Hmmm, I have this code:

 

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

 

And get this error:

 

pygame.draw.circle(screen, WHITE, random.randint(0,1600), radius)
TypeError: must be 2-item sequence, not int
 

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!