Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/data/graphics/bounce
diff options
context:
space:
mode:
Diffstat (limited to 'data/graphics/bounce')
-rw-r--r--data/graphics/bounce89
1 files changed, 89 insertions, 0 deletions
diff --git a/data/graphics/bounce b/data/graphics/bounce
new file mode 100644
index 0000000..94e5c8b
--- /dev/null
+++ b/data/graphics/bounce
@@ -0,0 +1,89 @@
+# bounce: move some text around the screen
+# use the escape key to exit
+#
+# on the XO, the escape key is the top lefthand key,
+# circle with an x in it.
+
+import sys,pygame
+from pygame.locals import *
+from random import *
+
+# always need to init first thing
+pygame.init()
+
+# turn off cursor
+pygame.mouse.set_visible(False)
+
+# XO screen is 1200x900
+size = width, height = 1200, 900
+
+# we'll use 36 pixel high text
+fsize = 36
+
+# vector for motion, will control speed and angle
+mvect = [3,2]
+
+# create the window and keep track of the surface
+# for drawing into
+screen = pygame.display.set_mode(size)
+
+msg = "Hello!"
+
+# create a Font object from a file, or use the default
+# font if the file name is None. size param is height
+# in pixels
+
+# usage: pygame.font.Font(filename|object, size)
+font = pygame.font.Font(None, fsize)
+
+# Font.render draws text onto a new surface.
+#
+# usage: Font.render(text, antialias, color, bg=None)
+text = font.render(msg, True, (10,10,10))
+
+# the Rect object is used for positioning
+textRect = text.get_rect()
+
+# start at the top left
+textRect.left = 0;
+textRect.top = 0;
+
+while 1:
+
+ for event in pygame.event.get():
+ if event.type == QUIT:
+ sys.exit()
+
+ elif event.type == KEYDOWN:
+ if event.key == K_ESCAPE:
+ sys.exit()
+
+ screen.fill((250,250,250))
+
+ # draw the text
+ screen.blit(text, textRect)
+
+ # update the display
+ pygame.display.flip()
+
+ # move the text
+ #
+ # Rect.move returns a new Rect while
+ # Rect.move_ip moves in place, so we'll use
+ # the latter
+ textRect.move_ip(mvect)
+
+ # bounce off edges
+ if textRect.left < 0 :
+ textRect.left = 0
+ mvect[0] = -1 * mvect[0]
+ elif textRect.right >= size[0] :
+ textRect.right = size[0] - 1
+ mvect[0] = -1 * mvect[0]
+
+ if textRect.top < 0 :
+ textRect.top = 0
+ mvect[1] = -1 * mvect[1]
+ elif textRect.bottom >= size[1] :
+ textRect.bottom = size[1] - 1
+ mvect[1] = -1 * mvect[1]