pygame / examples / liquid.py

Diff from to

examples/liquid.py

 from pygame.locals import *
 from math import sin
 
+def main():
+    #initialize and setup screen
+    pygame.init()
+    screen = pygame.display.set_mode((640, 480), HWSURFACE|DOUBLEBUF)
 
-#initialize and setup screen
-pygame.init()
-screen = pygame.display.set_mode((640, 480), HWSURFACE|DOUBLEBUF, 8)
+    #load image and quadruple
+    imagename = os.path.join('data', 'liquid.bmp')
+    bitmap = pygame.image.load(imagename)
+    bitmap = pygame.transform.scale2x(bitmap)
+    bitmap = pygame.transform.scale2x(bitmap)
 
-#load image
-imagename = os.path.join('data', 'liquid.bmp')
-bitmap = pygame.image.load(imagename)
+    #get the image and screen in the same format
+    if screen.get_bitsize() == 8:
+        screen.set_palette(bitmap.get_palette())
+    else:
+        bitmap = bitmap.convert()
 
-#get the image and screen in the same format
-if screen.get_bitsize() == 8:
-    screen.set_palette(bitmap.get_palette())
-else:
-    bitmap = bitmap.convert()
+    #prep some variables
+    anim = 0.0
 
-#prep some variables
-anim = 0.0
+    #mainloop
+    xblocks = range(0, 640, 20)
+    yblocks = range(0, 480, 20)
+    stopevents = QUIT, KEYDOWN, MOUSEBUTTONDOWN
+    while 1:
+        for e in pygame.event.get():
+            if e.type in stopevents:
+                return
 
-#mainloop
-while not pygame.event.peek([QUIT, KEYDOWN, MOUSEBUTTONDOWN]):
-    anim = anim + 0.4
-    for x in range(0, 640, 20):
-        for y in range(0, 480, 20):
+        anim = anim + 0.2
+        for x in xblocks:
             xpos = (x + (sin(anim + x * .01) * 15)) + 20
-            ypos = (y + (sin(anim + y * .01) * 15)) + 20
-            screen.blit(bitmap, (x, y), (xpos, ypos, 20, 20))
-    pygame.display.flip()
+            for y in yblocks:
+                ypos = (y + (sin(anim + y * .01) * 15)) + 20
+                screen.blit(bitmap, (x, y), (xpos, ypos, 20, 20))
+
+        pygame.display.flip()
+
+
+if __name__ == '__main__': main()
 
 
 
 """BTW, here is the code from the BlitzBasic example this was derived
-from. This code runs a little faster, yet reads a lot slower. again
-i've snipped the sound and text stuff out.
+from. i've snipped the sound and text stuff out.
 -----------------------------------------------------------------
 ; Brad@freedom2000.com
 
 ; Load a bmp pic (800x600) and slice it into 1600 squares
-Graphics 640,480					
-SetBuffer BackBuffer()				
-bitmap$="f2kwarp.bmp"					
+Graphics 640,480
+SetBuffer BackBuffer()
+bitmap$="f2kwarp.bmp"
 pic=LoadAnimImage(bitmap$,20,15,0,1600)
 
 ; use SIN to move all 1600 squares around to give liquid effect
 For y=0 To 599 Step 15
 For x = 0 To 799 Step 20
 f=f+1:If f=1600 Then f=0
-DrawBlock pic,(x+(Sin(w+x)*40))/1.7+80,(y+(Sin(w+y)*40))/1.7+60,f 
+DrawBlock pic,(x+(Sin(w+x)*40))/1.7+80,(y+(Sin(w+y)*40))/1.7+60,f
 Next:Next:Flip:Cls
 Until KeyDown(1)
 """
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.