當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。