Update of /cvsroot/freevo/freevo/WIP/Barbieri
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5613
Modified Files:
anim-test.py
Log Message:
Better effects, big fade-in/out.
PyGame isn't that slow...
Index: anim-test.py
===================================================================
RCS file: /cvsroot/freevo/freevo/WIP/Barbieri/anim-test.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** anim-test.py 3 Aug 2004 09:18:23 -0000 1.2
--- anim-test.py 5 Aug 2004 22:34:30 -0000 1.3
***************
*** 2,5 ****
--- 2,6 ----
import pygame
+ import Numeric
from pygame.locals import *
import sys, math, time
***************
*** 8,18 ****
# Parameters -----------------------------------------------------------------
SIZE = ( 800, 600 )
! FLAGS = DOUBLEBUF
OBJFLAGS = SRCALPHA
! DT = 16
timings = { "create-bg": 0,
"create-obj": 0,
"blit-bg": [],
"blit-j" : [],
--- 9,21 ----
# Parameters -----------------------------------------------------------------
SIZE = ( 800, 600 )
! FLAGS = DOUBLEBUF | SRCALPHA
OBJFLAGS = SRCALPHA
! DT = 20
+ DEBUG=0
timings = { "create-bg": 0,
"create-obj": 0,
+ "blit-obj2": [],
"blit-bg": [],
"blit-j" : [],
***************
*** 23,27 ****
! def jump( ( x, y, w, h ), obj ):
if t > 0:
y = h - h * abs( math.sin( t ) / t )
--- 26,30 ----
! def jump( ( x, y, w, h ), t, obj ):
if t > 0:
y = h - h * abs( math.sin( t ) / t )
***************
*** 29,48 ****
# jump()
! def slidein_left( ( x, y, w, h ), obj ):
! A = 7
! T1 = ( A * t ** 2 ) / 2
! if x + T1 + obj.get_size()[ 0 ] < w:
! x += T1
return ( x, y )
# slidein_left()
! def slidein_right( ( x, y, w, h ), obj ):
! A = -7
! T1 = ( A * t ** 2 ) / 2
! if x + T1 > 0:
! x += T1
return ( x, y )
! # slidein_left()
def create_bg():
--- 32,91 ----
# jump()
! def slidein_left( ( x, y, w, h ), t, obj ):
! """Slide object from the left side to the right side.
!
! The movement starts at ( x, y ) and go to ( x+w, y )
!
! The animation has an exponential decrease of the velocity using the
! expression:
!
! e = 1 - 0.5 ^ t
!
! Which starts on t=0, e=0 down to t=Infinity, e=1.
!
! This makes the movement smooth, quick at the begining, slower at the end.
! """
! w -= obj.get_size()[ 0 ]
! x += w * ( 1 - 0.5 ** t )
return ( x, y )
# slidein_left()
! def slidein_right( ( x, y, w, h ), t, obj ):
! """Slide object from the right side to the left side.
!
! The movement starts at ( x+w, y ) and go to ( x, y ).
!
! The animation has an exponential decrease of the velocity using the
! expression:
!
! e = 0.5 ^ t
!
! Which starts on t=0, e=1 down to t=Infinity, e=0.
!
! This makes the movement smooth, quick at the begining, slower at the end.
! """
! w -= obj.get_size()[ 0 ]
! x += w * ( 0.5 ** t )
return ( x, y )
! # slidein_right()
+ def fadeout( delay, t, obj ):
+ """Fade out object.
+
+ This function use set_alpha(), so it's only applicable to per-surface
+ alpha. Objects with per-pixel alpha will now work (remains, unchanged)
+ """
+ obj.set_alpha( int( 255.0 * ( 1 - float( t ) / delay ) ) )
+ # fadeout()
+
+ def fadein( delay, t, obj ):
+ """Fade in object.
+
+ This function use set_alpha(), so it's only applicable to per-surface
+ alpha. Objects with per-pixel alpha will now work (remains, unchanged)
+ """
+ obj.set_alpha( int( 255.0 * ( 1 - float( t ) / delay ) ) )
+ # fadein()
+
def create_bg():
***************
*** 52,71 ****
if 1:
surface = pygame.image.load('../../share/images/aubin_bg2.jpg')
else:
! surface = pygame.Surface( SIZE, OBJFLAGS ).convert()
timings[ "create-bg" ] = time.clock() - c
surface.fill( 0xffffff )
! while i < SIZE[ 0 ]:
! pygame.draw.line( surface, 0x000000, ( 0, 0 ), ( SIZE[ 0 ], i ), 1 )
! i += stepx
return surface
# create_bg()
def create_obj():
c = time.clock()
obj = pygame.Surface( ( 200, 100 ), OBJFLAGS )
! obj = obj.convert_alpha()
timings[ "create-obj" ] = time.clock() - c
--- 95,116 ----
if 1:
surface = pygame.image.load('../../share/images/aubin_bg2.jpg')
+ surface = surface.convert()
else:
! surface = pygame.Surface( SIZE, OBJFLAGS ).convert()
timings[ "create-bg" ] = time.clock() - c
surface.fill( 0xffffff )
! while i < SIZE[ 0 ]:
! pygame.draw.line( surface, 0x000000, ( 0, 0 ), ( SIZE[ 0 ], i ), 1 )
! i += stepx
return surface
# create_bg()
+
def create_obj():
c = time.clock()
obj = pygame.Surface( ( 200, 100 ), OBJFLAGS )
! obj = obj.convert_alpha( obj )
timings[ "create-obj" ] = time.clock() - c
***************
*** 74,86 ****
obj.fill( 0x00000000, r )
! pygame.draw.ellipse( obj, 0x33ffffff, r, 0 )
r = ( 3, 3, r[ 2 ] - 6, r[ 3 ] - 6 )
! pygame.draw.ellipse( obj, 0x66ffff00, r, 0 )
r = ( 6, 6, r[ 2 ] - 6, r[ 3 ] - 6 )
! pygame.draw.ellipse( obj, 0x66ff00ff, r, 0 )
return obj
# create_obj()
def event_handler():
for event in pygame.event.get():
--- 119,141 ----
obj.fill( 0x00000000, r )
! pygame.draw.ellipse( obj, 0x22ffffff, r, 0 )
r = ( 3, 3, r[ 2 ] - 6, r[ 3 ] - 6 )
! pygame.draw.ellipse( obj, 0x44ffff00, r, 0 )
r = ( 6, 6, r[ 2 ] - 6, r[ 3 ] - 6 )
! pygame.draw.ellipse( obj, 0x88ff00ff, r, 0 )
return obj
# create_obj()
+ def create_obj2():
+ stepx = 10
+ i = 0
+ c = time.clock()
+ surface = pygame.image.load( '../../share/images/barbieri/bg.jpg' )
+ surface = surface.convert()
+ return surface
+ # create_obj2()
+
+
def event_handler():
for event in pygame.event.get():
***************
*** 99,102 ****
--- 154,158 ----
obj = create_obj()
+ obj2 = create_obj2()
clock = pygame.time.Clock()
***************
*** 104,111 ****
s = obj.get_size()
p1 = ( 0, 0 )
! p2 = ( S[ 0 ] + obj.get_size()[ 0 ], 200 )
! p3 = ( - obj.get_size()[ 0 ], 400 )
!
! d = ( S[ 0 ] - s[ 0 ], S[ 1 ] - s[ 1 ] )
t = 0
while True:
--- 160,167 ----
s = obj.get_size()
p1 = ( 0, 0 )
! p2 = ( 0, 100 )
! p3 = ( 0, 300 )
!
! d = ( S[ 0 ], 200 )
t = 0
while True:
***************
*** 116,141 ****
c1 = time.clock() - c0
timings[ "blit-bg" ] += [ c1 ]
! print "blit-bg: %s" % c1
c0 = time.clock()
! p1 = jump( p1 + d, obj )
! screen.blit( obj, p1 )
c1 = time.clock() - c0
timings[ "blit-j" ] += [ c1 ]
! print "blit-jump: %s" % c1
c0 = time.clock()
! p2 = slidein_right( p2 + d, obj )
! screen.blit( obj, p2 )
c1 = time.clock() - c0
timings[ "blit-sr" ] += [ c1 ]
! print "blit-slidein_right: %s" % c1
c0 = time.clock()
! p3 = slidein_left( p3 + d, obj )
! screen.blit( obj, p3 )
c1 = time.clock() - c0
timings[ "blit-sl" ] += [ c1 ]
! print "blit-slidein_left: %s" % c1
t += 0.1
--- 172,204 ----
c1 = time.clock() - c0
timings[ "blit-bg" ] += [ c1 ]
! if DEBUG: print "blit-bg: %s" % c1
c0 = time.clock()
! fadeout( 10, t, obj2 )
! screen.blit( obj2, ( 0, 0 ) )
! c1 = time.clock() - c0
! timings[ "blit-obj2" ] += [ c1 ]
! if DEBUG: print "blit-obj2: %s" % c1
!
! c0 = time.clock()
! p1 = jump( p1 + d, t, obj )
! #screen.blit( obj, p1 )
c1 = time.clock() - c0
timings[ "blit-j" ] += [ c1 ]
! if DEBUG: print "blit-jump: %s" % c1
c0 = time.clock()
! p = slidein_right( p2 + d, t, obj )
! screen.blit( obj, p )
c1 = time.clock() - c0
timings[ "blit-sr" ] += [ c1 ]
! if DEBUG: print "blit-slidein_right: %s" % c1
c0 = time.clock()
! p = slidein_left( p3 + d, t, obj )
! screen.blit( obj, p )
c1 = time.clock() - c0
timings[ "blit-sl" ] += [ c1 ]
! if DEBUG: print "blit-slidein_left: %s" % c1
t += 0.1
***************
*** 144,156 ****
c1 = time.clock() - c0
timings[ "flip" ] += [ c1 ]
! print "flip-screen: %s" % c1
!
r = event_handler()
if r == 1:
! break
# while
for k in timings:
! print "%s: " % k,
v = timings[ k ]
if isinstance( v, list ):
--- 207,223 ----
c1 = time.clock() - c0
timings[ "flip" ] += [ c1 ]
! if DEBUG: print "flip-screen: %s" % c1
!
! #print "FPS: %0.2f" % clock.get_fps()
! if t > 10:
! t = 0
!
r = event_handler()
if r == 1:
! break
# while
for k in timings:
! print "%15s: " % k,
v = timings[ k ]
if isinstance( v, list ):
***************
*** 159,163 ****
r += i
r /= len( v )
! print "%s ::: %s" % ( r, v )
else:
print v
--- 226,231 ----
r += i
r /= len( v )
! #print "%0.3f ms (average) #### list: %s" % ( r * 1000, v )
! print "%0.3f ms (average)" % ( r * 1000 )
else:
print v
-------------------------------------------------------
This SF.Net email is sponsored by OSTG. Have you noticed the changes on
Linux.com, ITManagersJournal and NewsForge in the past few weeks? Now,
one more big change to announce. We are now OSTG- Open Source Technology
Group. Come see the changes on the new OSTG site. www.ostg.com
_______________________________________________
Freevo-cvslog mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog