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


Python Vector.limit方法代码示例

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


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

示例1: Chunk

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import limit [as 别名]
class Chunk(visualizer.Chunk):
    def update(self):
        self.force = Vector(0,0)
        self.attract_to_neighbours()
        self.force.limit(0.5)
        self.repel_from_boundaries()
        self.position += self.force

    def repel_from_boundaries(self):
        if self.position.x < self.visualizer.inner_margin:
            self.force += Vector(1,0)
        if self.position.x > (self.visualizer.width - self.visualizer.inner_margin):
            self.force += Vector(-1,0)
        if self.position.y < self.visualizer.inner_margin:
            self.force += Vector(1,0)
        if self.position.y > (self.visualizer.height - self.visualizer.inner_margin):
            self.force += Vector(-1,0)

    def attract_to_neighbours(self):
        for other in self.file.arriving_chunks.values():
            if other != self:
                desired_distance = abs(self.begin - other.begin) * 0.01
                self.force += spring_force(self.position, other.position, desired_distance)
开发者ID:alex-berman,项目名称:tforms,代码行数:25,代码来源:particles.py

示例2: __init__

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import limit [as 别名]
class Vehicle:
    def __init__(self,n,x,y):
        brain = Perceptron(n,0.001)
        self.location = Vector([x,y])
        self.velocity = Vector([0,0])
        self.acceleration = Vector([0,0])
        self.maxforce = 0.1
        self.maxspeed = 4
    
    def update():
        self.velocity.add(self.acceleration)
        self.velocity.limit(self.maxspeed)
        self.location.add(self.velocity)
        self.acceleration.mult(0)

    def applyForce(self, force):
        acceleration.add(force)
        
    #expects an array
    def steer(self, targets):
        if isinstance(targets,Vector):
            forces = 
        elif isinstance(targets,[]):
            targets = Vector(targets)
开发者ID:EricSchles,项目名称:neuralnet,代码行数:26,代码来源:second.py

示例3: __init__

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import limit [as 别名]
class Physics:

	DEFAULT_MAX_SPEED = 10
	DEFAULT_WEIGHT = 1.03
	DEFAULT_FLOOR_IT_SPEED = 0.9

	ORIGINAL_MAX_SPEED = None
	maxSpeed = None
	ORIGINAL_WEIGHT = None
	weight = None
	ORIGINAL_FLOOR_IT_SPEED = None
	floorItSpeed = None

	ORIGINAL_LOCATION = None
	location = None
	ORIGINAL_VELOCITY = None
	velocity = None
	ORIGINAL_ACCELERATION = None
	acceleration = None

	def __init__(self, x, y):
		self.ORIGINAL_LOCATION = Vector(x, y)
		self.location = Vector(x, y)
		self.ORIGINAL_VELOCITY = Vector(0, 0)
		self.velocity = Vector(0, 0)
		self.ORIGINAL_ACCELERATION = Vector(0, 0)
		self.acceleration = Vector(0, 0)

		self.ORIGINAL_MAX_SPEED = Vector(self.DEFAULT_MAX_SPEED, self.DEFAULT_MAX_SPEED)
		self.maxSpeed = Vector(self.DEFAULT_MAX_SPEED, self.DEFAULT_MAX_SPEED)
		self.ORIGINAL_WEIGHT = Vector(self.DEFAULT_WEIGHT, self.DEFAULT_WEIGHT)
		self.weight = Vector(self.DEFAULT_WEIGHT, self.DEFAULT_WEIGHT)
		self.ORIGINAL_FLOOR_IT_SPEED = Vector(self.DEFAULT_FLOOR_IT_SPEED, self.DEFAULT_FLOOR_IT_SPEED)
		self.floorItSpeed = Vector(self.DEFAULT_FLOOR_IT_SPEED, self.DEFAULT_FLOOR_IT_SPEED)

	def scale(self, horizontalScale, verticalScale):
		self.location.scaleWithRespectTo(self.ORIGINAL_LOCATION, horizontalScale, verticalScale)
		self.velocity.scaleWithRespectTo(self.ORIGINAL_VELOCITY, horizontalScale, verticalScale)
		self.acceleration.scaleWithRespectTo(self.ORIGINAL_ACCELERATION, horizontalScale, verticalScale)

		self.maxSpeed.scaleWithRespectTo(self.ORIGINAL_MAX_SPEED, horizontalScale, verticalScale)
		"""
		Scaling physics SEEMS to work correctly the minute we stop scaling the
		weight as well. I'm sure the concept of why this makes sense is super
		simple but it alludes me at the moment. No matter, it seems to work,
		so I'll leave it be for now and check back later when I have other
		things to check besides just the ship...
		"""
		self.weight.scaleWithRespectTo(self.ORIGINAL_WEIGHT, horizontalScale, verticalScale)
		self.floorItSpeed.scaleWithRespectTo(self.ORIGINAL_FLOOR_IT_SPEED, horizontalScale, verticalScale)

	def updateForNewLocation(self, newLocationBasedOnActions):
		direction = vector.subtract(newLocationBasedOnActions, self.location)
		direction.normalize()

		direction.multiply(self.floorItSpeed)
		self.acceleration = direction;

		self.velocity.add(self.acceleration)
		self.velocity.limit(self.maxSpeed);
		self.velocity.stopIfSlowEnough();
		self.velocity.divideByVector(vector=self.weight)
		self.location.add(self.velocity)
开发者ID:Barrowclift,项目名称:Game-Physics-Test,代码行数:65,代码来源:physics.py


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