本文整理汇总了Python中pymunk.moment_for_circle函数的典型用法代码示例。如果您正苦于以下问题:Python moment_for_circle函数的具体用法?Python moment_for_circle怎么用?Python moment_for_circle使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了moment_for_circle函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: car
def car(self, space):
pos = Vec2d(100,100)
wheel_color = .2,.86,.47
shovel_color = .86,.47,.2
mass = 100
radius = 25
moment = pymunk.moment_for_circle(mass, 20, radius)
wheel1_b = pymunk.Body(mass, moment)
wheel1_s = pymunk.Circle(wheel1_b, radius)
wheel1_s.friction = 1.5
wheel1_s.color = wheel_color
space.add(wheel1_b, wheel1_s)
mass = 100
radius = 25
moment = pymunk.moment_for_circle(mass, 20, radius)
wheel2_b = pymunk.Body(mass, moment)
wheel2_s = pymunk.Circle(wheel2_b, radius)
wheel2_s.friction = 1.5
wheel2_s.color = wheel_color
space.add(wheel2_b, wheel2_s)
mass = 100
size = (50,30)
moment = pymunk.moment_for_box(mass, size)
chassi_b = pymunk.Body(mass, moment)
chassi_s = pymunk.Poly.create_box(chassi_b, size)
space.add(chassi_b, chassi_s)
vs = [(0,0),(0,-45),(25,-45)]
shovel_s = pymunk.Poly(chassi_b, vs, transform = pymunk.Transform(tx=85))
shovel_s.friction = 0.5
shovel_s.color = shovel_color
space.add(shovel_s)
wheel1_b.position = pos - (55,0)
wheel2_b.position = pos + (55,0)
chassi_b.position = pos + (0,25)
space.add(
pymunk.PinJoint(wheel1_b, chassi_b, (0,0), (-25,-15)),
pymunk.PinJoint(wheel1_b, chassi_b, (0,0), (-25, 15)),
pymunk.PinJoint(wheel2_b, chassi_b, (0,0), (25,-15)),
pymunk.PinJoint(wheel2_b, chassi_b, (0,0), (25, 15))
)
speed = -4
space.add(
pymunk.SimpleMotor(wheel1_b, chassi_b, speed),
pymunk.SimpleMotor(wheel2_b, chassi_b, speed)
)
with self.canvas:
Color(*wheel_color)
wheel1_s.ky = self.ellipse_from_circle(wheel1_s)
Color(*wheel_color)
wheel2_s.ky = self.ellipse_from_circle(wheel2_s)
Color(*shovel_color)
chassi_s.ky = Quad(points=self.points_from_poly(chassi_s))
shovel_s.ky = Triangle(points=self.points_from_poly(shovel_s))
示例2: __init__
def __init__(self, body_mass, body_position, body_size, wheel_base):
self.body_mass = body_mass
self.body_position = body_position
self.body_size = body_size
self.body_body = pymunk.Body(self.body_mass, 1000)
self.body_body.position = self.body_position
self.body_poly = pymunk.Poly.create_box(self.body_body, self.body_size)
self.body_poly.friction = 0.5
body_space.add(self.body_body, self.body_poly)
self.wheel_base = wheel_base
self.wheelL_mass = 1
self.wheelL_radius = (self.body_size[1]//1.5)
self.wheelL_position_x = self.body_position[0]-(self.body_size[0]//2)+self.wheelL_radius - self.wheel_base
self.wheelL_position_y = self.body_position[1] + self.body_size[1]*1.5
self.wheelL_position = self.wheelL_position_x, self.wheelL_position_y
self.inertiaL = pymunk.moment_for_circle(self.wheelL_mass, 0, self.wheelL_radius)
self.wheelL_b = pymunk.Body(self.wheelL_mass, self.inertiaL)
self.wheelL_b.position = self.wheelL_position
self.wheelL_shape = pymunk.Circle(self.wheelL_b, self.wheelL_radius)
self.wheelL_shape.friction = 0.5
space.add(self.wheelL_b, self.wheelL_shape)
self.wheelR_mass = 1
self.wheelR_radius = (self.body_size[1]//1.5)
self.wheelR_position_x = self.body_position[0]+(self.body_size[0]//2)-self.wheelL_radius + self.wheel_base
self.wheelR_position_y = self.body_position[1] + self.body_size[1]*1.5
self.wheelR_position = self.wheelR_position_x, self.wheelR_position_y
self.inertiaR = pymunk.moment_for_circle(self.wheelR_mass, 0, self.wheelR_radius)
self.wheelR_b = pymunk.Body(self.wheelR_mass, self.inertiaR)
self.wheelR_b.position = self.wheelR_position
self.wheelR_shape = pymunk.Circle(self.wheelR_b, self.wheelR_radius)
self.wheelR_shape.friction = 0.5
space.add(self.wheelR_b, self.wheelR_shape)
self.left_spring = pymunk.constraint.DampedSpring(self.body_body, self.wheelL_b, (0, self.body_size[1]//2), (0,0), 200, 80.0, 50)
self.right_spring = pymunk.constraint.DampedSpring(self.body_body, self.wheelR_b, (0, self.body_size[1]//2), (0,0), 200, 80.0, 50)
self.left_groove_start = (-self.body_size[0]//2 + self.wheelL_radius, 0)
self.left_groove_end = (-self.body_size[0]//2 + self.wheelL_radius - self.wheel_base, self.wheelL_radius + 20)
self.left_groove_joint = pymunk.constraint.GrooveJoint(self.body_body, self.wheelL_b, self.left_groove_start, self.left_groove_end, (0,0))
self.right_groove_start = (self.body_size[0]//2 - self.wheelL_radius, 0)
self.right_groove_end = (self.body_size[0]//2 - self.wheelR_radius + self.wheel_base, self.wheelR_radius + 20)
self.right_groove_joint = pymunk.constraint.GrooveJoint(self.body_body, self.wheelR_b, self.right_groove_start, self.right_groove_end, (0,0))
space.add(self.left_spring, self.right_spring, self.left_groove_joint, self.right_groove_joint)
示例3: __init__
def __init__(self, body_mass, body_position, body_size, wheel_base):
self.body_mass = body_mass
self.body_position = body_position
self.body_size = body_size
self.body_body = pymunk.Body(self.body_mass, 1000)
self.body_body.position = self.body_position
self.body_poly = pymunk.Poly.create_box(self.body_body, self.body_size)
self.body_poly.friction = 0.5
body_space.add(self.body_body, self.body_poly)
self.wheel_base = wheel_base
self.wheelL_mass = 1
self.wheelL_radius = (self.body_size[1]//1.5)
self.wheelL_position_x = self.body_position[0]-(self.body_size[0]//2)+self.wheelL_radius - self.wheel_base
self.wheelL_position_y = self.body_position[1] + self.body_size[1] + 20
self.wheelL_position = self.wheelL_position_x, self.wheelL_position_y
self.inertiaL = pymunk.moment_for_circle(self.wheelL_mass, 0, self.wheelL_radius)
self.wheelL_b = pymunk.Body(self.wheelL_mass, self.inertiaL)
self.wheelL_b.position = self.wheelL_position
self.wheelL_shape = pymunk.Circle(self.wheelL_b, self.wheelL_radius)
self.wheelL_shape.friction = 0.5
space.add(self.wheelL_b, self.wheelL_shape)
self.wheelR_mass = 1
self.wheelR_radius = (self.body_size[1]//1.5)
self.wheelR_position_x = self.body_position[0]+(self.body_size[0]//2)-self.wheelL_radius + self.wheel_base
self.wheelR_position_y = self.body_position[1] + self.body_size[1] + 20
self.wheelR_position = self.wheelR_position_x, self.wheelR_position_y
self.inertiaR = pymunk.moment_for_circle(self.wheelR_mass, 0, self.wheelR_radius)
self.wheelR_b = pymunk.Body(self.wheelR_mass, self.inertiaR)
self.wheelR_b.position = self.wheelR_position
self.wheelR_shape = pymunk.Circle(self.wheelR_b, self.wheelR_radius)
self.wheelR_shape.friction = 0.5
space.add(self.wheelR_b, self.wheelR_shape)
self.left_spring = pymunk.constraint.DampedSpring(self.body_body, self.wheelL_b, (-self.body_size[0]//2, 0), (0,0), self.wheelL_position_y, 7.0, 7)
self.right_spring = pymunk.constraint.DampedSpring(self.body_body, self.wheelR_b, (self.body_size[0]//2, 0), (0,0), self.wheelR_position_y, 7.0, 7)
self.middle_spring = pymunk.constraint.DampedSpring(self.wheelL_b, self.wheelR_b, (0,0), (0,0), self.body_size[0], 100.0, 5)
self.left_pinjoint = pymunk.constraint.PinJoint(self.body_body, self.wheelL_b, (0,0), (0,0))
self.right_pinjoint = pymunk.constraint.PinJoint(self.body_body, self.wheelR_b, (0,0), (0,0))
space.add(self.left_spring, self.right_spring, self.left_pinjoint, self.right_pinjoint, self.middle_spring)
示例4: car
def car(space):
pos = Vec2d(100,200)
wheel_color = 52,219,119
shovel_color = 219,119,52
mass = 100
radius = 25
moment = pymunk.moment_for_circle(mass, 20, radius)
wheel1_b = pymunk.Body(mass, moment)
wheel1_s = pymunk.Circle(wheel1_b, radius)
wheel1_s.friction = 1.5
wheel1_s.color = wheel_color
space.add(wheel1_b, wheel1_s)
mass = 100
radius = 25
moment = pymunk.moment_for_circle(mass, 20, radius)
wheel2_b = pymunk.Body(mass, moment)
wheel2_s = pymunk.Circle(wheel2_b, radius)
wheel2_s.friction = 1.5
wheel2_s.color = wheel_color
space.add(wheel2_b, wheel2_s)
mass = 100
size = (50,30)
moment = pymunk.moment_for_box(mass, size)
chassi_b = pymunk.Body(mass, moment)
chassi_s = pymunk.Poly.create_box(chassi_b, size)
space.add(chassi_b, chassi_s)
vs = [(0,0),(25,45),(0,45)]
shovel_s = pymunk.Poly(chassi_b, vs, transform = pymunk.Transform(tx=85))
shovel_s.friction = 0.5
shovel_s.color = shovel_color
space.add(shovel_s)
wheel1_b.position = pos - (55,0)
wheel2_b.position = pos + (55,0)
chassi_b.position = pos + (0,-25)
space.add(
pymunk.PinJoint(wheel1_b, chassi_b, (0,0), (-25,-15)),
pymunk.PinJoint(wheel1_b, chassi_b, (0,0), (-25, 15)),
pymunk.PinJoint(wheel2_b, chassi_b, (0,0), (25,-15)),
pymunk.PinJoint(wheel2_b, chassi_b, (0,0), (25, 15))
)
speed = 4
space.add(
pymunk.SimpleMotor(wheel1_b, chassi_b, speed),
pymunk.SimpleMotor(wheel2_b, chassi_b, speed)
)
示例5: __init__
def __init__(self, pos, rot, child_unit):
self.unit = child_unit
self.obj_id = child_unit.obj_id
inertia = pymunk.moment_for_circle(
self.unit.mass, 0, self.unit.radius,(0,0)
)
self.body = pymunk.Body(self.unit.mass, inertia)
self.unit.set_offset(0,0)
self.unit.local_angle = 0
self.unit.local_angle_target = 0
self.unit.rotation = 0
self.unit.initialize(self,collision_type=physics.FREE)
self.body.angle = math.radians(rot)
self.body.position = pos
self.angle_degrees = rot
self.attachable = True
self.visible = True
physics.body_update_list.append(self)
physics.unit_update_list.append(self.unit)
physics.space.add(self.body)
self.unit.add_shapes()
示例6: update_center_of_mass_old
def update_center_of_mass_old(self):
if len(self.units) == 0: return
avg_x = 0.0
avg_y = 0.0
mass_total = 0.0
inertia_total = 0.0
for u in self.units:
mass_total += u.mass
inertia_total += pymunk.moment_for_circle(
u.mass, 0, u.radius, u.offset)
avg_x += u.mass * u.offset[0]
avg_y += u.mass * u.offset[1]
u.remove_shapes()
avg_x /= mass_total
avg_y /= mass_total
new_body_position = self.body.local_to_world((avg_x,avg_y))
old_body = self.body
physics.space.remove(old_body)
self.body = pymunk.Body(mass_total, inertia_total)
self.body.position = new_body_position
self.body.velocity = old_body.velocity
self.body.angular_velocity = old_body.angular_velocity
self.body.angle = old_body.angle
old_body = None
physics.space.add(self.body)
for u in self.units:
x, y = u.offset[0]-avg_x, u.offset[1]-avg_y
u.set_offset(x,y)
u.initialize(self,collision_type=physics.PLAYER)
u.add_shapes()
示例7: update_center_of_mass
def update_center_of_mass(self):
if len(self.units) == 0: return
avg_x = 0.0
avg_y = 0.0
mass_total = 0.0
inertia_total = 0.0
for u in self.units:
mass_total += u.mass
inertia_total += pymunk.moment_for_circle(
u.mass, 0, u.radius, u.offset)
avg_x += u.mass * u.offset[0]
avg_y += u.mass * u.offset[1]
#u.remove_shapes()
avg_x /= mass_total
avg_y /= mass_total
new_body_position = self.body.local_to_world((avg_x,avg_y))
self.body.position = new_body_position
self.body.mass = mass_total
self.body.moment = inertia_total
for u in self.units:
x, y = u.offset[0]-avg_x, u.offset[1]-avg_y
u.set_offset(x,y)
u.update_shapes()
示例8: __init__
def __init__(self, scene, tex = 'blinky', position=(0,0)):
self.start_pos = position
radius, mass = 7, .001
p_man_moment = pymunk.moment_for_circle(mass, 0, radius)
self.ghost_b = pymunk.Body(mass, p_man_moment)
self.ghost_b.position = position
self.ghost_shape = pymunk.Circle(self.ghost_b, radius)
self.ghost_shape.friction = .5
self.ghost_shape.elasticity = .2
self.ghost_shape.collision_type = 4
self.ghost_shape.fill_color = (0,0,0,0)
scene.space.add(self.ghost_b, self.ghost_shape)
ghost_img = pyglet.image.load('resources/textures/'+tex+'.png')
ghost_img.anchor_x, ghost_img.anchor_y = ghost_img.width/2, ghost_img.height/2
tex = ghost_img.get_texture()
glTexParameteri(tex.target, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
glTexParameteri(tex.target, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
self.ghost_s = pyglet.sprite.Sprite(
ghost_img, batch=scene.normal_batch, group=scene.ordered_group3)
self.ghost_s.scale = 1
self.ghost_b.on_tween_complete = self.on_tween_complete
self.ghost_b.update_tween = self.update_tween
self.ghost_b.posx = position[0]
self.ghost_b.posy = position[1]
示例9: __init__
def __init__(self, world, position, width=1.6, length=4.0, tire_width=.25, tire_length=.8, skidmarks=None, body_density=1.0):
mass = width * length * body_density
inertia = moment_for_box(mass, width, length)
self.world = world
body = Body(mass, inertia, )
body.position = position
shape = Poly.create_box(body, size=(width, length))
super(Car, self).__init__(world, body, shape)
slot_density = .01
slot_radius = .1
slot_mass = slot_density * (slot_radius ** 2) * pi
slot_inertia = moment_for_circle(slot_mass, 0.0, slot_radius)
#self.slot = Body(slot_mass, slot_inertia)
flpos = position[0] - width / 2.0 - tire_width * 2, position[1] + length / 2.0
self.front_left = Tire(self, flpos, tire_width, tire_length, skidmarks=skidmarks, powered=False, density=body_density)
frpos = position[0] + width / 2.0 + tire_width * 2, position[1] + length / 2.0
self.front_right = Tire(self, frpos, tire_width, tire_length, skidmarks=skidmarks, powered=False, density=body_density)
rlpos = position[0] - width / 2.0 - tire_width * 2, position[1] - length / 2.0
self.rear_left = Tire(self, rlpos, tire_width * 1.5, tire_length, steerable=False, skidmarks=skidmarks, density=body_density)
rrpos = position[0] + width / 2.0 + tire_width * 2, position[1] - length / 2.0
self.rear_right = Tire(self, rrpos, tire_width * 1.5, tire_length, steerable=False, skidmarks=skidmarks, density=body_density)
self.tires = [self.front_left, self.front_right, self.rear_left, self.rear_right]
示例10: __init__
def __init__(self, space, x, y):
inertia = pymunk.moment_for_circle(Raindrop.MASS, 0, Raindrop.RADIUS)
self.body = pymunk.Body(Raindrop.MASS, inertia)
self.body.position = x, y
shape = pymunk.Circle(self.body, Raindrop.RADIUS)
shape.friction = 0.5
space.add(self.body, shape)
示例11: create_ball
def create_ball(self, x, y, mass=40, radius=7):
inertia = pymunk.moment_for_circle(mass, 0, radius, (0, 0))
body = pymunk.Body(mass, inertia)
body.position = x, y
shape = pymunk.Circle(body, radius, (0, 0))
shape.elasticity = 0.95
return body, shape
示例12: __init__
def __init__(self, x, y):
self.mass = 1
self.radius = 14
self.inertia = pk.moment_for_circle(self.mass, 0, self.radius)
self.body = pk.Body(self.mass, self.inertia)
self.body.position = x, y
self.shape = pk.Circle(self.body, self.radius)
示例13: __init__
def __init__(
self, col_type, img, damage,
x, y, vx, vy, rotate=False, batch=None, group=None
):
super(Bullet, self).__init__(img, x, y, batch=batch, group=group)
self.damage = damage
if rotate:
self.rotation = math.degrees(-math.atan2(vy, vx))
radius = 4
mass = physics.default_density*(radius*radius*2*math.pi)
inertia = pymunk.moment_for_circle(mass, 0, radius, (0,0))
self.body = pymunk.Body(mass, inertia)
self.body.position = (x,y)
self.body.velocity = (vx, vy)
self.shape = pymunk.Circle(self.body, radius, (0,0))
self.shape.friction = 1.0
self.shape.elasticity = 0.0
self.shape.parent = self
self.shape.collision_type = col_type
self.shape.layers = 1
physics.space.add(self.body)
physics.space.add(self.shape)
physics.body_update_list.append(self)
示例14: addBall
def addBall(self, mass, radius, pos):
inertia = pymunk.moment_for_circle(mass, 0, radius, (0, 0))
body = pymunk.Body(mass, inertia)
body.position = pos
shape = pymunk.Circle(body, radius, (0, 0))
shape.elasticity = 0.75
return shape
示例15: __init__
def __init__(self, level, radius=100, position=(0,0), density=1.0, verticies=None, orbit=None, mass=None, static=False, **kwargs):
# physics
if not mass:
mass = math.pi * radius**2 * density #4/3 * math.pi * radius**3 * density * 0.1
inertia = pymunk.moment_for_circle(mass, 0, radius, (0,0))
body = pymunk.Body(mass, inertia)
body.position = Vec2d(position)
body.radius = radius
shape = pymunk.Circle(body, radius, (0,0))
shape.friction = 2
if static:
level.space.add_static(body,shape)
else:
level.space.add(body,shape)
# visuals
if not verticies:
verticies = int(radius / 5.) + 10
vert_list = generate_circle(radius=radius, steps=verticies)
display = level.batch.add(verticies, GL_LINE_LOOP, PositionedList(self), ('v2f', vert_list))
if orbit:
gravitation = level.gravity * (body.mass + orbit.body.mass)
distance = body.position.get_distance(orbit.body.position)
speed = (gravitation/distance)**(0.5)
body.velocity = (body.position - orbit.body.position).rotated(90).normalized() * speed
self.body = body
self.shape = shape
self.display = display
self.level = level