示例#1
0
 def copy(cls, obj, grid=None, background=None, particles=None,
          rez=None, _threshfcn = None):
     """ Returns a copied canvas object.  __init__ params are taken from
     object unless explicitly passed.  
     
     Notes
     -----
     copy grid, bg and particles separately as they are 
     deep objects.  Particles is especially finiky so just
     create a completely new instance of it.
     
     Explicit passing is useful, for insance, if one wants to copy a
     canvas with new particles.  This makes the operation quicker than
     copying the old particles and then overwriting.
     """
 
     if not grid:
         grid = copy.copy(obj.grid)
     if not background:        
         background = copy.copy(obj.background)
     if not particles:
         particles = ParticleManager(plist=obj.plist, copy=True)
         
     if not rez:
         rez = obj.rez
         
     if not _threshfcn:
         _threshfcn = obj.threshfcn
     
     return cls(background=background, 
                particles=particles, 
                rez=rez, 
                grid=grid, 
                _threshfcn=_threshfcn)        
示例#2
0
 def __init__(self, particles=None, background=None, rez=None, grid=None, 
              _threshfcn=None): #No other traits
     """ Load with optionally a background image and instance of Particle
         Manager"""
     
     if not particles:
         particles = ParticleManager()
     self._particles = particles
         
     if background is None and rez is None:
         self.reset_background() #sets default color/resolution    
     elif background is not None and rez is None:
         self._resolution = BGRES
         self.set_bg(background, keepres=False, inplace=True)
     else:
         self._resolution = rez
         self.set_bg(background, keepres=rez, inplace=True) 
         
     if not grid:
         self.reset_grid()
     else:
         self.grid = grid
         
     # _threshfcn through __init__ only really for Cavnas.copy(); not users
     if _threshfcn is None:
         self.set_threshfcn(THRESHDEF)
     else:
         self._threshfcn = _threshfcn
示例#3
0
 def random_circles(cls, n=50, rmin=5, rmax=50, background=BGCOLOR, pcolor=None):
     """ Return a canvas populated with n randomly positioned circles.  
     Radius ranges vary randomly between 5 and 50."""
     from random import randint as RIT
                    
     particles = ParticleManager()            
     # Randomize particle centers within the image default dimensions
     for i in range(n):
         cx, cy = RIT(0, BGRES[0]), RIT(0, BGRES[1])
         radius = RIT(rmin,rmax)
         particles.add('circle', center=(cx,cy), radius=radius, 
                       color=to_normrgb(pcolor))
     
     # Use default resolution and grid
     return cls(background=background, particles=particles)
示例#4
0
 def random_triangles(cls, n=50, lmin=5, lmax=50, background=BGCOLOR, pcolor=None):
     """ Return a canvas populated with n randomly positioned circles.  
     Radius ranges vary randomly between 5 and 50."""
     from random import randint as RIT
                    
     particles = ParticleManager()            
     # Randomize particle centers within the image default dimensions
     for i in range(n):
         # ADD PADDING ADHOC AT THE MOMENT!!
         PAD = 2*lmax
         cx, cy = RIT(0+PAD, BGRES[0]-PAD), RIT(0+PAD, BGRES[1]-PAD)
         length = RIT(lmin,lmax)
         particles.add('triangle', center=(cx,cy), length=length, 
                       color=to_normrgb(pcolor))
     
     # Use default resolution and grid
     return cls(background=background, particles=particles)
示例#5
0
 def _set_particles(self, particles):
     """ Make a copy of the particles to avoid passing by reference. 
     Note this is implictly controlled by _COPYPARTICLES in config.
     """
     self._particles = ParticleManager(particles.plist, particles.fastnames)    
示例#6
0
 def _get_particles(self):
     """ Return a NEW INSTANCE of particles manager (ie new particles instead
     of in-memory references)"""
     return ParticleManager(plist=self._particles.plist, 
                            fastnames=self._particles.fastnames)