~facundo/enjuewemela/trunk

« back to all changes in this revision

Viewing changes to cocos/path.py

  • Committer: facundo at com
  • Date: 2011-05-14 18:13:25 UTC
  • mfrom: (67.1.4 v3rel)
  • Revision ID: facundo@taniquetil.com.ar-20110514181325-614h8kjz32w5cmoy
Refactor back

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
class Path:
2
 
    def at(self, t):
3
 
        pass
4
 
        
5
 
class Bezier(Path):
6
 
    def __init__(self, a, b, ac, bc):
7
 
        self.a = a
8
 
        self.b = b
9
 
        self.ac = ac
10
 
        self.bc = bc
11
 
        
12
 
    def at(self, t):
13
 
        def calc(i):
14
 
            a = self.a[i]
15
 
            b = self.ac[i]
16
 
            c = self.bc[i]
17
 
            d = self.b[i]
18
 
            return ( 
19
 
                ((1-t)**3) * a + 
20
 
                3*t*((1-t)**2)*b + 
21
 
                3*(t**2)*(1-t)*c +
22
 
                (t**3)*d
23
 
                )
24
 
        return calc(0), calc(1)
25
 
        
26
 
    def __repr__(self):
27
 
        return "Bezier( (%i,%i), (%i,%i), (%i, %i), (%i,%i) )"%(
28
 
                self.a[0], self.a[0],
29
 
                self.b[0], self.b[1],
30
 
                self.ac[0], self.ac[1],
31
 
                self.bc[0], self.bc[1],
32
 
 
33
 
            )
34