Title: Sinkblur

Author: Brendan Becker
Submission date: January 05, 2002

Description: Renders the text with a static 'motion blur' effect, as if the text is receeding.

Download: sinkblur.py

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

Comments: Import this module as mentioned in the script comments, then create your own text surfaces with the sinkblur() function. The module has an example script - hit 's' to take a screenshot. A nice effect - a neat improvement would be to allow effect_amt to be assigned negative values, to create an 'approaching text' effect.

Messages: 0


# Sinkblur, by Brendan Becker  ( http://clickass.org/ )
# use this anywhere you want, just give me a little credit =]
#
# Implement with:
# import sinkblur
# [....]
#  asdf = sinkblur.sinkblur("text",size,effect_amt,(rectsizex,rectsizey),(r,g,b))
#  asdfpos = asdf.get_rect()
#  asdfpos.centerx = screen.get_rect().centerx
#  asdfpos.top = 16
#  screen.blit(asdf,asdfpos)

import pygame, pygame.font, os, sys, pygame.image
from pygame.locals import *

# SINKBLUR - sinking "motion blur" effect (middle is brightest)
def sinkblur(textstring, textsize, sinkamount, displaysize, trgb=(255,255,255)):
    displaysurface = pygame.Surface(displaysize)
    displayrect = displaysurface.get_rect()
    if sinkamount*2 > textsize:
        sinkamount = textsize / 2
    for it in range(sinkamount):
        font = pygame.font.Font(None, textsize-(it*2))
        camt = sinkamount-it
        text = font.render(textstring, 1, (trgb[0]/camt,trgb[1]/camt,trgb[2]/camt) )
        textrect = text.get_rect()
        dx = displayrect.centerx - textrect.centerx
        dy = displayrect.centery - textrect.centery
        displaysurface.blit(text, (dx,dy) )
    return displaysurface

entry_info = 'Sinkblur, by Brendan Becker'

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

    #create our fancy text
    text = sinkblur(entry_info, 55, 8, (460,70), (200, 200, 255))

    #create a window the correct size
    win = pygame.display.set_mode(text.get_size())
    winrect = win.get_rect()
    win.blit(text, (0, 0))
    pygame.display.flip()
    
    #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):
            break

Main - Repository - Submit - News

Feedback