pygame is
Python
Simple DirectMedia Layer
 
 
pygame.org is
Site Swing
Wiki

CookBook

      
Search:  
 
 

Posting A Recipe:

- Please start a new page for each recipe.

- Use the <pre><code>YOUR CODE</code></pre> tags to put in code.(View source of some other pages to see how it is done.)

- Except where otherwise noted, recipes posted in the pygame cookbook are in public domain.

- Tabs are lost when posting, so convert tabs to spaces first if you use them.

# Render Text Example: 'I love pygame!'
 
pygame.init()
 
screen = pygame.display.set_mode([300,100])
screen.fill([255,255,255])
 
mainloop, x, y, color, fontsize, delta, fps =  True, 25 , 0, (32,32,32), 35, 1, 30
 
Clock = pygame.time.Clock().
 
while mainloop:
    tickFPS = Clock.tick(fps)
    pygame.display.set_caption("Press Esc to quit. FPS: %.2f" % (Clock.get_fps()))
    fontsize = random.randint(35, 150)
    myFont = pygame.font.SysFont("None", fontsize)
    color = (random.randint(0,255), random.randint(0,255), random.randint(0,255))
    screen.fill((255,255,255))
    screen.blit(myFont.render("I love pygame!", 0, (color)), (x,y))
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            mainloop = False # Be IDLE friendly!
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ESCAPE:
                mainloop = False # Be IDLE friendly!
    pygame.display.update()
 
pygame.quit() # Be IDLE friendly! 
Generic recipes PyGame recipes PyOpenGL recipes
Profiling
RunningInCorrectDirectory
LinearInterpolator
SmoothInterpolator
BoundingBox
2DVectorClass
3DVectorClass
CommandDispatch (A pattern for building GUIs)
2DGeometryEngine
QuadTree
MemoizingDecorator (Another lazy resource loader)
SignalSlot (A signal/slot implementation)
Interpolator (An improved interpolator)
BezierCurve
RGBColorConversion
CalculateDist
SpatialHashMap
ConstantGameSpeed
LazyImageLoading
SimpleFontManager
TTFToBitmapConverter
toggle_fullscreen
Joystick_analyzer
ImagePacker
SmallerRectForSpriteCollision
GradientCode
ConchMusicSoundToolkit
FastPixelPerfect
SettingWindowPosition
DummyVideoDriver
WindowResizing
TextWrapping
CairoPygame
Load_32-bit_BMP_with_Alpha
HeadlessNoWindowsNeeded (Use pygame without using creating a window)
SubtractRects
ShadowEffects (Using arrays)
MatplotlibPygame
IntersectingLineDetection
MmapSurfaces
WxPython
Pygame2exe
InputWrapper
RotateCenter
MidiScheduler
SpatialHash_for_Pygame
Spritesheet
SimpleOpenGL2dClasses
OBJFileLoader
GLLight
GLSLExample
GLSL_ARB_Example
TextureCoordinateArithmetic
MakeOpenglDrawIn2D
CrossPlatformTextOpengl
ProgramArcadeGames.com has another list of cookbook code examples.
spotlight

 
our projects
pygame.org welcomes all python game, art, music, sound, video and multimedia projects. If they use pygame or not.
 
recent releases
Jun 11, 2013

Jun 9, 2013

Jun 7, 2013

Jun 4, 2013

Jun 1, 2013

May 30, 2013

May 26, 2013

May 24, 2013


May 23, 2013

May 22, 2013

May 21, 2013

... more!
 
for pygame related questions, comments, and suggestions, please see help (lists, irc)