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


Python pymunk.Segment方法代码示例

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


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

示例1: add_bottle

# 需要导入模块: import pymunk [as 别名]
# 或者: from pymunk import Segment [as 别名]
def add_bottle(space):
    mass = 10
    inertia = 0xFFFFFFFFF

    body = pymunk.Body(mass, inertia)
    body.position = (130,300)

    l1 = pymunk.Segment(body, (-150, 0), (-100, 0), 2.0)
    l2 = pymunk.Segment(body, (-150, 0), (-150, 100), 2.0)
    l3 = pymunk.Segment(body, (-100, 0), (-100, 100), 2.0)

    # Glass friction
    l1.friction = 0.94
    l2.friction = 0.94
    l3.friction = 0.94

    # Set collision types for sensors
    l1.collision_type = 0x2 # bottle_bottom
    l2.collision_type = 0x3 # bottle_right_side
    l3.collision_type = 0x4 # bottle_left_side

    space.add(l1, l2, l3, body)

    return l1,l2,l3 
开发者ID:jseidl,项目名称:virtuaplant,代码行数:26,代码来源:world.py

示例2: __init__

# 需要导入模块: import pymunk [as 别名]
# 或者: from pymunk import Segment [as 别名]
def __init__(self, space, p1, p2, thickness, mass, static, cosmetic=False):
        x = (p1[0] + p2[0]) / 2
        y = (p1[1] + p2[1]) / 2

        if not cosmetic:
            moment = pymunk.moment_for_segment(mass, (p1[0]-x, p1[1]-y), (p2[0]-x, p2[1]-y), thickness)

            if static:
                self.body = pymunk.Body(mass, moment, pymunk.Body.STATIC)
            else:
                self.body = pymunk.Body(mass, moment)

            self.body.position = x, y
            self.shape = pymunk.Segment(self.body, (p1[0]-x, p1[1]-y), (p2[0]-x, p2[1]-y), thickness)
            space.add(self.body, self.shape)

        self.radius = thickness
        self.static = static
        self._p1 = p1
        self._p2 = p2
        self._x = x;
        self._y = y

        super().__init__(cosmetic) 
开发者ID:jshaffstall,项目名称:PyPhysicsSandbox,代码行数:26,代码来源:line_segment.py

示例3: create_obstacle

# 需要导入模块: import pymunk [as 别名]
# 或者: from pymunk import Segment [as 别名]
def create_obstacle(self, xy1, xy2, r, color):
        c_body = pymunk.Body(pymunk.inf, pymunk.inf)
        #c_shape = pymunk.Circle(c_body, r)
        c_shape = pymunk.Segment(c_body, xy1, xy2, r)
        #c_shape.elasticity = 1.0
        #c_body.position = x, y
        c_shape.friction = 1.
        c_shape.group = 1
        c_shape.collision_type = 1
        c_shape.color = THECOLORS[color]
        self.space.add(c_body, c_shape)
        return c_body 
开发者ID:jangirrishabh,项目名称:toyCarIRL,代码行数:14,代码来源:carmunk.py

示例4: add_wall

# 需要导入模块: import pymunk [as 别名]
# 或者: from pymunk import Segment [as 别名]
def add_wall(self, space, pt_from, pt_to):
        body = pymunk.Body(body_type=pymunk.Body.STATIC)
        ground_shape = pymunk.Segment(body, pt_from, pt_to, 0.0)
        ground_shape.friction = 0.8
        ground_shape.elasticity = .99
        self.space.add(ground_shape) 
开发者ID:PySimpleGUI,项目名称:PySimpleGUI,代码行数:8,代码来源:Demo_Graph_pymunk_2D_Graphics.py

示例5: add_wall

# 需要导入模块: import pymunk [as 别名]
# 或者: from pymunk import Segment [as 别名]
def add_wall(self, pt_from, pt_to):
        body =  pymunk.Body(body_type=pymunk.Body.STATIC)
        ground_shape = pymunk.Segment(body, pt_from, pt_to, 0.0)
        ground_shape.friction = 0.8
        ground_shape.elasticity = .99
        self.space.add(ground_shape) 
开发者ID:PySimpleGUI,项目名称:PySimpleGUI,代码行数:8,代码来源:Demo_Graph_pymunk_2D_Graphics.py

示例6: add_wall

# 需要导入模块: import pymunk [as 别名]
# 或者: from pymunk import Segment [as 别名]
def add_wall(self, pt_from, pt_to):
        body = pymunk.Body(body_type=pymunk.Body.STATIC)
        ground_shape = pymunk.Segment(body, pt_from, pt_to, 0.0)
        ground_shape.friction = 0.8
        ground_shape.elasticity = .99
        self.space.add(ground_shape) 
开发者ID:PySimpleGUI,项目名称:PySimpleGUI,代码行数:8,代码来源:Demo_Graph_pymunk_2D_Graphics.py

