Title: Dropshadow module

Author: Pete Shinners
Submission date: December 03, 2001

Description: A function to render text with a user-defined drop shadow.

Download: dropshadow.py

pygame version required: Any
SDL version required: Any
Python version required: Any

Comments: The "offset" argument that the function takes is the number of pixels the shadow will appear, below and to the right of the original text.

Messages: 0

#!/usr/bin/env python

example non-animated entry for the pygame text contest

if you would like to change this for your own entry, modify
the first function that renders the text. you'll also probably
want to change the arguments that your function used. simply
running the script should show some sort of example for your
text rendering
import os, sys, pygame, pygame.font, pygame.image
from pygame.locals import *

def textDropShadow(font, message, offset, fontcolor, shadowcolor):
    base = font.render(message, 0, fontcolor)
    size = base.get_width() + offset, base.get_height() + offset
    img = pygame.Surface(size, 16)
    base.set_palette_at(1, shadowcolor)
    img.blit(base, (offset, offset))
    base.set_palette_at(1, fontcolor)
    img.blit(base, (0, 0))
    return img

entry_info = 'Drop Shadow, by Pete Shinners'

#this code will display our work, if the script is run...
if __name__ == '__main__':

    #create our fancy text
    white = 255, 255, 255
    grey = 100, 100, 100
    bigfont = pygame.font.Font(None, 60)
    text = textDropShadow(bigfont, entry_info, 3, white, grey)

    #create a window the correct size
    win = pygame.display.set_mode(text.get_size())
    winrect = win.get_rect()
    win.blit(text, (0, 0))
    #wait for the finish
    while 1:
        event = pygame.event.wait()
        if event.type is KEYDOWN and event.key == K_s: #save it
            name = os.path.splitext(sys.argv[0])[0] + '.bmp'
            print 'Saving image to:', name
            pygame.image.save(win, name)
        elif event.type in (QUIT,KEYDOWN,MOUSEBUTTONDOWN):

Main - Repository - Submit - News