示例#1
0
 def scatter(self,amount):
     """
     Scatters the ball by up to amount in a random direction.
     """
     self.x += np.random.random()*amount-amount/2.
     self.y += np.random.random()*amount-amount/2.
     self.x = utils.bracket(0,self.x,self.layout.xsize)
     self.y = utils.bracket(0,self.y,self.layout.ysize)
示例#2
0
 def scatter(self, amount):
     """
     Scatters the ball by up to amount in a random direction.
     """
     self.x += np.random.random() * amount - amount / 2.
     self.y += np.random.random() * amount - amount / 2.
     self.x = utils.bracket(0, self.x, self.layout.xsize)
     self.y = utils.bracket(0, self.y, self.layout.ysize)
示例#3
0
 def __init__(self, **kwargs):
     """
     :param hex: 'RRGGBB'
     :param r: 0 - 255
     :param g: 0 - 255
     :param b: 0 - 255
     :param h: 0 - 360
     :param s: 0 - 100
     :param v: 0 - 100
     """
     if 'hex' in kwargs:
         hex_code = kwargs.get('hex')
         self._color = hex_to_rgb(hex_code)
     elif 'r' in kwargs and 'g' in kwargs and 'b' in kwargs:
         r = bracket(kwargs.get('r'))
         g = bracket(kwargs.get('g'))
         b = bracket(kwargs.get('b'))
         self._color = r, g, b
     elif 'h' in kwargs and 's' in kwargs and 'v' in kwargs:
         h = bracket(kwargs.get('h'), 0, 360)
         s = bracket(kwargs.get('s'), 0, 100)
         v = bracket(kwargs.get('v'), 0, 100)
         r, g, b = hsv_to_rgb(h / 360.0, s / 100.0, v / 100.0)
         self._color = (int(r * 255.0 + 0.5), int(g * 255.0 + 0.5),
                        int(b * 255.0 + 0.5))
     else:
         self._color = 0, 0, 0
示例#4
0
 def distAlongAngle(ang, obj, full_return=False):
     " Finds shortest dist along this angle"
     # find eq of line from me at angle
     m = math.tan(ang * deg2rad)
     b = obj.y - m * obj.x
     # Find shortest intersection distance
     shortest_dist = -1
     for eq in pb_eqs:
         if eq[2] == -1:
             # Case where y co-ords are equal.
             dist = abs(obj.x - eq[1])
             yi = obj.y
             xi = eq[1]
         else:
             # Find co-ords of intersection point
             xi = (b - eq[2]) / (eq[1] - m)
             yi = m * xi + b
             # Checks for intersection being out of bounds
             if yi > obj.layout.ysize:
                 # Pull back intersection point to OOB position
                 yi = obj.layout.ysize
                 xi = (yi - b) / m
             elif yi < 0:
                 yi = 0
                 xi = (yi - b) / m
             # Ensure intersection points are in the field
             xi = utils.bracket(0, xi, obj.layout.xsize)
             # dist=np.sqrt( (x-xi)**2 + (y-yi)**2)
             dist = xi - obj.x
         if dist < shortest_dist or shortest_dist < 0.0:
             shortest_dist = dist
             xs = xi
             ys = yi
     if full_return:
         return (shortest_dist, xs, ys)
     return -shortest_dist
示例#5
0
 def distAlongAngle(ang,obj,full_return=False):
     " Finds shortest dist along this angle"
     # find eq of line from me at angle
     m=math.tan(ang*deg2rad)
     b=obj.y - m*obj.x
     # Find shortest intersection distance
     shortest_dist=-1
     for eq in pb_eqs:
         if eq[2] == -1:
             # Case where y co-ords are equal.
             dist=abs(obj.x-eq[1])
             yi=obj.y
             xi=eq[1]
         else:
             # Find co-ords of intersection point
             xi=(b-eq[2])/(eq[1]-m)
             yi=m*xi+b
             # Checks for intersection being out of bounds
             if (yi > obj.layout.ysize):
                 # Pull back intersection point to OOB position
                 yi = obj.layout.ysize
                 xi = (yi-b)/m
             elif (yi < 0):
                 yi = 0
                 xi = (yi-b)/m
             # Ensure intersection points are in the field
             xi = utils.bracket(0,xi,obj.layout.xsize)
             #dist=np.sqrt( (x-xi)**2 + (y-yi)**2)
             dist=xi-obj.x
         if dist < shortest_dist or shortest_dist < 0.:
             shortest_dist=dist
             xs=xi
             ys=yi
     if full_return:
         return (shortest_dist,xs,ys)
     return -shortest_dist
示例#6
0
def get_macro(name, form, product):
    return utils.bracket(PAREN, [name,
                                 form,
                                 product])