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


Python Util.clamp方法代码示例

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


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

示例1: addFood

# 需要导入模块: from util import Util [as 别名]
# 或者: from util.Util import clamp [as 别名]
	def addFood(self, x, y=None, num = 1):

		# If no y was given then use the standard food distance above the tank
		if(y is None):
			y = self.height - self.foodDistance
		else:
			y = Util.clamp(self.tank.box.bottom, y, self.height)

		# Make sure the food will go in the tank
		x = Util.clamp(self.tank.box.left, x, self.tank.box.right)

		# Add the foods
		for _ in range(num):
			newFood = Food(world=self)
			newFood.pos = Vector2D(x, y)
			self.food.append(newFood)
开发者ID:geordiemhall,项目名称:fishy,代码行数:18,代码来源:world.py

示例2: swayShape

# 需要导入模块: from util import Util [as 别名]
# 或者: from util.Util import clamp [as 别名]
	def swayShape(self):

		# TODO: Optimise this somehow. 
		# At the very least cache it so that both sway functions can use it without recalculating
		sqrtSpeed = self.speedSqrt

		# Speed up fins as we slow down, illusion of swimming harder
		frequency = sqrtSpeed * 0.4
		
		# The bigger the fish, the slower it should paddle
		# frequency /= (1 + self.body * 0.25)

		# if(self.chosenOne):	print 'spedFreq', frequency
		frequency = Util.clamp(2, frequency, 3)
		# if(self.chosenOne):	print 'clampedFreq', frequency

		# print 'sqrtSpeed', self.speedSqrt(), 'freq', frequency

		swayAngle = sin(self.world._clock * frequency)
		# print 'frequency', frequency

		swayRange = sqrtSpeed / 80
		# print 'swayRange', swayRange

		matrix = Matrix33()
		matrix.scale_update(1 + (swayAngle * 0.2 * sqrt(swayRange)), 1)
		# self.matrix.rotate_update(swayAngle * swayRange)

		shape = deepcopy(self.fishShape)
		matrix.transform_vector2d_list(shape)
		
		return shape
开发者ID:geordiemhall,项目名称:fishy,代码行数:34,代码来源:guppy.py

示例3: colorForSickness

# 需要导入模块: from util import Util [as 别名]
# 或者: from util.Util import clamp [as 别名]
	def colorForSickness(self, sickness, colorScale):
		# Make sure it's within range
		sick = Util.clamp(self._sicknessDomain[0], sickness, self._sicknessDomain[1])
		
		# Interpolate colors
		c = colorScale
		return (c['r'](sick), c['g'](sick), c['b'](sick), c['a'](sick))
开发者ID:geordiemhall,项目名称:fishy,代码行数:9,代码来源:guppy.py

示例4: statForSize

# 需要导入模块: from util import Util [as 别名]
# 或者: from util.Util import clamp [as 别名]
	def statForSize(self, key, size):

		sizeRange = self._sizes 	# domain
		statRange = self._stats[key]	# range

		scale = Util.linearScale(sizeRange, statRange)

		clampedSize = Util.clamp(sizeRange[0], size, sizeRange[1])

		return scale(clampedSize)
开发者ID:geordiemhall,项目名称:fishy,代码行数:12,代码来源:guppy.py

示例5: sickness

# 需要导入模块: from util import Util [as 别名]
# 或者: from util.Util import clamp [as 别名]
	def sickness(self, value):
		self._sickness = Util.clamp(self._sicknessDomain[0], value, self._sicknessDomain[1])


		# If we are too sick, then we're dead (for now!)
		if(self._sickness > self._sicknessDomain[1] - 1):
			self.dead = True
			
		# Sickness has changed, so recalculate our color
		self.recalculateColor()
开发者ID:geordiemhall,项目名称:fishy,代码行数:12,代码来源:guppy.py

示例6: swayPosition

# 需要导入模块: from util import Util [as 别名]
# 或者: from util.Util import clamp [as 别名]
	def swayPosition(self):

		sqrtSpeed = self.speedSqrt
		# frequency = sqrtSpeed * 0.4
		frequency = 0.1 * sqrtSpeed
		swayRange = 0.5 * self.size


		frequency = Util.clamp(0, frequency, 0.5)


		offsetAngle = cos((self.world._clock) * frequency / 2)
		offset = self.side * swayRange * offsetAngle
		position = self.pos + offset
		
		return position
开发者ID:geordiemhall,项目名称:fishy,代码行数:18,代码来源:guppy.py

示例7: swayShape

# 需要导入模块: from util import Util [as 别名]
# 或者: from util.Util import clamp [as 别名]
	def swayShape(self):

		# TODO: Optimise this more 
		sqrtSpeed = self.speedSqrt

		# Speed up fins as we slow down, gives the illusion of swimming harder
		frequency = sqrtSpeed * 0.4

		frequency = Util.clamp(2, frequency, 2.5)
		swayAngle = sin(self.world._clock * frequency)
		swayRange = sqrtSpeed / 80

		matrix = Matrix33()
		matrix.scale_update(1 + (swayAngle * 0.2 * sqrt(swayRange)), 1)

		shape = deepcopy(self.fishShape)
		matrix.transform_vector2d_list(shape)
		
		return shape
开发者ID:geordiemhall,项目名称:fishy,代码行数:21,代码来源:hunter.py

示例8: size

# 需要导入模块: from util import Util [as 别名]
# 或者: from util.Util import clamp [as 别名]
	def size(self, value):
		self._size = Util.clamp(self._sizes[0], value, self._sizes[1])
		self.updateStats()
开发者ID:geordiemhall,项目名称:fishy,代码行数:5,代码来源:guppy.py


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