当前位置: 首页>>代码示例>>Python>>正文


Python pymunk.moment_for_poly函数代码示例

本文整理汇总了Python中pymunk.moment_for_poly函数的典型用法代码示例。如果您正苦于以下问题:Python moment_for_poly函数的具体用法?Python moment_for_poly怎么用?Python moment_for_poly使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了moment_for_poly函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

	def __init__(self,cellspace,num,pos,angle,radius=5,length=None,vertices=6,mass=0.1,biochem=None,**kwargs):
		##{{{
		## Cell Attributes
		super(cellp, self).__init__(cellspace,num,pos,angle,biochem=biochem,**kwargs)
		self.radius=radius #Radius of hemisphere at cell end. Radius is in uM
		self.length=radius*2 if length is None else length #The length of the cell measured from the center of the two hemisphere
		self.height=self.radius*2
		self.vertices=vertices #Number of vertices in the hemisphere
		self.mass=mass #Self Explanatory
		self.color=pg.color.THECOLORS["red"]

		self.growthrate=0.05 #Growth rate can be a function of a state variable eventually. um/s growth in length
		self.divmean=4.*self.radius #Threshold for division
		self.divstd=0.1*self.divmean
		self.divthreshold=self.divmean+self.divstd*np.random.randn(1) #Threshold decided at the start to reduce computational cost

		self.cycle='grow'
		self.kwargs=kwargs	# This is done so that when the cell divides, any special attribute
							# will be transfered to the daughter cell.
		for i in kwargs.iterkeys(): 
			vars(self)[i]=kwargs[i]

		## Initializing cell in space
		self._genpoly()
		inertia=pm.moment_for_poly(self.mass,self.ver, (0,0))
		self.body=pm.Body(self.mass,inertia)
		self.body.position = pos
		self.body.angle = angle
		#-----------
		self.box = pm.Poly(self.body,self.ver,(-self.length/2.,-self.height/2.)) # Connecting box
		#-----------
		self.box.elasticity=0.5
		self.box.friction=0
		self.box.color = self.color
		self.space.add(self.body, self.box)
开发者ID:shockingpants,项目名称:GIT,代码行数:35,代码来源:celltype.py

示例2: __init__

    def __init__(self, position):
        super(Player, self).__init__()
        self.v1 = 50
        self.v2 = 15
        #Pymunk physics variables.
        self.verts = [(-self.v2, -self.v1), (-self.v2, self.v1), (self.v2, self.v1), (self.v2, -self.v1)]
        self.mass = 100
        self.friction = 9
        self.elasticity = 0
        self.moment = pymunk.moment_for_poly(self.mass, self.verts)
        self.body = pymunk.Body(self.mass, self.moment)
        self.body.position = position
        self.shape = pymunk.Poly(self.body, self.verts)
        #self.shape.group = 1
        #self.shape.layers = 1
        #self.shape.collision_type = 1
        self.shape.friction = 0.1
        self.shape.elasticity = 0.9
        self.shape.collision_type = 2
        self.pin_body = pymunk.Body()
        self.pin_body.position = self.body.position
        self.spring = pymunk.DampedRotarySpring(self.body, self.pin_body, 0, 20000000, 900000)

        self.groove_body = pymunk.Body()
        self.groove_body.position = (self.body.position.x, 0)
        self.groove = pymunk.GrooveJoint(self.groove_body, self.body, (0, 0), (0, 768), (0,0))
开发者ID:Art9681,项目名称:LocoPong,代码行数:26,代码来源:player.py

示例3: create_bananas

