| | |
Pygame question2
Thread Solved |
•
•
Join Date: Mar 2009
Posts: 10
Reputation:
Solved Threads: 1
Python beginner try to learn pygame. Here is a program I made for random color circles popping out.
It is pretty, I was excited. Now I want to make all circle fly, my goal is, to make random color circles randomly pop out and then fly toward the top of the window. So of course it will include the code that y -= something. However I tried different ways, none worked out, so here is my code for only one circle going up. Please give me some advice on how to make a lot of these circles pop out from random place and then go up.
Thanks. Here is my code for one sucessful flying circle.
Python Syntax (Toggle Plain Text)
import pygame, random pygame.init() X = 680 Y = 460 def main(): screen = pygame.display.set_mode((X,Y)) pygame.display.set_caption('circles') background = pygame.Surface(screen.get_size()) background = background.convert() background.fill(pygame.color.Color('white')) run = True clock = pygame.time.Clock() while run: clock.tick(30) for event in pygame.event.get(): if event.type == pygame.QUIT: run = False elif event.type == pygame.KEYDOWN: if event.key == pygame.K_q: run = False for count in range(50): r = random.randint(1,40) a = random.randint(1,X) b = random.randint(1, Y) c = random.randint(1, 255) d = random.randint(1, 255) e = random.randint(1, 255) pygame.draw.circle(background, (c,d,e), (a,b), r, 0) screen.blit(background, (0,0)) pygame.display.flip() if __name__ == "__main__": main()
It is pretty, I was excited. Now I want to make all circle fly, my goal is, to make random color circles randomly pop out and then fly toward the top of the window. So of course it will include the code that y -= something. However I tried different ways, none worked out, so here is my code for only one circle going up. Please give me some advice on how to make a lot of these circles pop out from random place and then go up.
Thanks. Here is my code for one sucessful flying circle.
Python Syntax (Toggle Plain Text)
import pygame, random pygame.init() X = 680 Y = 460 def main(): screen = pygame.display.set_mode((X,Y)) pygame.display.set_caption('circles') background = pygame.Surface(screen.get_size()) background = background.convert() background.fill(pygame.color.Color('white')) run = True clock = pygame.time.Clock() a = random.randint(1,X) b = random.randint(1, Y) color1 = random.randint(1, 255) color2 = random.randint(1, 255) color3 = random.randint(1, 255) radius = random.randint(10,40) while run: clock.tick(30) background.fill(pygame.color.Color('white')) for event in pygame.event.get(): if event.type == pygame.QUIT: run = False elif event.type == pygame.KEYDOWN: if event.key == pygame.K_q: run = False pygame.draw.circle(background, (color1,color2,color3),\ (a,b), radius, 0) b-=10 screen.blit(background, (0,0)) pygame.display.flip() if __name__ == "__main__": main()
•
•
Join Date: Mar 2009
Posts: 10
Reputation:
Solved Threads: 1
0
#2 26 Days Ago
I kind of got what I wanted. But it's still one circle floating up at a time. Please give advice on how to make multiple circles. Thanks
Python Syntax (Toggle Plain Text)
import pygame, random pygame.init() X = 680 Y = 460 def draw(background,screen): a = random.randint(1,X) b = random.randint(1, Y) color1 = random.randint(1, 255) color2 = random.randint(1, 255) color3 = random.randint(1, 255) radius = random.randint(10,40) while b > 0: background.fill(pygame.color.Color('white')) pygame.draw.circle(background, (color1,color2,color3),\ (a,b), radius, 0) b -= 1 screen.blit(background, (0,0)) pygame.display.flip() def main(): screen = pygame.display.set_mode((X,Y)) pygame.display.set_caption('circles') background = pygame.Surface(screen.get_size()) background = background.convert() background.fill(pygame.color.Color('white')) run = True while run: clock = pygame.time.Clock() clock.tick(30) for event in pygame.event.get(): if event.type == pygame.QUIT: run = False elif event.type == pygame.KEYDOWN: if event.key == pygame.K_q: run = False draw(background,screen) if __name__ == "__main__": main()
Last edited by FengG; 26 Days Ago at 1:13 am.
•
•
Join Date: Mar 2009
Posts: 10
Reputation:
Solved Threads: 1
0
#4 25 Days Ago
•
•
•
•
Looks like you have made nice progress with coding pygame. The pygame module has something called sprites that, as far as I remember, are more suitable for what you have in mind.
http://www.cs.iupui.edu/~aharris/pygame/
this is the source I learn from, good lessons for pygame with videos and powerpoints, maybe we can put the link somewhere so people who are interested in pygame can get something out of it.
Any advice on weather learning pygame is a good path to master the python language?
Thanks
![]() |
Similar Threads
- Code Snippet: Pygame Curve Library for Anti-Aliased Circles and Curved Surface Corners. (Python)
- Windows freeze in pygame- Windows (Python)
- pygame full screen help (Python)
- Pygame crashing (Python)
Other Threads in the Python Forum
- Previous Thread: Py_INCREF / Py_DECREF
- Next Thread: With with Pascals Triangle Program
| Thread Tools | Search this Thread |
accessdenied advanced apache application argv array beginner book change command converter countpasswordentry csv curved dan08 def dictionary dynamic edit enter event examples file float format function google gui homework import inches input jaunty java keyboard lapse library line lines linux list lists loop microphone mouse movingimageswithpygame mysqlquery newb number numbers numeric obexftp output parameters parsing path phonebook plugin port prime programming projects py2exe pygame pygtk pyopengl python random recursion redirect remote return reverse scrolledtext session simple skinning software sprite statictext string strings syntax terminal text threading time tlapse trick tuple tutorial ubuntu unicode unit urllib urllib2 variable voip wordgame wxpython






