本文整理汇总了Python中turtle.backward函数的典型用法代码示例。如果您正苦于以下问题:Python backward函数的具体用法?Python backward怎么用?Python backward使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了backward函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: turtle_init
def turtle_init():
turtle.ht()
turtle.up()
turtle.speed(0)
turtle.left(90)
turtle.backward(350)
turtle.down()
示例2: basaDon
def basaDon():
turtle.penup()
turtle.backward(200)
turtle.right(90)
turtle.forward(100)
turtle.left(90)
turtle.pendown()
示例3: main
def main():
turtle.left(90)
turtle.up()
turtle.backward(120)
turtle.down()
drawTree(60)
turtle.exitonclick()
示例4: backward
def backward(seconds):
turtle.backward(seconds * 100)
motor_on(LEFT_BACKWARD)
motor_on(RIGHT_BACKWARD)
sleep(seconds)
motor_off(LEFT_BACKWARD)
motor_off(RIGHT_BACKWARD)
示例5: player1_symbol
def player1_symbol(jogada):
if jogada == 1:
go_to(-200,200,45)
elif jogada==2:
go_to(0,200,45)
elif jogada==3:
go_to(200,200,45)
elif jogada==4:
go_to(-200,0,45)
elif jogada==5:
go_to(0,0,45)
elif jogada==6:
go_to(200,0,45)
elif jogada==7:
go_to(-200,-200,45)
elif jogada==8:
go_to(0,-200,45)
elif jogada==9:
go_to(200,-200,45)
turtle.pencolor('green')
for i in range(4):
turtle.forward(75)
turtle.backward(75)
turtle.right(90)
示例6: drawTree
def drawTree(tree, angle, length, width):
turtle.width(width)
if tree[0] == "ancestor":
# left branch
turtle.left(angle)
turtle.forward(length)
turtle.right(angle)
drawTree(tree[1], angle - 0.2 * angle, length - 0.2 * length, width - 0.3 * width)
turtle.width(width)
turtle.left(angle)
turtle.backward(length)
turtle.right(angle)
# right branch
turtle.right(angle)
turtle.forward(length)
turtle.left(angle)
drawTree(tree[2], angle - 0.2 * angle, length - 0.2 * length, width - 0.3 * width)
turtle.width(width)
turtle.right(angle)
turtle.backward(length)
turtle.left(angle)
else:
# draw the ending node
turtle.pencolor("red")
turtle.write(tree[0], font=("Monospace", 14, "bold"))
turtle.pencolor("black")
示例7: pezzo
def pezzo(color, colors = colors, unit = unit, alfa = alfa, depth = depth):
turtle.pencolor(colors[color])
turtle.fillcolor(color)
turtle.begin_fill()
for i in range(2):
turtle.forward(unit)
turtle.left(90)
turtle.forward(unit)
turtle.left(90)
turtle.forward(unit)
for i in range(2):
turtle.left(alfa)
turtle.forward(depth)
turtle.left(alfa)
turtle.forward(unit)
turtle.left(90)
turtle.backward(unit)
turtle.left(90)
turtle.forward(unit)
turtle.right(90)
for i in range(2):
turtle.forward(unit)
turtle.left(alfa)
turtle.forward(depth)
turtle.left(180-alfa)
turtle.end_fill()
turtle.right(90)
turtle.forward(unit)
turtle.left(90)
示例8: pythagoras_tree
def pythagoras_tree(size, n):
turtle.begin_fill()
for _ in range(4):
turtle.forward(size)
turtle.left(90)
turtle.end_fill()
if n > 0:
roof = .5 * math.sqrt(2) * size
turtle.left(90)
turtle.forward(size)
turtle.right(45)
pythagoras_tree(roof, n - 1)
turtle.forward(roof)
turtle.right(90)
pythagoras_tree(roof, n - 1)
turtle.left(90)
turtle.backward(roof)
turtle.left(45)
turtle.backward(size)
turtle.right(90)
示例9: tscm_backward
def tscm_backward(n):
"""Move the turtle backward a distance N units on the current heading,
without changing direction."""
_check_nums(n)
_tscm_prep()
turtle.backward(n.num_val)
return UNSPEC
示例10: render
def render(tree, length, width):
"Draws a given phylogenetic tree constrained by dimensions of"
"length and width."
root = tree[0]
leftTree = tree[1]
rightTree = tree[2]
if leftTree == ():
turtle.dot(10)
turtle.write(root , font=("Arial", 20, "normal"))
return
else:
turtle.dot(10)
turtle.write(root, font=("Arial", 20, "normal"))
turtle.left(90)
turtle.forward(width)
turtle.right(90)
turtle.forward(length)
render(leftTree, 0.5*length, 0.5*width)
turtle.back(length)
turtle.left(90)
turtle.backward(2*width)
turtle.right(90)
turtle.forward(length)
render(rightTree, 0.5*length, 0.5*width)
turtle.back(length)
turtle.right(90)
turtle.back(width)
turtle.left(90)
return
示例11: draw_tree
def draw_tree(depth, height, branches, leafs, angle):
"""
Draws the tree using recursion
:pre: pos(0,0), heading east, up
:post: pos(0,0), heading east, up
:param depth: number of layers of sub branches (recursion depth)
:param height: height of tree
:param branches: number of branches
:param leafs: number of leafs
:param angle: angle between branches
:return: None
"""
if depth == 0:
leafs = random.randint(0, leafs)
draw_leaf(leafs)
t.down()
pass
else:
t.color('brown')
t.forward(height)
for i in range(1, branches+1):
t.left(90 - i * angle)
#random branches
branches = random.randint(branches-1,branches+5)
draw_tree(depth - 1, height * HEIGHT_FACTOR, branches, leafs, angle)
t.right(90 - i * angle)
#random angle
angle = random.randint(angle-1, angle+1)
if depth == 1:
break
t.color('brown')
t.backward(height)
示例12: draw_tree
def draw_tree(length=200):
"""
A recursive function that uses the turtle external library to
draw a binary tree in the size of the user input (or default: 200).
The flow of the function that it first draw a straight line,
the right side branches and then left side branches.
"""
# length is number of pixel
deg = 30 # degrees of each branch (left, right)
if not length < 10:
# Base is when the length is lower then 10,
# otherwise, continue with the iteration.
turtle.forward(length) # Draw straight line forward size length
turtle.right(deg) # Turn right 30 degrees
draw_tree(length*0.6) # Call the recursion to draw the right
# side branches
turtle.left(deg*2) # Then turn left (30 degrees center,
# 30 degrees more to the left)
draw_tree(length*0.6) # Draw inner left side branches
turtle.right(deg) # Turn to center
turtle.backward(length) # Go backwards length size
示例13: 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()
示例14: house
def house(length):
"""
Draw a nice house where the base is length long and put the turtle
back to its original position at the end.
"""
inside = SQRT2 * length
roof = inside / 2.
turtle.forward(length)
turtle.left(90)
turtle.forward(length)
# roof
turtle.left(45)
turtle.forward(roof)
turtle.left(90)
turtle.forward(roof)
turtle.left(45)
# interior
turtle.forward(length)
turtle.left(135)
turtle.forward(inside)
turtle.left(135)
turtle.forward(length)
turtle.left(135)
turtle.forward(inside)
# back into position
turtle.left(45)
turtle.backward(length)
示例15: plot_a_face
def plot_a_face(angle, pencolor, fillcolors, dimension):
t.down()
def plot_a_row(angle, pencolor, fillcolors,dimension):
for i in range(len(fillcolors)):
t.color(pencolor, fillcolors[i])
t.begin_fill()
t.forward(50*3/dimension)
t.right(angle)
t.forward(50*3/dimension)
t.right(180 - angle)
t.forward(50*3/dimension)
t.right(angle)
t.forward(50*3/dimension)
t.right(180 - angle)
t.end_fill()
t.forward(50*3/dimension)
n = int(len(fillcolors)/dimension)
for i in range(n):
plot_a_row(angle,pencolor,fillcolors[dimension*i:dimension*(i+1)],dimension)
t.up()
t.backward(150)
t.right(angle)
t.forward(50*3/dimension)
t.left(angle)
t.down()