def create_bananas(space):
    mass = 10
    size = 50
    points = [(-size, -size), (-size, size), (size,size), (size, -size)]
    moment = pymunk.moment_for_poly(mass, points, (0,0))
    body = pymunk.Body(mass, moment)
    x = random.randint(0, 500)
    body.position = Vec2d(x,x)
    banana = pymunk.Poly(body, points, (0,0))
    #banana.friction = 2
    banana.elasticity = 0.95
    space.add(body, banana)

    """
    Circular Banana

    radius = 10
    inertia = pymunk.moment_for_circle(mass, 0, radius, (0, 0))
    body = pymunk.Body(mass, inertia)
    x = random.randint(0, 500)
    body.position = x, x
    banana = pymunk.Circle(body, radius, (0, 0))
    banana.elasticity = 0.95
    space.add(body, banana)
    """
    return banana
开发者ID:gaganshrestha,项目名称:uthcode,代码行数:26,代码来源:version04.py

示例4: __init__

    def __init__(self, space, x, y, mass, sprite, sprite_size=1):
        pygame.sprite.Sprite.__init__(self)
    
        self.image, self.rect = load_image(sprite)
        
        # This is not exactly an ideal way to figure this out
        self.width = self.rect[2]
        self.height = self.rect[3]
        
        # This will resize the sprite if we've resized it
        self.image = pygame.transform.scale(self.image, (int(self.width * sprite_size), int(self.height * sprite_size) ))
    
        self.space = space
        self.mass = mass
        
        ## Need to offset the points of the shape so that the center of the image is at (0, 0)		
        offset = Vec2d(self.width/2, self.height/2)
        
        bounds = self.rect
        points = [Vec2d(bounds.topleft) - offset, Vec2d(bounds.topright) - offset, Vec2d(bounds.bottomright) - offset, Vec2d(bounds.bottomleft) - offset] 
        #### End of shape offset code - we can now pass the points to the body/shape creation ####

        inertia = pymunk.moment_for_poly(mass, points, (0,0))
        self.body = pymunk.Body(mass, inertia)
        self.body.position = x, y
    
        self.shape = pymunk.Poly(self.body, points, (0, 0) )
        self.shape.friction = DEFAULT_FRICTION_AMT
        
        game.space.add(self.body, self.shape)
开发者ID:pangal,项目名称:dlm,代码行数:30,代码来源:delongestmile.py

示例5: add_triangle

    def add_triangle(self, vertices, random_color):
        vbackup = vertices
        vertices = [int(v) for v in vertices]
        vertices  = zip(vertices[::2], vertices[1::2])
        center = cymunk.util.calc_center(vertices)
        body = cymunk.Body(100,
            cymunk.moment_for_poly(100, vertices))
        body.position.x = center[0]
        body.position.y = center[1]
        triangle = cymunk.Poly(body, vertices)
        triangle.elasticity = 0.6
        triangle.friction = FRICTION
        self.space.add(body, triangle)

        with self.parent.canvas.before:
            color = Color(*random_color, mode="rgba")
            rot = Rotate(angle=0, axis=(0, 0, 1), origin=center)
            triangle_shape = Triangle(points=vbackup)
            unrot = Rotate(0, (0, 0, 1), origin=center)
        body.data = {
            "color": color,
            "instruction": [triangle_shape, rot, unrot],
            "type": TRIANGLE_TYPE,
            "shapes": [triangle],
        }    
开发者ID:vipulroxx,项目名称:physics,代码行数:25,代码来源:renderer.py

示例6: create_body_poly

	def create_body_poly(self, mass, posinit, points):
		center = pm.util.calc_center(points)
		points = pm.util.poly_vectors_around_center(points)
		moment = pm.moment_for_poly(mass,points, Vec2d(0,0))
		body = pm.Body(mass, moment)
		body.position = Vec2d(posinit)
		return body, points
开发者ID:utcoupe,项目名称:coupe2013,代码行数:7,代码来源:motorphysic.py

