Mercurial > pygame
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 |
| rev | line source |
|---|---|
| 498 | 1 #!/usr/bin/env python |
| 29 | 2 |
| 3 """This examples demonstrates a simplish water effect of an | |
| 4 image. It attempts to create a hardware display surface that | |
| 5 can use pageflipping for faster updates. Note that the colormap | |
| 6 from the loaded GIF image is copied to the colormap for the | |
| 7 display surface. | |
| 8 | |
| 9 This is based on the demo named F2KWarp by Brad Graham of Freedom2000 | |
| 10 done in BlitzBasic. I was just translating the BlitzBasic code to | |
| 11 pygame to compare the results. I didn't bother porting the text and | |
| 12 sound stuff, that's an easy enough challenge for the reader :]""" | |
| 13 | |
| 300 | 14 import pygame, os |
| 29 | 15 from pygame.locals import * |
| 217 | 16 from math import sin |
| 29 | 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 | 20 def main(): |
| 21 #initialize and setup screen | |
| 22 pygame.init() | |
| 23 screen = pygame.display.set_mode((640, 480), HWSURFACE|DOUBLEBUF) | |
| 29 | 24 |
| 507 | 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 | 27 bitmap = pygame.image.load(imagename) |
| 28 bitmap = pygame.transform.scale2x(bitmap) | |
| 29 bitmap = pygame.transform.scale2x(bitmap) | |
| 29 | 30 |
| 507 | 31 #get the image and screen in the same format |
| 32 if screen.get_bitsize() == 8: | |
| 33 screen.set_palette(bitmap.get_palette()) | |
| 34 else: | |
| 35 bitmap = bitmap.convert() | |
| 36 | |
| 37 #prep some variables | |
| 38 anim = 0.0 | |
| 29 | 39 |
| 507 | 40 #mainloop |
| 41 xblocks = range(0, 640, 20) | |
| 42 yblocks = range(0, 480, 20) | |
| 43 stopevents = QUIT, KEYDOWN, MOUSEBUTTONDOWN | |
| 44 while 1: | |
| 45 for e in pygame.event.get(): | |
| 46 if e.type in stopevents: | |
| 47 return | |
| 29 | 48 |
| 507 | 49 anim = anim + 0.2 |
| 50 for x in xblocks: | |
| 217 | 51 xpos = (x + (sin(anim + x * .01) * 15)) + 20 |
| 507 | 52 for y in yblocks: |
| 53 ypos = (y + (sin(anim + y * .01) * 15)) + 20 | |
| 54 screen.blit(bitmap, (x, y), (xpos, ypos, 20, 20)) | |
| 55 | |
| 56 pygame.display.flip() | |
| 57 | |
| 58 | |
| 59 if __name__ == '__main__': main() | |
| 29 | 60 |
| 61 | |
| 62 | |
| 63 """BTW, here is the code from the BlitzBasic example this was derived | |
| 507 | 64 from. i've snipped the sound and text stuff out. |
| 29 | 65 ----------------------------------------------------------------- |
| 66 ; Brad@freedom2000.com | |
| 67 | |
| 68 ; Load a bmp pic (800x600) and slice it into 1600 squares | |
| 507 | 69 Graphics 640,480 |
| 70 SetBuffer BackBuffer() | |
| 71 bitmap$="f2kwarp.bmp" | |
| 29 | 72 pic=LoadAnimImage(bitmap$,20,15,0,1600) |
| 73 | |
| 74 ; use SIN to move all 1600 squares around to give liquid effect | |
| 75 Repeat | |
| 76 f=0:w=w+10:If w=360 Then w=0 | |
| 77 For y=0 To 599 Step 15 | |
| 78 For x = 0 To 799 Step 20 | |
| 79 f=f+1:If f=1600 Then f=0 | |
| 507 | 80 DrawBlock pic,(x+(Sin(w+x)*40))/1.7+80,(y+(Sin(w+y)*40))/1.7+60,f |
| 29 | 81 Next:Next:Flip:Cls |
| 82 Until KeyDown(1) | |
| 83 """ |
