Sections
Timeline
Sub-Sections
Download
Unified Diff
Zip Archive
Metanav
Preferences
About Trac
Links
Slowchop Studios
Gerald Kaszuba
Advertisement

Changeset 47

Show
Ignore:
Timestamp:
04/05/08 01:15:24 (8 months ago)
Author:
gak
Message:
 
Location:
muckaround/cython-getting-started-tutorial
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • muckaround/cython-getting-started-tutorial/fast_circles.pyx

    r46 r47  
    1818import random 
    1919 
    20 class Circle(object): 
     20cdef class Circle: 
    2121 
    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): 
    2329        self.x = x 
    2430        self.y = y 
     
    2733        self.radius = radius 
    2834 
    29     def think(self, dt, max_x, max_y): 
     35    def think(self, float dt, float max_x, float max_y): 
    3036        """Moves the circle and bounces it off walls""" 
    3137        self.x += self.dx * dt 
     
    3945 
    4046    def render(self): 
     47        cdef int sections 
     48        cdef float a 
     49        cdef float x 
     50        cdef float y 
    4151        sections = 10 
    4252        glPushMatrix() 
     
    4454        glScalef(self.radius, self.radius, 1) 
    4555        glBegin(GL_LINE_LOOP) 
    46         for a in xrange(sections): 
    47             a = float(a) 
     56        for a from 0 <= a < sections: 
    4857            x = cos(a / sections * pi * 2) 
    4958            y = sin(a / sections * pi * 2) 
     
    5362 
    5463 
    55 class Circles(object): 
     64cdef class Circles: 
     65 
     66    cdef int max_x 
     67    cdef int max_y 
     68    cdef object circles 
    5669 
    5770    def __init__(self, max_x, max_y): 
     
    7083        self.circles.append(Circle(x, y, dx, dy, rad)) 
    7184 
    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 
    7391 
    7492        # Make all the circles move 
  • muckaround/cython-getting-started-tutorial/main.py

    r46 r47  
    55from pyglet.gl import * 
    66 
    7 from fast_circles import Circle, Circles 
     7from slow_circles import Circle, Circles 
    88 
    99WIDTH = 800