Example #1
0
 def remove(self, particle):
     # Speed is set to Attractor.radius * Attractor.gravity to shoot away.
     particle.v.angle = angle(self.x, self.y, particle.x, particle.y)
     particle.v.length = self.radius * self.gravity * 1.0
     particle.parent = None
     particle.frames = -10 # Take some time to escape attraction radius.
     self.particles.remove(particle)
Example #2
0
 def remove(self, particle):
     # Speed is set to Attractor.radius * Attractor.gravity to shoot away.
     particle.v.angle = angle(self.x, self.y, particle.x, particle.y)
     particle.v.length = self.radius * self.gravity * 1.0
     particle.parent = None
     particle.frames = -10  # Take some time to escape attraction radius.
     self.particles.remove(particle)
Example #3
0
 def draw(self, m=1.2, blur=False, color=[1, 1, 1, 1], alpha=1.0):
     """ Draw the particle with the given image, or as an ellipse (default).
     """
     r = self.radius * m  # Increase m to let attracted particles overlap.
     a = self.v.angle
     if self.parent is not None:
         # Particles attached to the attractor always point to the attractor.
         a = angle(self.x, self.y, self.parent.x, self.parent.y)
     push()
     translate(self.x, self.y)
     if self.image is None:
         ellipse(0, 0, r * 2, r * 2)
     else:
         scale(r * 2 / max(self.image.width, self.image.height))
         rotate(a - 90)
         img = self.image
         if blur is not False:
             # Blurring assumes that a global "images" cache is available.
             # Blur is assumed to be a value between 0.0 and 1.0.
             img = images.blurred(img.id, max(0.1, float(blur)))
         image(img,
               x=-self.image.width / 2,
               y=-self.image.height / 2,
               color=color,
               alpha=self.alpha * alpha)
     pop()
Example #4
0
File: 06-pack.py Project: msarch/py
 def draw(self):
     a = angle(self.x, self.y, self.goal.x, self.goal.y)
     r = self.radius * 1.25 # Let the cells overlap a little bit.
     push()
     translate(self.x, self.y)
     scale(r*2 / min(self.image.width, self.image.height))
     rotate(a)
     image(self.image, x=-r, y=-r) # Rotate from image center.
     pop()
Example #5
0
 def mesh(self, f=0.008):
     # Returns a list of (particle, dx, dy, angle)-tuples, 
     # where (dx, dy) is the tip of the particle's feeler.
     points = []
     for i,p in enumerate(self.particles):
         dx = (p.x - self.x) * p.radius * f 
         dy = (p.y - self.y) * p.radius * f
         points.append((p, dx, dy, angle(p.x, p.y, self.x, self.y)))
     return points
 def draw(self):
     a = angle(self.x, self.y, self.goal.x, self.goal.y)
     r = self.radius * 1.25  # Let the cells overlap a little bit.
     push()
     translate(self.x, self.y)
     scale(r * 2 / min(self.image.width, self.image.height))
     rotate(a)
     image(self.image, x=-r, y=-r)  # Rotate from image center.
     pop()
Example #7
0
 def mesh(self, f=0.008):
     # Returns a list of (particle, dx, dy, angle)-tuples,
     # where (dx, dy) is the tip of the particle's feeler.
     points = []
     for i, p in enumerate(self.particles):
         dx = (p.x - self.x) * p.radius * f
         dy = (p.y - self.y) * p.radius * f
         points.append((p, dx, dy, angle(p.x, p.y, self.x, self.y)))
     return points
 def draw(self):
     # fill(self.color)
     # circle(self.x, self.y, self.size)
     text(self.text, x=self.x, y=self.y, width=self.width,
            font = "Droid Serif", 
            fontsize = 12, 
            fontweight = BOLD,
            lineheight = 1.9,
            fill = self.color)
     a = angle(self.x, self.y, self.goal.x, self.goal.y)
     r = self.radius * 1.25 # Let the cells overlap a little bit.
     push()
     translate(self.x, self.y)
     scale(r*2 / min(5, 5))
     rotate(a)
     # image(self.image, x=-r, y=-r) # Rotate from image center.
     pop()
Example #9
0
 def draw(self, m=1.2, blur=False, color=[1,1,1,1], alpha=1.0):
     """ Draw the particle with the given image, or as an ellipse (default).
     """
     r = self.radius * m # Increase m to let attracted particles overlap.
     a = self.v.angle
     if self.parent is not None:
         # Particles attached to the attractor always point to the attractor.
         a = angle(self.x, self.y, self.parent.x, self.parent.y)
     push()
     translate(self.x, self.y)
     if self.image is None:
         ellipse(0, 0, r*2, r*2)
     else:
         scale(r*2 / max(self.image.width, self.image.height))
         rotate(a-90)
         img = self.image
         if blur is not False:
             # Blurring assumes that a global "images" cache is available.
             # Blur is assumed to be a value between 0.0 and 1.0.
             img = images.blurred(img.id, max(0.1, float(blur)))
         image(img, x=-self.image.width/2, y=-self.image.height/2, color=color, alpha=self.alpha*alpha)
     pop()