annotate examples/liquid.py @ 3172:d1b367fc08bc tests-returncode

Use a return code of 1 when the tests fail.
author Thomas Kluyver <takowl@gmail.com>
date Wed, 09 Jan 2013 10:13:57 +0000
parents a6e94e964a69
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
498
dc24519e33d1 incorporate openbsd patches
pygame
parents: 300
diff changeset
1 #!/usr/bin/env python
29
ae12316035a9 default font added, all color args changed to RGBA
pygame
parents:
diff changeset
2
ae12316035a9 default font added, all color args changed to RGBA
pygame
parents:
diff changeset
3 """This examples demonstrates a simplish water effect of an
ae12316035a9 default font added, all color args changed to RGBA
pygame
parents:
diff changeset
4 image. It attempts to create a hardware display surface that
ae12316035a9 default font added, all color args changed to RGBA
pygame
parents:
diff changeset
5 can use pageflipping for faster updates. Note that the colormap
ae12316035a9 default font added, all color args changed to RGBA
pygame
parents:
diff changeset
6 from the loaded GIF image is copied to the colormap for the
ae12316035a9 default font added, all color args changed to RGBA
pygame
parents:
diff changeset
7 display surface.
ae12316035a9 default font added, all color args changed to RGBA
pygame
parents:
diff changeset
8
ae12316035a9 default font added, all color args changed to RGBA
pygame
parents:
diff changeset
9 This is based on the demo named F2KWarp by Brad Graham of Freedom2000
ae12316035a9 default font added, all color args changed to RGBA
pygame
parents:
diff changeset
10 done in BlitzBasic. I was just translating the BlitzBasic code to
ae12316035a9 default font added, all color args changed to RGBA
pygame
parents:
diff changeset
11 pygame to compare the results. I didn't bother porting the text and
ae12316035a9 default font added, all color args changed to RGBA
pygame
parents:
diff changeset
12 sound stuff, that's an easy enough challenge for the reader :]"""
ae12316035a9 default font added, all color args changed to RGBA
pygame
parents:
diff changeset
13
300
5696b91aabed new importing
pygame
parents: 217
diff changeset
14 import pygame, os
29
ae12316035a9 default font added, all color args changed to RGBA
pygame
parents:
diff changeset
15 from pygame.locals import *
217
ecea3acad11d python 1.5.2 compatability
pygame
parents: 175
diff changeset
16 from math import sin
29
ae12316035a9 default font added, all color args changed to RGBA
pygame
parents:
diff changeset
17
1427
a6e94e964a69 examples can be run from outside the examples directory
Lenard Lindstrom <len-l@telus.net>
parents: 507
diff changeset
18 main_dir = os.path.split(os.path.abspath(__file__))[0]
a6e94e964a69 examples can be run from outside the examples directory
Lenard Lindstrom <len-l@telus.net>
parents: 507
diff changeset
19
507
31390eaafd87 clean liquid example, remove uberball example
pygame
parents: 498
diff changeset
20 def main():
31390eaafd87 clean liquid example, remove uberball example
pygame
parents: 498
diff changeset
21 #initialize and setup screen
31390eaafd87 clean liquid example, remove uberball example
pygame
parents: 498
diff changeset
22 pygame.init()
31390eaafd87 clean liquid example, remove uberball example
pygame
parents: 498
diff changeset
23 screen = pygame.display.set_mode((640, 480), HWSURFACE|DOUBLEBUF)
29
ae12316035a9 default font added, all color args changed to RGBA
pygame
parents:
diff changeset
24
507
31390eaafd87 clean liquid example, remove uberball example
pygame
parents: 498
diff changeset
25 #load image and quadruple
1427
a6e94e964a69 examples can be run from outside the examples directory
Lenard Lindstrom <len-l@telus.net>
parents: 507
diff changeset
26 imagename = os.path.join(main_dir, 'data', 'liquid.bmp')
507
31390eaafd87 clean liquid example, remove uberball example
pygame
parents: 498
diff changeset
27 bitmap = pygame.image.load(imagename)
31390eaafd87 clean liquid example, remove uberball example
pygame
parents: 498
diff changeset
28 bitmap = pygame.transform.scale2x(bitmap)
31390eaafd87 clean liquid example, remove uberball example
pygame
parents: 498
diff changeset
29 bitmap = pygame.transform.scale2x(bitmap)
29
ae12316035a9 default font added, all color args changed to RGBA
pygame
parents:
diff changeset
30
507
31390eaafd87 clean liquid example, remove uberball example
pygame
parents: 498
diff changeset
31 #get the image and screen in the same format
31390eaafd87 clean liquid example, remove uberball example
pygame
parents: 498
diff changeset
32 if screen.get_bitsize() == 8:
31390eaafd87 clean liquid example, remove uberball example
pygame
parents: 498
diff changeset
33 screen.set_palette(bitmap.get_palette())
31390eaafd87 clean liquid example, remove uberball example
pygame
parents: 498
diff changeset
34 else:
31390eaafd87 clean liquid example, remove uberball example
pygame
parents: 498
diff changeset
35 bitmap = bitmap.convert()
31390eaafd87 clean liquid example, remove uberball example
pygame
parents: 498
diff changeset
36
31390eaafd87 clean liquid example, remove uberball example
pygame
parents: 498
diff changeset
37 #prep some variables
31390eaafd87 clean liquid example, remove uberball example
pygame
parents: 498
diff changeset
38 anim = 0.0
29
ae12316035a9 default font added, all color args changed to RGBA
pygame
parents:
diff changeset
39
507
31390eaafd87 clean liquid example, remove uberball example
pygame
parents: 498
diff changeset
40 #mainloop
31390eaafd87 clean liquid example, remove uberball example
pygame
parents: 498
diff changeset
41 xblocks = range(0, 640, 20)
31390eaafd87 clean liquid example, remove uberball example
pygame
parents: 498
diff changeset
42 yblocks = range(0, 480, 20)
31390eaafd87 clean liquid example, remove uberball example
pygame
parents: 498
diff changeset
43 stopevents = QUIT, KEYDOWN, MOUSEBUTTONDOWN
31390eaafd87 clean liquid example, remove uberball example
pygame
parents: 498
diff changeset
44 while 1:
31390eaafd87 clean liquid example, remove uberball example
pygame
parents: 498
diff changeset
45 for e in pygame.event.get():
31390eaafd87 clean liquid example, remove uberball example
pygame
parents: 498
diff changeset
46 if e.type in stopevents:
31390eaafd87 clean liquid example, remove uberball example
pygame
parents: 498
diff changeset
47 return
29
ae12316035a9 default font added, all color args changed to RGBA
pygame
parents:
diff changeset
48
507
31390eaafd87 clean liquid example, remove uberball example
pygame
parents: 498
diff changeset
49 anim = anim + 0.2
31390eaafd87 clean liquid example, remove uberball example
pygame
parents: 498
diff changeset
50 for x in xblocks:
217
ecea3acad11d python 1.5.2 compatability
pygame
parents: 175
diff changeset
51 xpos = (x + (sin(anim + x * .01) * 15)) + 20
507
31390eaafd87 clean liquid example, remove uberball example
pygame
parents: 498
diff changeset
52 for y in yblocks:
31390eaafd87 clean liquid example, remove uberball example
pygame
parents: 498
diff changeset
53 ypos = (y + (sin(anim + y * .01) * 15)) + 20
31390eaafd87 clean liquid example, remove uberball example
pygame
parents: 498
diff changeset
54 screen.blit(bitmap, (x, y), (xpos, ypos, 20, 20))
31390eaafd87 clean liquid example, remove uberball example
pygame
parents: 498
diff changeset
55
31390eaafd87 clean liquid example, remove uberball example
pygame
parents: 498
diff changeset
56 pygame.display.flip()
31390eaafd87 clean liquid example, remove uberball example
pygame
parents: 498
diff changeset
57
31390eaafd87 clean liquid example, remove uberball example
pygame
parents: 498
diff changeset
58
31390eaafd87 clean liquid example, remove uberball example
pygame
parents: 498
diff changeset
59 if __name__ == '__main__': main()
29
ae12316035a9 default font added, all color args changed to RGBA
pygame
parents:
diff changeset
60
ae12316035a9 default font added, all color args changed to RGBA
pygame
parents:
diff changeset
61
ae12316035a9 default font added, all color args changed to RGBA
pygame
parents:
diff changeset
62
ae12316035a9 default font added, all color args changed to RGBA
pygame
parents:
diff changeset
63 """BTW, here is the code from the BlitzBasic example this was derived
507
31390eaafd87 clean liquid example, remove uberball example
pygame
parents: 498
diff changeset
64 from. i've snipped the sound and text stuff out.
29
ae12316035a9 default font added, all color args changed to RGBA
pygame
parents:
diff changeset
65 -----------------------------------------------------------------
ae12316035a9 default font added, all color args changed to RGBA
pygame
parents:
diff changeset
66 ; Brad@freedom2000.com
ae12316035a9 default font added, all color args changed to RGBA
pygame
parents:
diff changeset
67
ae12316035a9 default font added, all color args changed to RGBA
pygame
parents:
diff changeset
68 ; Load a bmp pic (800x600) and slice it into 1600 squares
507
31390eaafd87 clean liquid example, remove uberball example
pygame
parents: 498
diff changeset
69 Graphics 640,480
31390eaafd87 clean liquid example, remove uberball example
pygame
parents: 498
diff changeset
70 SetBuffer BackBuffer()
31390eaafd87 clean liquid example, remove uberball example
pygame
parents: 498
diff changeset
71 bitmap$="f2kwarp.bmp"
29
ae12316035a9 default font added, all color args changed to RGBA
pygame
parents:
diff changeset
72 pic=LoadAnimImage(bitmap$,20,15,0,1600)
ae12316035a9 default font added, all color args changed to RGBA
pygame
parents:
diff changeset
73
ae12316035a9 default font added, all color args changed to RGBA
pygame
parents:
diff changeset
74 ; use SIN to move all 1600 squares around to give liquid effect
ae12316035a9 default font added, all color args changed to RGBA
pygame
parents:
diff changeset
75 Repeat
ae12316035a9 default font added, all color args changed to RGBA
pygame
parents:
diff changeset
76 f=0:w=w+10:If w=360 Then w=0
ae12316035a9 default font added, all color args changed to RGBA
pygame
parents:
diff changeset
77 For y=0 To 599 Step 15
ae12316035a9 default font added, all color args changed to RGBA
pygame
parents:
diff changeset
78 For x = 0 To 799 Step 20
ae12316035a9 default font added, all color args changed to RGBA
pygame
parents:
diff changeset
79 f=f+1:If f=1600 Then f=0
507
31390eaafd87 clean liquid example, remove uberball example
pygame
parents: 498
diff changeset
80 DrawBlock pic,(x+(Sin(w+x)*40))/1.7+80,(y+(Sin(w+y)*40))/1.7+60,f
29
ae12316035a9 default font added, all color args changed to RGBA
pygame
parents:
diff changeset
81 Next:Next:Flip:Cls
ae12316035a9 default font added, all color args changed to RGBA
pygame
parents:
diff changeset
82 Until KeyDown(1)
ae12316035a9 default font added, all color args changed to RGBA
pygame
parents:
diff changeset
83 """