本文整理汇总了Python中turtle.heading函数的典型用法代码示例。如果您正苦于以下问题:Python heading函数的具体用法?Python heading怎么用?Python heading使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了heading函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:masterzu,项目名称:pylsys,代码行数:33,代码来源:pylsys.py
示例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)
开发者ID:Rems19,项目名称:Python,代码行数:8,代码来源:Labergère_TP42.py
示例3: main
def main():
turtle.color('red')
turtle.heading()
turtle.left(80)
turtle.speed(5)
turtle.pendown()
turtle.fill(True)
turtle.circle(30,90)
开发者ID:ALEX99XY,项目名称:uband-python-s1,代码行数:9,代码来源:day_17.py
示例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
开发者ID:lekamj,项目名称:turtlePath,代码行数:13,代码来源:pathCreator.py
示例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()
开发者ID:Papapashu,项目名称:main,代码行数:26,代码来源:python_three.py
示例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()
开发者ID:EddieCunningham,项目名称:PedigreeDataCollection,代码行数:29,代码来源:pedigreeDraw.py
示例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()
开发者ID:EddieCunningham,项目名称:PedigreeDataCollection,代码行数:28,代码来源:pedigreeDraw.py
示例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
开发者ID:SrMouraSilva,项目名称:Academic-Projects,代码行数:27,代码来源:cb.py
示例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)
开发者ID:Drellimal2,项目名称:ascii-old-board-games,代码行数:28,代码来源:TurtleTreewithsign+(1).py
示例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()
开发者ID:ALEX99XY,项目名称:uband-python-s1,代码行数:16,代码来源:B20826-day17-homework.py
示例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()
开发者ID:xerebus,项目名称:nedm,代码行数:28,代码来源:fieldpic.py
示例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()
开发者ID:akaralekas,项目名称:cs151-colby,代码行数:29,代码来源:turtle_interpreter.py
示例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()
开发者ID:RichardBarrell,项目名称:snippets,代码行数:25,代码来源:draw_l.py
示例14: moveDir
def moveDir(turtle, direction):
if turtle.heading() != direction:
turtle.setheading(direction)
turtle.forward(MOVING_DISTANCE)
global remainingY
newY = remainingY - 1
remainingY = newY
开发者ID:lekamj,项目名称:turtlePath,代码行数:8,代码来源:pathCreator.py
示例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()
开发者ID:rckc,项目名称:CoderDojoUWA2016,代码行数:8,代码来源:Peter+-+Space+Rocket.py
示例16: drawFlame
def drawFlame(size, degrees, fillcolor="yellow"):
turtle.fillcolor(fillcolor)
turtle.begin_fill()
turtle.setheading(270)
drawSemi(size, "right", degrees, "black")
turtle.setheading(turtle.heading()+degrees+degrees-180)
drawSemi(size, "right", degrees, "black")
turtle.end_fill()
开发者ID:rckc,项目名称:CoderDojoUWA2016,代码行数:8,代码来源:Peter+-+Space+Rocket.py
示例17: creation_triangle
def creation_triangle(self):
#choix de taille du triangle
self.chx = random.randint(10, 100)
tt.begin_fill()
for _ in range(3):
tt.forward(self.chx)
tt.left(120)
tt.end_fill()
print("debug", tt.heading())
开发者ID:mseyne,项目名称:curriculum,代码行数:9,代码来源:7_1_ex.py
示例18: triforceFlower
def triforceFlower(turtle, center, heading, length, color):
#draws a flower made up of triforces rotated around a point
turtle.penup()
turtle.goto(center)
turtle.pendown()
turtle.setheading(heading)
turtle.color(color)
for k in range(20):
triforce(turtle, turtle.position(), turtle.heading(), length, turtle.color()[0], turtle.pensize())
turtle.left(120)
turtle.right(18)
开发者ID:jyu197,项目名称:comp_sci_101,代码行数:11,代码来源:TurtlePicture.py
示例19: e_branch
def e_branch(self):
global length
global NewNodeQue
turtle.up()
turtle.setpos(self.NodePosition)
turtle.down()
turtle.setheading(self.GrowAngle)
d = Node('d',self.NodePosition,self.GrowAngle)
dNodeQue.put(d)
turtle.left(angle)
turtle.forward(length)
a = Node('a',turtle.pos(),turtle.heading())
NewNodeQue.put(a)
turtle.up()
turtle.setpos(d.NodePosition)
turtle.down()
turtle.setheading(d.GrowAngle)
turtle.forward(length)
b = Node('b',turtle.pos(),turtle.heading())
NewNodeQue.put(b)
开发者ID:YLili,项目名称:Fractal-growing-tree,代码行数:20,代码来源:FractalTree.py
示例20: sign
def sign():
turtle.color("chocolate")
turtle.width(5)
Base((-250,-200))
turtle.setheading(0)
turtle.fd(100)
Tip = turtle.pos()
turtle.fill(True)
for x in range (1,5):
turtle.setheading(turtle.heading() + 90)
if x % 2 != 0:
turtle.fd(150)
else:
turtle.fd(75)
if turtle.heading() == 180:
turtle.fd(25)
turtle.bk(25)
turtle.fillcolor('chocolate')
turtle.fill(False)
def writing():
turtle.width(1)
turtle.color("white")
Base((-250,-100))
turtle.setheading(162)
turtle.pu()
turtle.fd(28)
turtle.setheading(180)
turtle.fd(10)
turtle.write("Raphaella and Danes' ", font=("Calibri", 12, "italic"))
turtle.fd(14)
turtle.pd()
turtle.write(" Apple Tree",font = ("Calibri",12,"bold"))
writing()
turtle.setheading(0)
开发者ID:Drellimal2,项目名称:ascii-old-board-games,代码行数:41,代码来源:TurtleTreewithsign+(1).py
注:本文中的turtle.heading函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论