Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Putzlocher <mputzi@gmx.de>2013-08-10 09:42:42 (GMT)
committer Martin Putzlocher <mputzi@gmx.de>2013-08-10 09:42:42 (GMT)
commita349f0611b61149c6945d68772f8ec116740de2b (patch)
tree3382b11d5730ed57c6268856631dc2e59c227a78
parent5c4bae44f2c350a89787741afa8eb799a180e53c (diff)
first testHEADmaster
Signed-off-by: Martin Putzlocher <mputzi@gmx.de>
-rw-r--r--pygameHelloWorld.py63
1 files changed, 63 insertions, 0 deletions
diff --git a/pygameHelloWorld.py b/pygameHelloWorld.py
new file mode 100644
index 0000000..da82a8f
--- /dev/null
+++ b/pygameHelloWorld.py
@@ -0,0 +1,63 @@
+import pygame, sys
+from pygame.locals import *
+
+# set up pygame
+pygame.init()
+
+# set up the window
+windowSurface = pygame.display.set_mode((500, 400), 0, 32)
+pygame.display.set_caption('Hello world!')
+
+# set up the colors
+BLACK = (0, 0, 0)
+WHITE = (255, 255, 255)
+RED = (255, 0, 0)
+GREEN = (0, 255, 0)
+BLUE = (0, 0, 255)
+
+# set up fonts
+basicFont = pygame.font.SysFont(None, 48)
+
+# set up the text
+text = basicFont.render('Hello world!', True, WHITE, BLUE)
+textRect = text.get_rect()
+textRect.centerx = windowSurface.get_rect().centerx
+textRect.centery = windowSurface.get_rect().centery
+
+# draw the white background onto the surface
+windowSurface.fill(WHITE)
+
+# draw a green polygon onto the surface
+pygame.draw.polygon(windowSurface, GREEN, ((146, 0), (291, 106), (236, 277), (56, 277), (0, 106)))
+
+# draw some blue lines onto the surface
+pygame.draw.line(windowSurface, BLUE, (60, 60), (120, 60), 4)
+pygame.draw.line(windowSurface, BLUE, (120, 60), (60, 120))
+pygame.draw.line(windowSurface, BLUE, (60, 120), (120, 120), 4)
+
+# draw a blue circle onto the surface
+pygame.draw.circle(windowSurface, BLUE, (300, 50), 20, 0)
+
+# draw a red ellipse onto the surface
+pygame.draw.ellipse(windowSurface, RED, (300, 250, 40, 80), 1)
+
+# draw the text's background rectangle onto the surface
+pygame.draw.rect(windowSurface, RED, (textRect.left - 20, textRect.top - 20, textRect.width + 40, textRect.height + 40))
+
+# get a pixel array of the surface
+pixArray = pygame.PixelArray(windowSurface)
+pixArray[480][380] = BLACK
+del pixArray
+
+# draw the text onto the surface
+windowSurface.blit(text, textRect)
+
+# draw the window onto the screen
+pygame.display.update()
+
+# run the game loop
+while True:
+ for event in pygame.event.get():
+ if event.type == QUIT:
+ pygame.quit()
+ sys.exit()