本文整理汇总了Python中Vector.set方法的典型用法代码示例。如果您正苦于以下问题:Python Vector.set方法的具体用法?Python Vector.set怎么用?Python Vector.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector
的用法示例。
在下文中一共展示了Vector.set方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import Vector [as 别名]
# 或者: from Vector import set [as 别名]
class Turtle:
"""This class is the turtle that will draw the fractals"""
class State:
"""This class represent a state of the turtle, for push and pop"""
def __init__(self, pos, heading, color):
self.pos = Vector().set(pos)
self.heading = Vector().set(heading)
self.color = Vector().set(color)
def __init__(self, pos=None):
if pos is None:
self.pos = Vector(Conf.TURTLE.INIT_POS)
else:
self.pos = Vector(pos)
self.heading = Vector(Conf.TURTLE.INIT_HEADING)
self.color = Vector(colorsys.rgb_to_hls(Conf.TURTLE.INIT_COLOR[0], Conf.TURTLE.INIT_COLOR[1], Conf.TURTLE.INIT_COLOR[2]))
self.stateStack = [] # allow to manage a stack of states
self.stochasticFactor = 0 # used to randomize drawing
# the vertex buffer is a liste of lists : [[x y z r g b time],...]
self.vertexBuffer = []
self.vertexBufferLength = 0
self.vertexBufferChanged = False
self.vertexPositions = None
#indices = np.array([[0,1,2], [0, 3, 2]], dtype=np.int32)
self.draw_type = GL_TRIANGLES
self.point()
""" allow to change the way the turtle is drawing the fractal """
def setDrawType(self, type):
self.draw_type = type
""" Set the stochastic factor of this instance of the turtle """
def setStochasticFactor(self, factor):
self.stochasticFactor = factor
""" Return a random number in a range around the given number. The range is defined by the stochastoc factor """
def randomize(self, value):
if self.stochasticFactor:
return ((random.random() * 2 * self.stochasticFactor) - self.stochasticFactor) * value + value
return value
""" Reinit the turtle to its initial state """
def reinit(self):
self.pos = Vector(Conf.TURTLE.INIT_POS)
self.heading = Vector(Conf.TURTLE.INIT_HEADING)
self.color = Vector(colorsys.rgb_to_hls(Conf.TURTLE.INIT_COLOR[0], Conf.TURTLE.INIT_COLOR[1], Conf.TURTLE.INIT_COLOR[2]))
self.vertexBuffer = []
self.vertexBufferChanged = False
self.vertexBufferLength = 0
self.vertexPositions = vbo.VBO(np.array(self.vertexBuffer, dtype=np.float32))
self.vertexPositions.bind()
""" Draw a point at the current position of the turtle """
def point(self, breakline = 0):
c = colorsys.hls_to_rgb(self.color.x, self.color.y, self.color.z)
self.vertexBuffer.append([float(self.pos.x), float(self.pos.y), float(self.pos.z),
c[0], c[1], c[2], breakline])
self.vertexBufferChanged = True
self.vertexBufferLength += 1
""" Begin a command list """
def begin(self, reinit = False):
# lorsque 'end()' est appele, si le vertexBuffer a change le vbo sera actualise
self.vertexBufferChanged = False
if reinit:
self.reinit()
glutSolidSphere(0.1, 10, 10)
""" Push current state (pos, heading and color) on the state stack """
def push(self, arg):
if 'turtle' in Conf.DEBUG:
print "Called: push"
self.stateStack.append(Turtle.State(self.pos, self.heading, self.color))
""" Rollback to the last pushed state of the state stack """
def pop(self, arg):
if 'turtle' in Conf.DEBUG:
print "Called: pop"
state = self.stateStack.pop()
self.pos.set(state.pos)
self.heading.set(state.heading)
self.color.set(state.color)
self.point(1)
""" Move forward (draw a point) """
def forward(self, step):
if 'turtle' in Conf.DEBUG:
print "Called: forward(", step, ");"
#print "call: forward"
self.pos += self.randomize(step) * self.heading
self.point()
#.........这里部分代码省略.........
示例2: Drone
# 需要导入模块: import Vector [as 别名]
# 或者: from Vector import set [as 别名]
class Drone():
def __init__(self, dt):
self.dt = dt
self.rotorspeed = Vector(0.0, 0.0)
self.pos = Vector(0,0)
self.speed = Vector(0.0,0.0)
self.acc = Vector(0.0, 0.0)
self.posPrev = Vector(0.0, 0.0)
self.speedPrev = Vector(0.0, 0.0)
self.control = None
def setRotorSpeed(self, value):
if value.coords[0] < -30:
self.rotorspeed.coords[0] = -30
elif value.coords[0] > 30:
self.rotorspeed.coords[0] = 30
else:
self.rotorspeed.coords[0] = value.coords[0]
if value.coords[1] < 0:
self.rotorspeed.coords[1] = 0
elif value.coords[1] > 30:
self.rotorspeed.coords[1] = 30
else:
self.rotorspeed.coords[1] = value.coords[1]
def setControl(self, control):
self.control = control
def refreshPos(self):
newpos = self.calc()
self.posPrev = self.pos
self.pos = newpos
#not here
self.speedPrev = self.speed
self.speed = (self.pos - self.posPrev)/self.dt
self.acc = (self.speed - self.speedPrev) / self.dt
def calc(self):
if self.pos.get() == (0,0) and self.rotorspeed.get() == (0,0):
return self.pos
else:
m = 1.0
g = 10.0
dt = self.dt #???
"""
m*ddx = F
"""
Fall = self.rotorspeed + Vector(0, -m*g)
newpos = Fall * dt**2 / m + self.pos * 2 - self.posPrev
if newpos.coords[1] < 0:
self.speed.set(0,0)
return Vector(newpos.coords[0], 0)
elif newpos.coords[0] < 0:
self.speed.set(0,0)
return Vector(0, newpos.coords[1])
elif newpos.coords[1] > 500:
self.speed.set(0,0)
return Vector(newpos.coords[0], 500)
elif newpos.coords[0] > 1000:
self.speed.set(0,0)
return Vector(1000, newpos.coords[1])
else:
return newpos