Changeset 47
- Timestamp:
- 04/05/08 01:15:24 (8 months ago)
- Location:
- muckaround/cython-getting-started-tutorial
- Files:
-
- 2 modified
-
fast_circles.pyx (modified) (6 diffs)
-
main.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
muckaround/cython-getting-started-tutorial/fast_circles.pyx
r46 r47 18 18 import random 19 19 20 c lass Circle(object):20 cdef class Circle: 21 21 22 def __init__(self, x, y, dx, dy, radius): 22 cdef public float x 23 cdef public float y 24 cdef public float dx 25 cdef public float dy 26 cdef public float radius 27 28 def __init__(self, float x, float y, float dx, float dy, float radius): 23 29 self.x = x 24 30 self.y = y … … 27 33 self.radius = radius 28 34 29 def think(self, dt, max_x,max_y):35 def think(self, float dt, float max_x, float max_y): 30 36 """Moves the circle and bounces it off walls""" 31 37 self.x += self.dx * dt … … 39 45 40 46 def render(self): 47 cdef int sections 48 cdef float a 49 cdef float x 50 cdef float y 41 51 sections = 10 42 52 glPushMatrix() … … 44 54 glScalef(self.radius, self.radius, 1) 45 55 glBegin(GL_LINE_LOOP) 46 for a in xrange(sections): 47 a = float(a) 56 for a from 0 <= a < sections: 48 57 x = cos(a / sections * pi * 2) 49 58 y = sin(a / sections * pi * 2) … … 53 62 54 63 55 class Circles(object): 64 cdef class Circles: 65 66 cdef int max_x 67 cdef int max_y 68 cdef object circles 56 69 57 70 def __init__(self, max_x, max_y): … … 70 83 self.circles.append(Circle(x, y, dx, dy, rad)) 71 84 72 def think(self, dt): 85 def think(self, float dt): 86 87 cdef float rel_pos_x 88 cdef float rel_pos_y 89 cdef float pos_angle 90 cdef float mag 73 91 74 92 # Make all the circles move -
muckaround/cython-getting-started-tutorial/main.py
r46 r47 5 5 from pyglet.gl import * 6 6 7 from fast_circles import Circle, Circles7 from slow_circles import Circle, Circles 8 8 9 9 WIDTH = 800