本文整理汇总了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)
示例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)
示例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)