예제 #1
0
 def damageBlockEnemy(arbiter, space, data):
     impulse = functions.magnitude(arbiter.total_impulse)
     damage = impulse / 10000
     for shape in arbiter.shapes:
         if shape.collision_type in (3, 4):
             if damage >= 15:
                 shape.body.entity_ref.takeDamage(damage)
예제 #2
0
 def __init__(self,
              start_junction,
              end_junction,
              width=None,
              road_id=None,
              *args,
              **kwargs):
     if not road_id:
         self.road_id = Road.auto_id
         Road.auto_id += 1
     else:
         self.road_id = road_id
     self.start_junction, self.end_junction = start_junction, end_junction
     self.width = width if width else Road.default_width
     (startx,
      starty), (endx, endy) = start_junction.location, end_junction.location
     self.vector = (endx - startx, endy - starty)
     self.length = functions.magnitude(self.vector)
     #self.slope = functions.slope(start_junction.location, end_junction.location)
     lx, ly = functions.weight_add((start_junction.x, start_junction.y),
                                   (end_junction.x, end_junction.y), 0.5,
                                   0.5)
     self.label = pyglet.text.Label(text=str(self.road_id),
                                    x=lx,
                                    y=ly,
                                    batch=kwargs['batch'],
                                    anchor_x='center',
                                    anchor_y='center',
                                    font_name='Times New Roman',
                                    font_size=12,
                                    color=(255, 0, 0, 255))
예제 #3
0
 def floorDamageBlock(arbiter, space, data):
     for shape in arbiter.shapes:
         if shape.collision_type == 2:
             impulse = functions.magnitude(
                 shape.body.velocity) * shape.body.mass
     damage = impulse / 10000
     for shape in arbiter.shapes:
         if shape.collision_type == 3:
             if damage >= 5:
                 shape.body.entity_ref.takeDamage(damage)
def find_eigenvector(A, tolerance=0.00001):
    guess = [random.random() for __ in A]

    while True:
        result = matrix_operate(A, guess)
        length = magnitude(result)
        next_guess = scalar_multiply(1 / length, result)

        if distance(guess, next_guess) < tolerance:
            return next_guess, length  #eigenvector, eigenvalue
        guess = next_guess
예제 #5
0
 def enemyProjectileDamageCharacter(arbiter, space, data):
     for shape in arbiter.shapes:
         if shape.collision_type == 2:
             impulse = functions.magnitude(
                 shape.body.velocity) * shape.body.mass
     damage = impulse / 10000
     for shape in arbiter.shapes:
         if shape.collision_type == 5:
             shape.body.entity_ref.takeDamage(damage)
         elif shape.collision_type == 2:
             try:
                 self.entities.remove(shape.body.entity_ref)
             except ValueError:
                 print(
                     "Exception Handled. list.remove(x): x not in list")
                 pass
             self.space.remove(shape.body, shape)
     return False
예제 #6
0
fn = '5x5filter_1d.jpg'
img = cv2.imread(fn, 0)

height, width = img.shape

#use sobel operator to get x and y derivatives
sobelox = np.array([[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]])
sobeloy = np.array([[1, 2, 1], [0, 0, 0], [-1, -2, -1]])

imgdx = ed.derivative(img, sobelox, height, width, 3, 3)
imgdy = ed.derivative(img, sobeloy, height, width, 3, 3)
#cv2.imwrite('dx.jpg', imgdx)
#cv2.imwrite('dy.jpg', imgdy)

#get image gradient magnitude
imgmagnitude = ed.magnitude(imgdx, imgdy, height, width)
imgmagnitudedisplay = ed.adjust(imgmagnitude, height, width)
cv2.imwrite('magnitudemap.jpg', imgmagnitudedisplay)

#get image gradient orientation
imgorientation, imgedgethin = ed.orientation(imgdx, imgdy, height, width,
                                             imgmagnitude)
cv2.imwrite('orientation_map.jpg', imgorientation)
cv2.imwrite('edge_map_thin.jpg', imgedgethin)

#apply threshold and edgelink
threshold_low = 25
threshold_high = 50
imgedge = ed.doublethreshold(imgedgethin, height, width, threshold_low,
                             threshold_high)
cv2.imwrite('edge_map.jpg', imgedge)