示例7: add_wall

# 需要导入模块: import pymunk [as 别名]
# 或者: from pymunk import Segment [as 别名]
def add_wall(self, pt_from, pt_to):
        body = pymunk.Body(body_type=pymunk.Body.STATIC)
        ground_shape = pymunk.Segment(body, pt_from, pt_to, 0.0)
        ground_shape.friction = 0.8
        ground_shape.elasticity = .99
        ground_shape.mass = pymunk.inf
        self.space.add(ground_shape) 
开发者ID:PySimpleGUI,项目名称:PySimpleGUI,代码行数:9,代码来源:Demo_Graph_Ball_Game.py

示例8: init_walls

# 需要导入模块: import pymunk [as 别名]
# 或者: from pymunk import Segment [as 别名]
def init_walls(space):  # Initializes the four outer walls of the board
    body = pymunk.Body(body_type=pymunk.Body.STATIC)
    walls = [pymunk.Segment(body, (0, 0), (0, BOARD_SIZE), BOARD_WALLS_SIZE),
             pymunk.Segment(body, (0, 0), (BOARD_SIZE, 0), BOARD_WALLS_SIZE),
             pymunk.Segment(
                 body, (BOARD_SIZE, BOARD_SIZE), (BOARD_SIZE, 0), BOARD_WALLS_SIZE),
             pymunk.Segment(
                 body, (BOARD_SIZE, BOARD_SIZE), (0, BOARD_SIZE), BOARD_WALLS_SIZE)
             ]
    for wall in walls:
        wall.color = BOARD_WALLS_COLOR
        wall.elasticity = WALLS_ELASTICITY
    space.add(walls)

# Initialize pockets 
开发者ID:samiranrl,项目名称:Carrom_rl,代码行数:17,代码来源:Utils.py

示例9: __init__

# 需要导入模块: import pymunk [as 别名]
# 或者: from pymunk import Segment [as 别名]
def __init__(self):
        # Global-ish.
        self.crashed = False

        # Physics stuff.
        self.space = pymunk.Space()
        self.space.gravity = pymunk.Vec2d(0., 0.)

        # Create the car.
        self.create_car(100, 100, 0.5)

        # Record steps.
        self.num_steps = 0

        # Create walls.
        static = [
            pymunk.Segment(
                self.space.static_body,
                (0, 1), (0, height), 1),
            pymunk.Segment(
                self.space.static_body,
                (1, height), (width, height), 1),
            pymunk.Segment(
                self.space.static_body,
                (width-1, height), (width-1, 1), 1),
            pymunk.Segment(
                self.space.static_body,
                (1, 1), (width, 1), 1)
        ]
        for s in static:
            s.friction = 1.
            s.group = 1
            s.collision_type = 1
            s.color = THECOLORS['red']
        self.space.add(static)

        # Create some obstacles, semi-randomly.
        # We'll create three and they'll move around to prevent over-fitting.
        self.obstacles = []
        self.obstacles.append(self.create_obstacle(200, 350, 100))
        self.obstacles.append(self.create_obstacle(700, 200, 125))
        self.obstacles.append(self.create_obstacle(600, 600, 35))

        # Create a cat.
        self.create_cat() 
开发者ID:llSourcell,项目名称:Self-Driving-Car-Demo,代码行数:47,代码来源:carmunk.py

示例10: __init__

# 需要导入模块: import pymunk [as 别名]
# 或者: from pymunk import Segment [as 别名]
def __init__(self, noisey=False, map_style='default'):
        # Noisey sensors?
        self.noisey = noisey

        # Physics stuff.
        self.space = pymunk.Space()
        self.space.gravity = pymunk.Vec2d(0., 0.)

        # Create the car.
        self.create_car(100, 100, -0.75)
        self.driving_direction = 0

        # Record steps.
        self.num_steps = 0

        # Which map?
        self.map_style = map_style

        # Create outer walls.
        static = [
            pymunk.Segment(
                self.space.static_body,
                (0, 1), (0, height), 1),
            pymunk.Segment(
                self.space.static_body,
                (1, height), (width, height), 1),
            pymunk.Segment(
                self.space.static_body,
                (width-1, height), (width-1, 1), 1),
            pymunk.Segment(
                self.space.static_body,
                (1, 1), (width, 1), 1)
        ]
        for s in static:
            s.friction = 1.
            s.group = 1
            s.collision_type = 1
            s.color = THECOLORS['red']
        self.space.add(static)

        if map_style == 'default':
            self.create_default_map()
            # Create a cat.
            self.create_cat()
        elif map_style == 'linear':
            # Used for testing a trained model mostly.
            self.create_linear_map()

        # Initialize our sensors.
        self.sensor_obj = sensors.Sensors(width, height, screen, pygame, False) 
开发者ID:harvitronix,项目名称:rl-rc-car,代码行数:52,代码来源:carmunk.py


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