示例7: __init__

    def __init__(self, world_pos, vertices, mass, friction=0.8, moment = None, taggable=True, grabable=False, texture_name=None, dynamic=True, collision_group=0, layers=2**32-1):
        self._world_entity_manager = None

        self._is_dynamic = True

        self._verts = vertices
        pymunk_verts = map(Vec2d, vertices)
        
        if not moment:
            moment = pymunk.moment_for_poly(mass, pymunk_verts, (0,0))

        self._body = pymunk.Body(mass, moment)
        self._body.position = world_pos
  
        self._shape = pymunk.Poly(self._body, pymunk_verts, (0,0) )
        self._shape.friction = friction

        self._is_taggable = taggable
        self._is_grabable = grabable
        self._texture_name = texture_name
        self._is_dynamic = dynamic
        self._time_passed = 0.0
        self._shape.layers = layers
        self._taggable_attached = None

        self._shape.group = collision_group

        if not self._is_dynamic:
            self._bounding_rect_cache = self.get_bounding_rect(force=True)

        self._tags = {}
        self._attached = False
开发者ID:goosemo,项目名称:monkey,代码行数:32,代码来源:world.py

示例8: __init__

	def __init__(self, pos):
		Collidable.__init__(self, self.groups)
		self.left_images = []
		for i in self.right_images:
			self.left_images.append(pygame.transform.flip(i, 1, 0))
		self.image = self.right_images[0]
		self.rect = self.image.get_rect()
		self.jump_speed = 0
		self.jump_accel = 0.3
		self.jumping = False
		self.frame = 0
		self.facing = 1
		self.still_timer = 0
		self.hit_timer = 0
		self.health = 5
		self.heat = 100
		
		w = self.rect.width/2 - 20
		h = self.rect.height/2 - 10
		
		poly = [(-w,-h),(w,-h),(w,h),(-w,h)]
		mass = 1000
		moment = pymunk.moment_for_poly(mass, poly)
		self.body = pymunk.Body(mass, pymunk.inf)
		
		self.shape = pymunk.Poly(self.body, poly)
		self.shape.color = THECOLORS["blue"]
		self.shape.friction = 3
		
		self.rect.topleft = pos
		self.body.position = (self.rect.center[0],480-self.rect.center[1])
		self.jumping = False
开发者ID:cullophid,项目名称:Scienceman,代码行数:32,代码来源:sprites.py

示例9: add_square

  def add_square(self, pos, a=18, density=0.1, friction=0.2, elasticity=0.3):
    """ Adding a Square | Note that a is actually half a side, due to vector easyness :) 
        Parameter: pos == (int(x), int(y))
        Optional: a == (sidelen/2) | #physical_parameters
        Returns: pymunk.Shape() (=> .Poly())
    """
    mass = density * (a * a * 4)
    
    # Square Vectors (Clockwise)
    verts = [Vec2d(-a,-a), Vec2d(-a, a), Vec2d(a, a), Vec2d(a,-a)]
    
    # Square Physic Settings
    inertia = pm.moment_for_poly(mass, verts, Vec2d(0,0))
  
    # Create Body
    body = pm.Body(mass, inertia)
    body.position = self.Vec2df(pos)
  
    # Create Shape
    shape = pm.Poly(body, verts, Vec2d(0,0))
    shape.riction = friction
    shape.elasticity = elasticity

    shape.color = self.get_color()
    shape.color2 = self.get_color()
          
    # Append to Space
    self.space.add(body, shape)
    self.element_count += 1
    return shape
开发者ID:lamielle,项目名称:aether,代码行数:30,代码来源:pymunx.py

