当前位置: 首页>>代码示例>>Python>>正文


Python turtle.forward方法代码示例

本文整理汇总了Python中turtle.forward方法的典型用法代码示例。如果您正苦于以下问题:Python turtle.forward方法的具体用法?Python turtle.forward怎么用?Python turtle.forward使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在turtle的用法示例。


在下文中一共展示了turtle.forward方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: draw_tree

# 需要导入模块: import turtle [as 别名]
# 或者: from turtle import forward [as 别名]
def draw_tree(length, width=9):
    color = 'brown'
    if length < 1:
        return
    elif length < 3:
        color = 'green'

    if width < 1:
        width = 1

    turtle.color(color)
    turtle.width(width)
    turtle.forward(length)
    turtle.left(30)
    draw_tree(length / FACTOR, width - 1)
    turtle.right(60)
    draw_tree(length / FACTOR, width - 1)
    turtle.left(30)
    turtle.color(color)
    turtle.width(width)
    turtle.backward(length) 
开发者ID:johnehunt,项目名称:advancedpython3,代码行数:23,代码来源:fractal_trees.py

示例2: gear

# 需要导入模块: import turtle [as 别名]
# 或者: from turtle import forward [as 别名]
def gear(count, width, height):

    angle = 90-(180/count)

    for _ in range(count):
        turtle.forward(width)
        turtle.left(angle)
        turtle.forward(height)
        turtle.right(90)
        turtle.forward(width)
        turtle.right(90)
        turtle.forward(height)
        turtle.left(angle)

# --- main ---

# clear everything 
开发者ID:furas,项目名称:python-examples,代码行数:19,代码来源:gear-1.py

示例3: square

# 需要导入模块: import turtle [as 别名]
# 或者: from turtle import forward [as 别名]
def square(x, y, size, name):
    """Draw square at `(x, y)` with side length `size` and fill color `name`.

    The square is oriented so the bottom left corner is at (x, y).

    """
    import turtle
    turtle.up()
    turtle.goto(x, y)
    turtle.down()
    turtle.color(name)
    turtle.begin_fill()

    for count in range(4):
        turtle.forward(size)
        turtle.left(90)

    turtle.end_fill() 
开发者ID:PacktPublishing,项目名称:Learning-Python-by-building-games,代码行数:20,代码来源:base.py

示例4: draw_pattern_rectangle

# 需要导入模块: import turtle [as 别名]
# 或者: from turtle import forward [as 别名]
def draw_pattern_rectangle(x, y, width, height, count, radius, color='red'):
    rotation = 360 / count

    turtle.goto(x, y)
    
    for _ in range(count):
        # move from center to circle
        turtle.pu()
        #turtle.color('black')
        turtle.forward(radius)
        turtle.right(90+rotation/2)
        
        draw_rectangle(width, height, color)

        # move from circle to center
        turtle.pu()
        #turtle.color('black')
        turtle.left(90+rotation/2)
        turtle.backward(radius)

        # rotate in circle
        turtle.right(rotation) 
开发者ID:furas,项目名称:python-examples,代码行数:24,代码来源:main.py

示例5: draw_pattern_circle

# 需要导入模块: import turtle [as 别名]
# 或者: from turtle import forward [as 别名]
def draw_pattern_circle(x, y, r, count, radius, color='red'):
    rotation = 360 / count

    turtle.goto(x, y)

    for _ in range(count):
        # move from center to circle
        #turtle.pu()
        turtle.color('black')
        turtle.forward(radius)
        turtle.right(90)

        draw_circle(r, color)

        # move from circle to center
        #turtle.pu()
        turtle.color('black')
        turtle.left(90)
        turtle.backward(radius)

        # rotate in circle
        turtle.right(rotation) 
开发者ID:furas,项目名称:python-examples,代码行数:24,代码来源:main.py

示例6: item

# 需要导入模块: import turtle [as 别名]
# 或者: from turtle import forward [as 别名]
def item(lenght, level, color):
    if level <= 0:
        return
    
    for _ in range(5):    # 5
        turtle.color(colors[color])
        turtle.forward(lenght)
        
        item(lenght/4, level-1, color+1)
        
        turtle.penup() # there is no need to draw again the same line  (and it can use differnt color)
        turtle.backward(lenght)
        turtle.pendown()
        
        turtle.right(360/8) # 8
    
    turtle.right(360/8 * 3) # 3 = 8 - 5 
开发者ID:furas,项目名称:python-examples,代码行数:19,代码来源:main-colors-asymmetrical.py

示例7: draw_koch

# 需要导入模块: import turtle [as 别名]
# 或者: from turtle import forward [as 别名]
def draw_koch(size, depth):
    if depth > 0:
        for angle in ANGLES:
            draw_koch(size / 3, depth - 1)
            turtle.left(angle)
    else:
        turtle.forward(size) 
开发者ID:johnehunt,项目名称:advancedpython3,代码行数:9,代码来源:snowflake_koch.py

示例8: draw_snowflake

# 需要导入模块: import turtle [as 别名]
# 或者: from turtle import forward [as 别名]
def draw_snowflake(size):
    """ Draw a picture of a snowflake """
    turtle.penup()
    turtle.forward(10 * size)
    turtle.left(45)
    turtle.pendown()
    turtle.color(generate_random_colour())

    # draw branch 8 times to make a snowflake
    for _ in range(8):
        draw_branch(size)
        turtle.forward(size)
        turtle.left(45)

    turtle.penup() 
开发者ID:johnehunt,项目名称:advancedpython3,代码行数:17,代码来源:snowflake.py

示例9: draw_branch

# 需要导入模块: import turtle [as 别名]
# 或者: from turtle import forward [as 别名]
def draw_branch(size):
    """ Draw an individual branch on a snowflake """
    side_branch_size = size / 3
    for _ in range(3):
        for i in range(3):
            turtle.forward(side_branch_size)
            turtle.backward(side_branch_size)
            turtle.right(45)
        turtle.left(90)
        turtle.backward(side_branch_size)
        turtle.left(45)
    turtle.right(90) 
开发者ID:johnehunt,项目名称:advancedpython3,代码行数:14,代码来源:snowflake.py

示例10: draw_square

# 需要导入模块: import turtle [as 别名]
# 或者: from turtle import forward [as 别名]
def draw_square(size):
    """ Function to draw a square """
    turtle.forward(size)
    turtle.right(90)
    turtle.forward(size)
    turtle.right(90)
    turtle.forward(size)
    turtle.right(90)
    turtle.forward(size) 
开发者ID:johnehunt,项目名称:advancedpython3,代码行数:11,代码来源:sample-window3.py

示例11: hexagon

# 需要导入模块: import turtle [as 别名]
# 或者: from turtle import forward [as 别名]
def hexagon():
    for _ in range(6):
        turtle.forward(50)
        turtle.left(60) 
开发者ID:johnehunt,项目名称:advancedpython3,代码行数:6,代码来源:draw-hexagons.py

示例12: move

# 需要导入模块: import turtle [as 别名]
# 或者: from turtle import forward [as 别名]
def move():
    if running:
        t.forward(15)
        angle = random.randint(-9, 9) * 10 
        t.left(angle)
        t.ontimer(move, 25) # 25ms 
开发者ID:furas,项目名称:python-examples,代码行数:8,代码来源:example-1.py

示例13: forward

# 需要导入模块: import turtle [as 别名]
# 或者: from turtle import forward [as 别名]
def forward():
    turtle.setheading(90)
    turtle.forward(100) 
开发者ID:furas,项目名称:python-examples,代码行数:5,代码来源:main.py

示例14: left

# 需要导入模块: import turtle [as 别名]
# 或者: from turtle import forward [as 别名]
def left():
    turtle.setheading(180)
    turtle.forward(100) 
开发者ID:furas,项目名称:python-examples,代码行数:5,代码来源:main.py

示例15: move

# 需要导入模块: import turtle [as 别名]
# 或者: from turtle import forward [as 别名]
def move(distance):
	turtle.penup()
	turtle.forward(distance)
	turtle.pendown() 
开发者ID:CharlesPikachu,项目名称:Tools,代码行数:6,代码来源:clock.py


注:本文中的turtle.forward方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。