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>2007-12-11 09:24:34 (GMT)
committer C. Scott Ananian <cscott@laptop.org>2007-12-11 09:24:34 (GMT)
commit9df72c5591aee015089a4e96f9403183262dcc01 (patch)
tree4a01e662068fe7977dbb4fd14e232fc7354863d4 /data
parent90c54afd7ea81be376b078eb08b87e4f20e71dcf (diff)
Factor out a pippy library, which programs can use with 'import pippy'.
The pygame portion of the library uses 'best practices' to avoid eating up CPU, and pauses & suspends after 20 seconds of inactivity.
Diffstat (limited to 'data')
-rw-r--r--data/graphics/bounce4
-rw-r--r--data/graphics/camera4
-rw-r--r--data/graphics/jump24
-rw-r--r--data/graphics/lines4
-rw-r--r--data/graphics/pong4
-rw-r--r--data/math/guess3
-rw-r--r--data/math/sierpinski6
-rw-r--r--data/sound/getSoundList7
-rw-r--r--data/sound/playSine9
-rw-r--r--data/sound/playWave9
-rw-r--r--data/sound/sequence10
-rw-r--r--data/sound/sndInfo8
12 files changed, 35 insertions, 57 deletions
diff --git a/data/graphics/bounce b/data/graphics/bounce
index 02bc34f..d0bcd3c 100644
--- a/data/graphics/bounce
+++ b/data/graphics/bounce
@@ -1,6 +1,6 @@
# bounce: move some text around the screen
-import sys,pygame
+import pippy, pygame, sys
from pygame.locals import *
from random import *
@@ -44,7 +44,7 @@ textRect = text.get_rect()
textRect.left = 0;
textRect.top = 0;
-while 1:
+while pippy.pygame.next_frame():
for event in pygame.event.get():
if event.type == QUIT:
diff --git a/data/graphics/camera b/data/graphics/camera
index 8a1bbb8..6eea88f 100644
--- a/data/graphics/camera
+++ b/data/graphics/camera
@@ -1,6 +1,6 @@
# image: take a picture
-import sys, pygame, gst, time
+import gst, pippy, pygame, sys, time
from random import *
# XO screen is 1200 by 900
@@ -32,7 +32,7 @@ image = pygame.image.load("/tmp/pippypic.jpg")
angle = 0.0
scale = 2.0
-while 1:
+while pippy.pygame.next_frame():
for event in pygame.event.get():
if event.type == pygame.QUIT: sys.exit()
elif event.type == pygame.KEYDOWN: sys.exit()
diff --git a/data/graphics/jump b/data/graphics/jump
index ed08950..be9b49e 100644
--- a/data/graphics/jump
+++ b/data/graphics/jump
@@ -1,31 +1,27 @@
-def clear_scr():
- print '\x1B[H\x1B[J' # clear screen
-
-def wait():
- import time
- time.sleep(0.1)
+import pippy
for i in xrange(0,50):
- clear_scr()
+ pippy.console.clear()
+ # Note that we have to escape backslashes
print "\\o/"
print "_|_"
print " "
- wait()
+ pippy.wait()
- clear_scr()
+ pippy.console.clear()
print "_o_"
print " | "
print "/ \\"
- wait()
+ pippy.wait()
- clear_scr()
+ pippy.console.clear()
print " o "
print "/|\\"
print "| |"
- wait()
+ pippy.wait()
- clear_scr()
+ pippy.console.clear()
print "_o_"
print " | "
print "/ \\"
- wait()
+ pippy.wait()
diff --git a/data/graphics/lines b/data/graphics/lines
index 682ab37..c0faf93 100644
--- a/data/graphics/lines
+++ b/data/graphics/lines
@@ -1,6 +1,6 @@
# lines: make lots of lines on the screen
-import sys,pygame
+import pippy, pygame, sys
from pygame.locals import *
from random import *
@@ -32,7 +32,7 @@ mvect_end = [choice((-1,1)) * randint(1,3), choice((-1,1)) * randint(1,3)]
color = [randint(0,255), randint(0,255), randint(0,255)]
direction = [choice((-1,1)), choice((-1,1)), choice((-1,1))]
-while 1:
+while pippy.pygame.next_frame():
for event in pygame.event.get():
if event.type == QUIT:
diff --git a/data/graphics/pong b/data/graphics/pong
index 351f7ce..0ce3a9e 100644
--- a/data/graphics/pong
+++ b/data/graphics/pong
@@ -5,7 +5,7 @@
# on the XO, the escape key is the top lefthand key,
# circle with an x in it.
-import sys,pygame
+import pippy, pygame, sys
from pygame.locals import *
from random import *
@@ -50,7 +50,7 @@ textRect = text.get_rect()
textRect.centerx = screen.get_rect().centerx
textRect.centery = screen.get_rect().centery
-while 1:
+while pippy.pygame.next_frame():
# display msg
screen.fill(bgcolor)
diff --git a/data/math/guess b/data/math/guess
index 97ee098..d80514c 100644
--- a/data/math/guess
+++ b/data/math/guess
@@ -1,6 +1,5 @@
import random
-from random import randrange
-R = randrange(1,100)
+R = random.randrange(1,100)
print "Guess a number between 1 and 100!"
N = input("Enter a number: ")
diff --git a/data/math/sierpinski b/data/math/sierpinski
index 133acc4..8b5f291 100644
--- a/data/math/sierpinski
+++ b/data/math/sierpinski
@@ -14,13 +14,13 @@ for i in range(0,lines):
newvector = vector[:]
for j in range(0,len(vector)-1):
if (newvector[j] == 0):
- sys.stdout.write(" ")
+ print " ",
else:
remainder = newvector[j] % modulus
if (remainder == 0):
- sys.stdout.write("O")
+ print "O",
else:
- sys.stdout.write(".")
+ print ".",
newvector[j] = vector[j-1] + vector[j+1]
print
vector = newvector[:]
diff --git a/data/sound/getSoundList b/data/sound/getSoundList
index 215e97a..8d722bb 100644
--- a/data/sound/getSoundList
+++ b/data/sound/getSoundList
@@ -1,7 +1,4 @@
-import sys
-from sugar.activity.activity import get_bundle_path
-sys.path.append(get_bundle_path() + '/sound')
-from sound import *
+import pippy
-for sound in getSoundList():
+for sound in pippy.sound.getSoundList():
print sound
diff --git a/data/sound/playSine b/data/sound/playSine
index cd97576..b68746c 100644
--- a/data/sound/playSine
+++ b/data/sound/playSine
@@ -1,8 +1,5 @@
-import sys
-from sugar.activity.activity import get_bundle_path
-sys.path.append(get_bundle_path() + '/sound')
-from sound import *
+import pippy
-playSine()
-audioOut()
+pippy.sound.playSine()
+pippy.sound.audioOut()
diff --git a/data/sound/playWave b/data/sound/playWave
index 27605bd..503b475 100644
--- a/data/sound/playWave
+++ b/data/sound/playWave
@@ -1,8 +1,5 @@
-import sys
-from sugar.activity.activity import get_bundle_path
-sys.path.append(get_bundle_path() + '/sound')
-from sound import *
+import pippy
-playWave(sound='didjeridu', loop=True, duration=5)
-audioOut()
+pippy.sound.playWave(sound='didjeridu', loop=True, duration=5)
+pippy.sound.audioOut()
diff --git a/data/sound/sequence b/data/sound/sequence
index 1577c9d..3922e7a 100644
--- a/data/sound/sequence
+++ b/data/sound/sequence
@@ -1,14 +1,10 @@
-import sys
-import random
-from sugar.activity.activity import get_bundle_path
-sys.path.append(get_bundle_path() + '/sound')
-from sound import *
+import pippy, random
for i in range(25):
pitch = random.randint(500,2000)
amplitude = 5000
duration = 0.1
starttime = i * 0.1
- playSine(pitch, amplitude, duration, starttime)
-audioOut()
+ pippy.sound.playSine(pitch, amplitude, duration, starttime)
+pippy.sound.audioOut()
diff --git a/data/sound/sndInfo b/data/sound/sndInfo
index 529995e..7767245 100644
--- a/data/sound/sndInfo
+++ b/data/sound/sndInfo
@@ -1,6 +1,2 @@
-import sys
-from sugar.activity.activity import get_bundle_path
-sys.path.append(get_bundle_path() + '/sound')
-from sound import *
-
-print playSine.__doc__
+import pippy
+help(pippy.sound.playSine)