示例10: _create_pm_object

    def _create_pm_object(self, shape):
        mass = shape.body.mass
        inertia = shape.body.inertia
        pm_body = pm.Body(mass, inertia)
        pm_body.position = shape.position

        if isinstance(shape, Circle):
            radius = shape.radius
            # WARNING: for now, circle shapes are completely aligned to their
            # body's center of gravity
            offset = (0, 0)
            pm_obj = pm.Circle(pm_body, radius,  offset)
        elif isinstance(shape, Segment):
            # WARNING: the segment is assumed to be centered around its position
            # points a and b are equally distant from the segments center
            #print 'creating segment: pos:',  pm_body.position, 'from: ', shape.a,  'to: ', shape.b, 'radius: ', shape.radius

            pm_obj = pm.Segment(pm_body, shape.a, shape.b, shape.radius)
        elif isinstance(shape, Polygon):
            vertices = shape.vertices
            # WARNING: for now, polygon shapes are completely aligned to their
            # body's center of gravity
            offset = (0, 0)
            moment = pm.moment_for_poly(mass, vertices, offset)
            pm_body = pm.Body(mass, moment)
            pm_obj = pm.Poly(pm_body, vertices, offset)
        return pm_obj
开发者ID:ricardoquesada,项目名称:aiamsori,代码行数:27,代码来源:collision.py

示例11: spawn_ball

def spawn_ball(dt, position, direction):
    x, y = position
    angle = random.random() * math.pi
    vs = [(-23, 26), (23, 26), (0, -26)]
    mass = 10
    moment = pymunk.moment_for_poly(mass, vs)
    body = pymunk.Body(mass, moment)
    body.apply_impulse(Vec2d(direction))
    # Keep ball velocity at a static value
    def constant_velocity(body, gravity, damping, dt):
        body.velocity = body.velocity.normalized() * 400
    body.velocity_func = constant_velocity

    shape = pymunk.Circle(body, ball_img.width / 2)
    # shape.friction = 0.5
    shape.elasticity = 1.0
    body.position = x, y
    body.angle = angle

    space.add(body, shape)

    sprite = pyglet.sprite.Sprite(ball_img, batch=batch)
    sprite.shape = shape
    sprite.body = body
    logos.append(sprite)
开发者ID:pasoev,项目名称:praxis,代码行数:25,代码来源:using_sprites_pyglet.py

示例12: create_square_thing

def create_square_thing(world, layer, position, image):
    points = [(0,0),(32,0),(32,32),(0,32)]
    shape = ConvexPolygonShape(*points)
    shape.translate( shape.centroid() * -1)
    moment = pymunk.moment_for_poly( 1.0, shape.vertices )
    rv = Debris( world, layer, position, shape, image, moment = moment, collision_type = physics.CollisionTypes["main"] )
    return rv
开发者ID:steinarvk,项目名称:blockspace,代码行数:7,代码来源:game.py

示例13: _build_physics_elements

    def _build_physics_elements(self):
        self.dynamic_object = []
        for element in self.collect_object_list:
            width, height = element.size
            mass = width * height
            if element.is_circle:
                moment = pymunk.moment_for_circle(mass, 0, 100)
                body = pymunk.Body(mass, moment)
                shape = pymunk.Circle(body, width/2)
                body.elasticity = 0.9
            else:
                vs = [(-width/2, height/2), (width/2, height/2), (width/2, -height/2), (-width/2, -height/2)]
                moment = pymunk.moment_for_poly(mass, vs)
                body = pymunk.Body(mass, moment)
                shape = pymunk.Poly(body, vs)
            shape.friction = 0.6
            body.position = element.position[0]+width/2, self.flipy(element.position[1]+height/2)
            body.angle = math.pi
            self.space.add(body, shape)
            self.dynamic_object.append((element, shape))

        static_body = pymunk.Body()
        for element in self.collide_object_list:
            x, y = element.position[0], self.flipy(element.position[1])
            width, height = element.size[0], element.size[1]
            static_lines = [pymunk.Segment(static_body, (x, y), (x+width, y), 0.0),
                            pymunk.Segment(static_body, (x+width, y), (x+width, y-height), 0.0),
                            pymunk.Segment(static_body, (x+width, y-height), (x, y-height), 0.0),
                            pymunk.Segment(static_body, (x, y-height), (x, y), 0.0),
                            ]
            for l in static_lines:
                l.friction = 0.5
            self.space.add(static_lines)
