/[gzz]/gzz/gfx/libutil/effects.py
ViewVC logotype

Diff of /gzz/gfx/libutil/effects.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.16 by tjl, Tue Oct 8 18:23:43 2002 UTC revision 1.17 by tjl, Fri Oct 18 14:02:14 2002 UTC
# Line 3  from gzz.vob.buoy import NadirAngler Line 3  from gzz.vob.buoy import NadirAngler
3  from gzz.vob.buoy import Buoy3Floater, Buoy4Floater  from gzz.vob.buoy import Buoy3Floater, Buoy4Floater
4  import math  import math
5    
 class CircleFloater4(Buoy4Floater):  
     def __init__(self, vs, parent, center, radius, p):  
         self.__dict__.update(locals())  
     def buoyCoordsys(self, anchorCS, key):  
         cs = self.vs.coords.buoyOnCircle(  
             self.parent, anchorCS,  
             self.center[0], self.center[1],  
             self.radius,  
             self.p[0], self.p[1],  
             1)  
         self.vs.matcher.add(cs, key)  
         return cs  
     def finishFloating(self):  
         pass  
   
 # Prototype: project to a semicircle  
 # from a point.  
 class NadirCircleFloater(Buoy3Floater):  
     def __init__(self, vs, center, radius, p, nadir):  
         self.vs, self.c, self.r, self.p, self.nadir = vs, center, radius, p, nadir  
         self.linecon = GLRen.createLineConnector(0, 0)  
     def addBuoy(self, anchorX, anchorY, importance, key, w, h):  
         size = importance  
   
         # 1. find the projected buoy point  
   
         # Vector from center to projection point  
         AmC = (self.p[0] - self.c[0], self.p[1] - self.c[1])  
   
         # Vector from anchor to projection point  
         v = (anchorX - self.p[0], anchorY - self.p[1])  
   
         # Coefficients of the 2nd degree eq  
         a = v[0]*v[0] + v[1]*v[1]  
         b = 2*(v[0]*AmC[0] + v[1]*AmC[1])  
         c = AmC[0]*AmC[0] + AmC[1]*AmC[1] - self.r**2  
   
         print "S: ",v,AmC,self.r, a,b,c  
   
         # Determinant  
         det = b**2 - 4*a*c  
         if det <= 0:  
             # For now, ignore  
             print "Ignoring ",key  
             b = (0,0)  
   
         else:  
   
             ans = (-b + math.sqrt(det)) / (2*a)  
             print "DA: ",det,ans  
   
             b = (self.p[0] + ans * v[0], self.p[1] + ans * v[1])  
             print "Buoy: (%s,%s): (%s,%s)\n"%(  
                 anchorX, anchorY, b[0], b[1])  
   
         # Create the coordinate system  
   
         vs = self.vs  
         cs1 = vs.coords.affineCoordsys(0, 50, b[0], b[1], size, 0, 0, size)  
         vs.matcher.add(cs1, str(key)+"_buo_1")  
         cs2 = vs.coords.rotateXY(cs1, -360 * self.nadir.getAngleRad(b[0], b[1]) / (2 * math.pi))  
         vs.matcher.add(cs2,str(key)+"_buo_2")  
         return cs2  
   
         # ac = vs.coords.coordsys(0, str(key)+"_5", 10, anchorX, anchorY, 0, 0)  
         # bc = vs.coords.coordsys(0, str(key)+"_6", 10, b[0], b[1], 0, 0)  
         # vs.map.put(self.linecon, ac, bc)  
     def addCentralBuoy(self, key):  
         b = self.c  
         size = 1  
         vs = self.vs  
         cs = vs.coords.affineCoordsys(0, 100, b[0], b[1], size, 0, 0, size)  
         vs.matcher.add(cs, str(key)+"_buo_1")  
   
         cs2 = vs.coords.rotateXY(cs, 0)  
         vs.matcher.add(cs2, str(key)+"_buo_2")  
         return cs2  
   
   
   
 # Prototype: just start from the middle, then up & down  
 class NadirCircleFloater_NoAnchor(Buoy3Floater):  
     def __init__(self, vs, center, radius, nadir, dir):  
         self.vs, self.c, self.r, self.nadir = vs, center, radius, nadir  
         self.dir = dir  
         self.ind = 0  
         self.angles = [0.2 * 2*math.pi, 0.4 * 2*math.pi]  
     def addBuoy(self, anchorX, anchorY, importance, key, w, h):  
         size = importance  
   
         # 1. find the buoy point  
   
         angle = self.angles[self.ind]  
         angle *= self.dir  
         self.ind += 1  
   
         b = (self.c[0] + self.r * math.sin(angle),  
              self.c[1] + self.r * math.cos(angle))  
   
         print "Buoy: (%s,%s): (%s,%s)\n"%(  
             anchorX, anchorY, b[0], b[1])  
   
         # Create the coordinate system  
   
         vs = self.vs  
         cs1 = vs.coords.affineCoordsys(0, 50, b[0], b[1], size, 0, 0, size)  
         vs.matcher.add(cs1, str(key)+"_buo_1")  
         cs2 = vs.coords.rotateXY(cs1, 360 * self.nadir.getAngleRad(b[0], b[1]) / (2 * math.pi))  
         vs.matcher.add(cs2,str(key)+"_buo_2")  
         return cs2  
   
         # ac = vs.coords.coordsys(0, str(key)+"_5", 10, anchorX, anchorY, 0, 0)  
         # bc = vs.coords.coordsys(0, str(key)+"_6", 10, b[0], b[1], 0, 0)  
         # vs.map.put(self.linecon, ac, bc)  
     def addCentralBuoy(self, key):  
         b = self.c  
         size = 1  
         vs = self.vs  
         cs = vs.coords.affineCoordsys(0, 100, b[0], b[1], size, 0, 0, size)  
         vs.matcher.add(cs, str(key)+"_buo_1")  
   
         cs2 = vs.coords.rotateXY(cs, 0)  
         vs.matcher.add(cs2, str(key)+"_buo_2")  
         return cs2  
   
           
6    
7  class IrreguFrame:  class IrreguFrame:
8      dicefactor = 0.8      dicefactor = 0.8

Legend:
Removed from v.1.16  
changed lines
  Added in v.1.17

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26