User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Python section within the Software Development category of DaniWeb, a massive community of 391,604 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,649 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Python advertiser:

Starting Python

Join Date: Oct 2004
Location: Mojave Desert
Posts: 2,394
Reputation: vegaseat will become famous soon enough vegaseat will become famous soon enough 
Rep Power: 9
Solved Threads: 172
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
Kickbutt Moderator

Re: Starting Python

  #136  
May 14th, 2008
The module pygame is an SDL based GUI toolkit written for game development. It handles sound, images, animation and drawing objects like lines, circles, polygons. Here is a playful example to give you a taste of pygame code ...
  1. # draw random circles with module pygame
  2. # pygame free from: http://www.pygame.org/
  3.  
  4. import pygame as pg
  5. import random as rn
  6.  
  7. # color rgb tuples
  8. black = 0, 0, 0
  9. blue = 0, 0, 255
  10. green = 0, 255, 0
  11. olive = 128, 128, 0
  12. orange = 255, 165, 0
  13. magenta = 255, 0, 255
  14. red = 255, 0, 0
  15. yellow = 255, 255, 0
  16. white = 255, 255, 255
  17. color_list = [red, blue, green, yellow, olive, orange, magenta]
  18.  
  19. # window/screen width and height
  20. w = 500
  21. h = 500
  22. screen = pg.display.set_mode((w, h))
  23. pg.display.set_caption('Draw a number of random circles')
  24. screen.fill(black)
  25.  
  26. # draw n circles
  27. n = 20
  28. for k in range(n):
  29. x = rn.randint(10, w)
  30. y = rn.randint(10, h)
  31. radius = rn.randint(2, h//3)
  32. color = rn.choice(color_list)
  33. position = x, y
  34. # circle border width = 2
  35. pg.draw.circle(screen, color, position, radius, 2)
  36.  
  37. # update display
  38. pg.display.flip()
  39.  
  40. # event loop ...
  41. running = True
  42. while running:
  43. for event in pg.event.get():
  44. # quit when window corner x is clicked
  45. if event.type == pg.QUIT:
  46. running = False
  47.  
May 'the Google' be with you!
Reply With Quote  
All times are GMT -4. The time now is 11:57 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC