本文整理汇总了Python中turtle.forward函数的典型用法代码示例。如果您正苦于以下问题:Python forward函数的具体用法?Python forward怎么用?Python forward使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了forward函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: y_tree
def y_tree(length = 200):
"""
This function receives a length and draws a tree according to the length
in an angle 60 between the branches always reducing the next length by
0.6. The drawing ends when the length is smaller than 10
:param length: The length of the branch to draw, default 200
:return: None
"""
ANGLE_BETWEEN_BRANCHES = 60
LENGTH_REDUCTION = 0.6
MIN_LENGTH = 10
if length <= MIN_LENGTH:
return
else:
turtle.forward(length) # draws the branch
turtle.left(ANGLE_BETWEEN_BRANCHES / 2)
y_tree(LENGTH_REDUCTION * length) # draws the left branch
turtle.right(ANGLE_BETWEEN_BRANCHES)
y_tree(LENGTH_REDUCTION * length) # draws the right branch
turtle.left(ANGLE_BETWEEN_BRANCHES / 2)
turtle.backward(length) # returns back to draw next
示例2: star
def star(points, length): # Defines a function polygon with respect to the number of points on the star and its length.
for i in range(points): # For loop used to draw the star using the users input for length.
turtle.right(180 / points)
turtle.forward(length)
turtle.left((90 / points) + 90)
turtle.forward(length)
示例3: initBannerCanvas
def initBannerCanvas( numChars , numLines, scale ):
"""
Set up the drawing canvas to draw a banner numChars wide and numLines high.
The coordinate system used assumes all characters are 20x20 and there
are 10-point spaces between them.
Precondition: The initial canvas is default size, then input by the first
two user inputs, every input after that defines each letter's scale, probably between
1 and 3 for the scale values to have the window visible on the screen.
Postcondition: The turtle's starting position is at the bottom left
corner of where the first character should be displayed, the letters are printed.
"""
scale = int(input("scale, integer please"))
# This setup function uses pixels for dimensions.
# It creates the visible size of the canvas.
canvas_height = 80 * numLines *scale
canvas_width = 80 * numChars *scale
turtle.setup( canvas_width *scale, canvas_height *scale)
# This setup function establishes the coordinate system the
# program perceives. It is set to match the planned number
# of characters.
height = 30 *scale
width = 30 * numChars *scale
margin = 5 # Add a bit to remove the problem with window decorations.
turtle.setworldcoordinates(
-margin+1 * scale, -margin+1 * scale, width + margin* scale, numLines*height + margin * scale)
turtle.reset()
turtle.up()
turtle.setheading( 90 )
turtle.forward( ( numLines - 1 ) * 30 )
turtle.right( 90 )
turtle.pensize( 1 *scale)
示例4: draw_fractal4
def draw_fractal4(turtle, size):
for i in range(1,5):
for i in range(1,3):
draw_fractal3(turtle, size)
turtle.forward(size * 27)
turtle.forward(size * 27)
turtle.right(90)
示例5: entrance
def entrance(pointOne):
turtle.goto(pointOne[0], pointOne[1] + 36)
turtle.setheading(270)
turtle.pendown()
turtle.forward(15)
turtle.penup()
drawArrows()
示例6: draw
def draw(self):
for i in range(0,2):
turtle.forward(self.length)
turtle.left(90)
turtle.forward(self.width)
turtle.left(90)
turtle.done()
示例7: at
def at(x, y):
turtle.penup()
turtle.home()
turtle.forward(x)
turtle.left(90)
turtle.forward(y)
turtle.pendown()
示例8: Minkovskiy
def Minkovskiy(l, n):
if n == 0:
turtle.forward(l)
else:
for angle in [90, -90, -90, 0, 90, 90, -90, 0]:
Minkovskiy(l/4, n-1)
turtle.left(angle)
示例9: circle
def circle(r, n, angle):
turtle.seth(angle)
a = 2*r*sin(pi/n)
phi = 180*(1-2/n)
for i in range(int(n/2)+1):
turtle.forward(a)
turtle.right(180-phi)
示例10: draw_leaf
def draw_leaf(no_of_leafs):
"""
Draws leafs at the end of branch. Min 0 and max = no_of_leafs
:pre: pos(0,0), heading east, up
:post: pos(0,0), heading east, up
:param no_of_leafs: maximum number of leads drawn
:return: None
"""
for i in range(no_of_leafs):
# draws random poylgon from triangle to hexagon
sides = random.randint(3, 6)
color = random.choice(COLORS)
size = 10
angle = 360/sides
t.left(90 - i * angle)
t.right(90)
t.begin_fill()
t.down()
t.color(color)
for _ in range(sides):
t.forward(size)
t.left(angle)
t.left(90)
t.up()
t.end_fill()
t.right(90 - i * angle)
global LEAF_COUNTER
LEAF_COUNTER += 1
示例11: draw_square_and_circle
def draw_square_and_circle():
window = turtle.Screen()
window.bgcolor("red")
count = 0
while count < 4:
turtle.position()
turtle.forward(100)
turtle.right(90)
count = count + 1
angie = turtle.Turtle()
angie.shape("arrow")
angie.color("blue")
angie.circle(100)
todd = turtle.Turtle()
todd.shape("arrow")
todd.color("green")
todd_count = 0
whilte todd_count < 3:
todd.forward(300)
todd.left(120)
todd_count = todd_count + 1
示例12: 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)
示例13: robber_move
def robber_move(turtle):
fifty_fifty = random.randrange(0, 2)
if fifty_fifty == 0:
turtle.right(90)
else:
turtle.left(90)
turtle.forward(10)
示例14: drawP
def drawP(size):
turtle.setheading(90)
turtle.penup()
turtle.forward(size*1.5);
turtle.pendown()
turtle.forward(size*0.5);
drawSemi(size, direction="right", degrees=336, colour="black")
示例15: draw_triangle
def draw_triangle(l):
i=0
while(i<3):
turtle.forward(l)
turtle.left(120)
i=i+1
turtle.done()