本文整理汇总了Python中turtle.heading函数的典型用法代码示例。如果您正苦于以下问题:Python heading函数的具体用法?Python heading怎么用?Python heading使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了heading函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: draw_state
def draw_state(self):
"""
the core of the class
Interprete character:
F: move forward
+: turn right
-: turn left
[: push (position, heading)
]: pop (position, heading)
"""
import turtle
state = self.lsystem().state()
for c in state:
if c == 'F':
turtle.forward(self.length)
if c == '+':
turtle.right(self.angle)
if c == '-':
turtle.left(self.angle)
if c == '[':
self.stack.append((turtle.position(), turtle.heading()))
if c == ']':
if len(self.stack) == 0:
raise ValueError('inconsistant state: using to much `]`')
pos, head = self.stack.pop()
turtle.penup()
turtle.setpos(pos)
turtle.setheading(head)
turtle.pendown()
return self
示例2: von_koch
def von_koch(l, n):
t.forward(l)
von_koch(l / 3, n - 1)
t.setheading(t.heading() + 60)
von_koch(l / 3, n - 1)
t.setheading(t.heading() - 120)
von_koch(l / 3, n - 1)
t.setheading(t.heading() + 60)
示例3: main
def main():
turtle.color('red')
turtle.heading()
turtle.left(80)
turtle.speed(5)
turtle.pendown()
turtle.fill(True)
turtle.circle(30,90)
示例4: randomDirection
def randomDirection():
if remainingX > 0 and remainingY > 0:
if turtle.xcor() < 0 and forwardX > backwardX:
randomInt = random.randrange(0,3)
else:
randomInt = random.randrange(0,2)
if randomInt == 0:
return NORTH
elif randomInt == 1 and turtle.heading() != WEST:
return EAST
elif randomInt == 2 and turtle.heading() != EAST:
return WEST
示例5: draw
def draw(cmds, size=2): #output tree
stack = []
for cmd in cmds:
if cmd=='F':
turtle.forward(size)
elif cmd=='-':
t = random.randrange(0,7,1)
p = ["Red","Green","Blue","Grey","Yellow","Pink","Brown"]
turtle.color(p[t])
turtle.left(15) #slope left
elif cmd=='+':
turtle.right(15) #slope right
t = random.randrange(0,7,1) #рандомная пер. для цвета
p = ["Red","Green","Blue","Grey","Yellow","Pink","Brown"] #ряд цветов
turtle.color(p[t]) #выбор цвета из ряда
elif cmd=='X':
pass
elif cmd=='[':
stack.append((turtle.position(), turtle.heading()))
elif cmd==']':
position, heading = stack.pop()
turtle.penup()
turtle.setposition(position)
turtle.setheading(heading)
turtle.pendown()
turtle.update()
示例6: makeSquare
def makeSquare(size, person=None, fill=False):
origPosition = turtle.pos()
origHead = turtle.heading()
turtle.penup()
goDown(size)
if(person != None or fill == True):
if(fill==True or person.affected):
turtle.begin_fill()
turtle.pendown()
goLeft(size)
goUp(2*size)
goRight(2*size)
goDown(2*size)
goLeft(size)
if(person != None or fill==True):
if(fill==True or person.affected):
turtle.end_fill()
turtle.penup()
turtle.goto(origPosition)
turtle.setheading(origHead)
if(person != None or fill==True):
if(fill==True or person.affected):
turtle.color('black')
if(person.multipleNotShown == 0):
turtle.write(str(person.name())+"\n"+probString(person), align="center")
else:
turtle.write(str(person.name())+"\n"+probString(person)+"\n\n"+str(person.multipleNotShown), align="center")
turtle.color('blue')
turtle.penup()
示例7: makeDiamond
def makeDiamond(size, person=None, fill=False):
origPosition = turtle.pos()
origHead = turtle.heading()
turtle.penup()
goDown(size)
turtle.pendown()
if(person != None or fill==True):
if(fill==True or person.affected):
turtle.begin_fill()
goNorthEast(2*size/np.sqrt(2))
goNorthWest(2*size/np.sqrt(2))
goSouthWest(2*size/np.sqrt(2))
goSouthEast(2*size/np.sqrt(2))
if(person != None or fill==True):
if(fill==True or person.affected):
turtle.end_fill()
turtle.penup()
turtle.goto(origPosition)
turtle.setheading(origHead)
if(person != None or fill==True):
if(fill==True or person.affected):
turtle.color('black')
if(person.multipleNotShown == 0):
turtle.write(str(person.name())+"\n"+probString(person), align="center")
else:
turtle.write(str(person.name())+"\n"+probString(person)+"\n\n"+str(person.multipleNotShown), align="center")
turtle.color('blue')
turtle.penup()
示例8: verificarPos
def verificarPos(self):
"""
Desc: Método para verificar se a posição e sentido da tartaruga é igual ao inicial
Use getPos() para pegar o inicial
Printa: String = Erro
Retorna: Boolean = True (caso esteja ok) ou False (caso não)
Exemplo:
cb.getPos()
cb.casa(25, 50, 30)
cb.verificarPos()
"""
self._retorno = True
if (round(turtle.xcor()) != self.turtlePosX) or (round(turtle.ycor()) != self.turtlePosY):
print("A posição atual da tartaruga difere da inicial ({0}, {1})\nEla está em: ({2}, {3})".format(str(self.turtlePosX),
str(self.turtlePosY),
str(round(turtle.xcor())),
str(round(turtle.ycor()))))
self._retorno = False
if turtle.heading() != self.turtleDir:
print("A direção atual da tartaruga difere da inicial (" + str(self.turtleDir) + ")\nEla está em:", str(turtle.heading()))
self._retorno = False
return self._retorno
示例9: makeTree
def makeTree(h, l, b, d, ad):
Base(b)
turtle.color("brown")
if h > 0:
if h == 1:
turtle.color("green")
if h== 4:
Apple(b)
if d == 0:
makeTree(h-1 , l*.75, drawLimb(l, d*ad), d+1,ad)
else:
y = turtle.heading()
makeTree(h-1 , l*.75, drawLimb(l*.75, d*ad/2.00), d,ad)
Base(b)
d = d*-1
turtle.setheading(y)
makeTree(h-1 , l*.75, drawLimb(l*.75, d*ad/2.00), d,ad)
else:
Base(b)
示例10: main
def main():
#设置一个画面
windows = turtle.Screen()
#设置背景
windows.bgcolor('black')
#生成一个黄色乌龟
bran = turtle.Turtle()
bran.shape('turtle')
bran.color('white')
turtle.home()
turtle.dot()
turtle.fd(50); turtle.dot(20, "blue"); turtle.fd(50)
turtle.position()
(100.00,-0.00)
turtle.heading()
示例11: draw_arrow
def draw_arrow():
'''Draw an arrow toward the turtle's current heading, then return to
position and heading.'''
arrow_length = 7 # pixels
arrow_width = 10 # pixels
arrow_end = tt.position()
old_heading = tt.heading()
# move to back end of upper line
tt.penup()
tt.backward(arrow_length)
tt.left(90)
tt.forward(arrow_width)
# draw upper line
tt.pendown()
tt.setposition(arrow_end)
tt.setheading(old_heading)
# move to back end of lower line
tt.penup()
tt.backward(arrow_length)
tt.right(90)
tt.forward(arrow_width)
# draw lower line
tt.pendown()
tt.setposition(arrow_end)
tt.setheading(old_heading)
tt.penup()
示例12: drawString
def drawString( dstring, distance, angle ):
""" Interpret the characters in string dstring as a series
of turtle commands. Distance specifies the distance
to travel for each forward command. Angle specifies the
angle (in degrees) for each right or left command. The list of
turtle supported turtle commands is:
F : forward
- : turn right
+ : turn left
[ : save position, heading
] : restore position, heading
"""
stack = []
for c in dstring:
if c == 'F':
turtle.forward(distance)
elif c == '-':
turtle.right(angle)
elif c == '+':
turtle.left(angle)
elif c == '[':
stack.append(turtle.position())
stack.append(turtle.heading())
elif c == ']':
turtle.up()
turtle.setheading(stack.pop())
turtle.goto(stack.pop())
turtle.down()
turtle.update()
示例13: draw_l
def draw_l(word):
turtle.up()
turtle.clear()
turtle.setposition(0, 0)
turtle.setheading(0)
turtle.bk(INITIAL_POS[0])
turtle.down()
turtle.st()
stack = []
for char in word:
if char == '0':
turtle.fd(SIZE[0])
if char == '1':
turtle.fd(SIZE[0])
if char == '[':
stack.append((turtle.position(), turtle.heading()))
turtle.lt(45)
if char == ']':
position, heading = stack.pop()
turtle.up()
turtle.setposition(position)
turtle.setheading(heading)
turtle.rt(45)
turtle.down()
turtle.ht()
示例14: moveDir
def moveDir(turtle, direction):
if turtle.heading() != direction:
turtle.setheading(direction)
turtle.forward(MOVING_DISTANCE)
global remainingY
newY = remainingY - 1
remainingY = newY
示例15: drawDome
def drawDome(size, degrees):
turtle.setheading(90)
turtle.fillcolor("red")
turtle.begin_fill()
drawSemi(size, "right", degrees, colour="black" )
turtle.setheading(turtle.heading()+degrees+degrees-180)
drawSemi(size, "right", degrees, colour="black")
turtle.end_fill()