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


Python turtle.forward函数代码示例

本文整理汇总了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
开发者ID:Metushelah,项目名称:Python_Intro2cs_exercises,代码行数:25,代码来源:y_tree.py

示例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)
开发者ID:junghoyo92,项目名称:Stars,代码行数:7,代码来源:proj02.py

示例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)
开发者ID:jonobrien,项目名称:School_Backups,代码行数:34,代码来源:spell_out.py

示例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)
开发者ID:csgray,项目名称:IPND_lesson_3,代码行数:7,代码来源:sierpinski_carpet.py

示例5: entrance

def entrance(pointOne):
    turtle.goto(pointOne[0], pointOne[1] + 36)
    turtle.setheading(270)
    turtle.pendown()
    turtle.forward(15)
    turtle.penup()
    drawArrows()
开发者ID:JonSchwarz23,项目名称:Automaton,代码行数:7,代码来源:NoSaveAutomaton.py

示例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()
开发者ID:ddamuliram,项目名称:Mahadi-Ddamulira,代码行数:7,代码来源:shapes.py

示例7: at

def at(x, y):
    turtle.penup()
    turtle.home()
    turtle.forward(x)
    turtle.left(90)
    turtle.forward(y)
    turtle.pendown()
开发者ID:michaelmp,项目名称:python-lab,代码行数:7,代码来源:lab2.py

示例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)
开发者ID:gunther-on-fire,项目名称:boris-the-parselmouth,代码行数:7,代码来源:minkovskiy1.py

示例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)
开发者ID:gunther-on-fire,项目名称:boris-the-parselmouth,代码行数:7,代码来源:spring.py

示例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
开发者ID:AnushaBalusu,项目名称:PythonCodes,代码行数:29,代码来源:enhanced_tree.py

示例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
开发者ID:Aliciawyse,项目名称:intro-programming-nanodegree,代码行数:25,代码来源:classes_notes.py

示例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)
开发者ID:AnushaBalusu,项目名称:PythonCodes,代码行数:33,代码来源:enhanced_tree.py

示例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)
开发者ID:guardhunt,项目名称:all_projects,代码行数:7,代码来源:Cop+Robber+Game.py

示例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")
开发者ID:rckc,项目名称:CoderDojoUWA2016,代码行数:7,代码来源:Peter+-+Space+Rocket.py

示例15: draw_triangle

def draw_triangle(l):
    i=0
    while(i<3):
        turtle.forward(l)
        turtle.left(120)
        i=i+1
    turtle.done()
开发者ID:gesesew,项目名称:Gesesew-Reta,代码行数:7,代码来源:matplot.py


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