當前位置: 首頁>>代碼示例>>Python>>正文


Python turtle.left方法代碼示例

本文整理匯總了Python中turtle.left方法的典型用法代碼示例。如果您正苦於以下問題:Python turtle.left方法的具體用法?Python turtle.left怎麽用?Python turtle.left使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在turtle的用法示例。


在下文中一共展示了turtle.left方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: draw_tree

# 需要導入模塊: import turtle [as 別名]
# 或者: from turtle import left [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: square

# 需要導入模塊: import turtle [as 別名]
# 或者: from turtle import left [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

示例3: gear

# 需要導入模塊: import turtle [as 別名]
# 或者: from turtle import left [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

示例4: draw_pattern_rectangle

# 需要導入模塊: import turtle [as 別名]
# 或者: from turtle import left [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 left [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: draw_koch

# 需要導入模塊: import turtle [as 別名]
# 或者: from turtle import left [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

示例7: draw_snowflake

# 需要導入模塊: import turtle [as 別名]
# 或者: from turtle import left [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

示例8: draw_branch

# 需要導入模塊: import turtle [as 別名]
# 或者: from turtle import left [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

示例9: hexagon

# 需要導入模塊: import turtle [as 別名]
# 或者: from turtle import left [as 別名]
def hexagon():
    for _ in range(6):
        turtle.forward(50)
        turtle.left(60) 
開發者ID:johnehunt,項目名稱:advancedpython3,代碼行數:6,代碼來源:draw-hexagons.py

示例10: arc

# 需要導入模塊: import turtle [as 別名]
# 或者: from turtle import left [as 別名]
def arc(sa, ea, x, y, r):  # start angle,end angle,circle center,radius
    turtle.penup()
    turtle.goto(x, y)
    turtle.setheading(0)
    turtle.left(sa)
    turtle.fd(r)
    turtle.pendown()
    turtle.left(90)
    turtle.circle(r, (ea - sa))
    return turtle.position() 
開發者ID:MiracleYoung,項目名稱:You-are-Pythonista,代碼行數:12,代碼來源:bqb.py

示例11: draw_rectangle

# 需要導入模塊: import turtle [as 別名]
# 或者: from turtle import left [as 別名]
def draw_rectangle(size):
    for _ in range(4):
        turtle.forward(size)
        turtle.left(90)

# --- main ---

# clear everything 
開發者ID:furas,項目名稱:python-examples,代碼行數:10,代碼來源:main-3.py

示例12: move

# 需要導入模塊: import turtle [as 別名]
# 或者: from turtle import left [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: s

# 需要導入模塊: import turtle [as 別名]
# 或者: from turtle import left [as 別名]
def s(n, l):

    if n == 0: # stop conditions

        # draw filled rectangle

        turtle.color('black')
        turtle.begin_fill()
        for _ in range (4):
            turtle.forward(l)
            turtle.left(90)
        turtle.end_fill()

    else: # recursion

        # around center point create 8 smalles rectangles.
        # create two rectangles on every side 
        # so you have to repeat it four times

        for _ in range(4):
            # first rectangle
            s(n-1, l/3)    
            turtle.forward(l/3)

            # second rectangle
            s(n-1, l/3)    
            turtle.forward(l/3)

            # go to next corner
            turtle.forward(l/3)
            turtle.left(90)
            
        # update screen
        turtle.update()

# --- main ---    

# stop updating screen (to make it faster) 
開發者ID:furas,項目名稱:python-examples,代碼行數:40,代碼來源:main.py

示例14: draw_1

# 需要導入模塊: import turtle [as 別名]
# 或者: from turtle import left [as 別名]
def draw_1(length, level):
    if level < 1:
        turtle.fd(length)
    else:
        length = length/3
        
        draw_1(length, level-1)
        turtle.left(90)
        draw_1(length, level-1)
        turtle.right(90)
        draw_1(length, level-1)
        turtle.right(90)
        draw_1(length, level-1)
        turtle.left(90)
        draw_1(length, level-1) 
開發者ID:furas,項目名稱:python-examples,代碼行數:17,代碼來源:main-2-left-right-draw_1.py

示例15: draw_2

# 需要導入模塊: import turtle [as 別名]
# 或者: from turtle import left [as 別名]
def draw_2(length, level):
    if level < 1:
        turtle.fd(length)
    else:
        length = length/3
        
        draw_2(length, level-1)
        turtle.left(60)
        draw_2(length, level-1)
        turtle.right(180-60)
        draw_2(length, level-1)
        turtle.left(60)
        draw_2(length, level-1) 
開發者ID:furas,項目名稱:python-examples,代碼行數:15,代碼來源:main-2-left-right-draw_1.py


注:本文中的turtle.left方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。