开发者ID:joaompinto,项目名称:DragonWalk,代码行数:33,代码来源:level.py

示例14: __init__

    def __init__(self,x=600,y=-20,angle=0,angular_velocity=0,buoyancy=pymunk.Vec2d(0,-8000)):
        pygame.sprite.Sprite.__init__(self)
        self.image_default = pygame.image.load("images/airship-balloon.png").convert()
        self.image_default.set_colorkey((1,0,0))
        self.image = self.image_default
        
        self.rect = self.image.get_rect()
        self.rect.center = (x, y)
        
        offset = (0,0) # center of gravity
        points = [(-210, -7), (-196, -24), (-82, -56), (-26, -60), (27, -60), (83, -56), (197, -24), (212, -7), (212, 6), (197, 25), (83, 57), (27, 61), (-26, 61), (-82, 57), (-196, 25), (-210, 8)]
        mass = 10
        moment = pymunk.moment_for_poly(mass,points)
        self.body = pymunk.Body(mass,moment)
        self.body.position = x,y
        self.body.angular_velocity = angular_velocity
        self.body.velocity_limit = 300
        

        self.shape = pymunk.Poly(self.body, points)
        self.shapes = [self.shape]
        
        self.shape.elasticity = 1
        self.shape.friction = .5
        self.shape.collision_type = 1    # 0 - can't jump off of it; 1 - can jump when standing on it

        self.buoyancy = buoyancy
        self.body.apply_force(buoyancy)
开发者ID:mklopot,项目名称:mia-in-a-maze,代码行数:28,代码来源:airship.py

示例15: load_poly_concave

def load_poly_concave(tmxobject, map_height, static_body, defaults):
    """
    Creates several pymunk.Poly objects parsed from a TiledObject instance.
    They share a common pymunk.Body object.

    :param TiledObject tmxobject: A TiledObject instance that represents a \
    concave polygon with multiple vertices.
    :param int map_height: The height of the TiledMap that the TiledObject \
    was loaded from in pixels.

    """

    poly_defaults = defaults["pymunktmx_poly"]
    shape_attrs = get_shape_attrs(tmxobject, poly_defaults)
    body_attrs = get_body_attrs(tmxobject, poly_defaults)
    offset = body_attrs[u"offset"]
    radius = shape_attrs[u"radius"]

    # break concave shape into triangles
    points = list(tmxobject.points)

    # pymunk.util.triangulate expects the list to be in anti-clockwise order
    if pymunk.util.is_clockwise(points):
        points.reverse()

    # the pymunk.util.convexise doesn't create shapes that match originals
    # so we will just use the triangles
    triangles = pymunk.util.triangulate(points)

    shapes = []
    if body_attrs[u"static"]:
        for vertices in triangles:
            vertices = [(p[0], map_height - p[1]) for p in vertices]
            shape = pymunk.Poly(static_body, vertices, offset, radius)
            shapes.append(shape)

    else:
        x = float(tmxobject.x)
        y = float(float(map_height) - tmxobject.y)
        mass = body_attrs[u"mass"]
        verts = [(p[0] - x, -(p[1] - y)) for p in tmxobject.points]
        moment = pymunk.moment_for_poly(mass, verts, offset)
        body = pymunk.Body(mass, moment)
        body.position = (x, y)

        set_attrs(body_attrs, body,
                  skip_keys=[u"position", u"mass", u"static"])

        for vertices in triangles:
            vertices = [(p[0] - x, -(p[1] - y)) for p in vertices]
            shape = pymunk.Poly(body, vertices, offset, radius)
            shapes.append(shape)

        shapes.append(body)

    for shape in shapes:
        set_attrs(shape_attrs, shape, skip_keys=[u"radius"])

    return shapes
开发者ID:bitcraft,项目名称:sanic,代码行数:59,代码来源:shapeloader.py


注:本文中的pymunk.moment_for_poly函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。