Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/data
diff options
context:
space:
mode:
authorC. Scott Ananian <cscott@laptop.org>2008-11-04 01:17:56 (GMT)
committer C. Scott Ananian <cscott@laptop.org>2008-11-04 01:17:56 (GMT)
commitec7d4f57742f6138002ed5f66ba735cea984f1fd (patch)
treea026cb6b94dfe6130673ba8ac43e58cf1ff2bd9a /data
parent80e16706827a64f8da25ddb0a697a6dafa8760a3 (diff)
Move physics/shapes example to graphics/physics, at least until there are more.
Also fix some minor issues: we don't need to create a Clock; pippy.pygame.next_frame() does that for us; and the nested while loop is not quite right.
Diffstat (limited to 'data')
-rw-r--r--data/graphics/physics47
-rw-r--r--data/physics/shapes53
2 files changed, 47 insertions, 53 deletions
diff --git a/data/graphics/physics b/data/graphics/physics
new file mode 100644
index 0000000..88138fd
--- /dev/null
+++ b/data/graphics/physics
@@ -0,0 +1,47 @@
+# physics
+
+import pippy, pygame, sys, math
+from pygame.locals import *
+from pippy import physics
+
+# initialize pygame first thing
+pygame.init()
+screen = pygame.display.set_mode((1200,900))
+
+# set up the physics world (instance of Elements)
+world = physics.Elements(screen.get_size())
+world.renderer.set_surface(screen)
+
+# set up initial physics objects
+world.add.ground()
+world.add.ball((600,0), 50)
+world.add.rect((500,0), 25, 300, dynamic=True, density=1.0, restitution=0.16, friction=0.5)
+
+# add 20 more balls
+balls = 0
+while(balls<20):
+ world.add.ball((balls*5+200,balls*5), 50)
+ balls+=1
+
+# begin physics simulation
+world.run_physics = True
+
+while pippy.pygame.next_frame() and world.run_physics:
+ for event in pygame.event.get():
+ if event.type == QUIT:
+ sys.exit()
+
+ elif event.type == KEYDOWN:
+ sys.exit()
+
+ # clear display with a color
+ # (r,g,b), where 0<=value<256
+ screen.fill((80,160,240))
+
+ # update & draw physics world
+ world.update()
+ world.draw()
+
+ # update the display
+ pygame.display.flip()
+
diff --git a/data/physics/shapes b/data/physics/shapes
deleted file mode 100644
index 111b22a..0000000
--- a/data/physics/shapes
+++ /dev/null
@@ -1,53 +0,0 @@
-# physics
-
-import pippy, pygame, sys, math
-from pygame.locals import *
-from pippy import physics
-
-# initialize pygame first thing
-pygame.init()
-screen = pygame.display.set_mode((1200,900))
-clock = pygame.time.Clock()
-
-# set up the physics world (instance of Elements)
-world = physics.Elements(screen.get_size())
-world.renderer.set_surface(screen)
-
-# set up initial physics objects
-world.add.ground()
-world.add.ball((600,0), 50)
-world.add.rect((500,0), 25, 300, dynamic=True, density=1.0, restitution=0.16, friction=0.5)
-
-# add 20 more balls
-balls = 0
-while(balls<20):
- world.add.ball((balls*5+200,balls*5), 50)
- balls+=1
-
-# begin physics simulation
-world.run_physics = True
-
-while pippy.pygame.next_frame():
- while world.run_physics:
-
- for event in pygame.event.get():
- if event.type == QUIT:
- sys.exit()
-
- elif event.type == KEYDOWN:
- sys.exit()
-
- # clear display with a color
- # (r,g,b), where 0<=value<256
- screen.fill((80,160,240))
-
- # update & draw physics world
- world.update()
- world.draw()
-
- # update the display
- pygame.display.flip()
-
- # try to stay at 30 frames per second
- clock.tick(30)
-