Changeset 46
- Timestamp:
- 04/05/08 00:35:57 (8 months ago)
- Location:
- muckaround/cython-getting-started-tutorial
- Files:
-
- 2 added
- 1 modified
- 1 moved
-
fast_circles.pyx (added)
-
main.py (modified) (2 diffs)
-
setup.py (added)
-
slow_circles.py (moved) (moved from muckaround/cython-getting-started-tutorial/circles.py) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
muckaround/cython-getting-started-tutorial/main.py
r44 r46 5 5 from pyglet.gl import * 6 6 7 from circles import Circle, Circles7 from fast_circles import Circle, Circles 8 8 9 9 WIDTH = 800 … … 26 26 27 27 for a in xrange(100): 28 circles.add( Circle.new(WIDTH, HEIGHT))28 circles.add() 29 29 30 30 while not win.has_exit: -
muckaround/cython-getting-started-tutorial/slow_circles.py
r45 r46 13 13 self.dy = dy 14 14 self.radius = radius 15 16 @staticmethod17 def new(max_x, max_y):18 """Selects a position, movement and a radius and returns a new Circle19 object with these properties."""20 rad = random.uniform(5, 10)21 x = random.uniform(rad, max_x - rad)22 y = random.uniform(rad, max_y - rad)23 angle = random.uniform(0, math.pi * 2)24 speed = random.uniform(1, 50)25 dx = math.cos(angle) * speed26 dy = math.sin(angle) * speed27 return Circle(x, y, dx, dy, rad)28 15 29 16 def think(self, dt, max_x, max_y): … … 60 47 self.max_y = max_y 61 48 62 def add(self, c): 63 self.circles.append(c) 49 def add(self): 50 rad = random.uniform(5, 10) 51 x = random.uniform(rad, self.max_x - rad) 52 y = random.uniform(rad, self.max_y - rad) 53 angle = random.uniform(0, math.pi * 2) 54 speed = random.uniform(1, 50) 55 dx = math.cos(angle) * speed 56 dy = math.sin(angle) * speed 57 self.circles.append(Circle(x, y, dx, dy, rad)) 64 58 65 59 def think(self, dt):