• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python turtle.position函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中turtle.position函数的典型用法代码示例。如果您正苦于以下问题:Python position函数的具体用法?Python position怎么用?Python position使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: draw_state

    def draw_state(self):
        """
        the core of the class

        Interprete character:

        F: move forward
        +: turn right
        -: turn left
        [: push (position, heading)
        ]: pop (position, heading)
        """
        import turtle

        state = self.lsystem().state()
        for c in state:
            if c == 'F':
                turtle.forward(self.length)
            if c == '+':
                turtle.right(self.angle)
            if c == '-':
                turtle.left(self.angle)
            if c == '[':
                self.stack.append((turtle.position(), turtle.heading()))
            if c == ']':
                if len(self.stack) == 0:
                    raise ValueError('inconsistant state: using to much `]`')
                pos, head = self.stack.pop()
                turtle.penup()
                turtle.setpos(pos)
                turtle.setheading(head)
                turtle.pendown()
        return self
开发者ID:masterzu,项目名称:pylsys,代码行数:33,代码来源:pylsys.py


示例2: main

def main():
    path_data = open('path.txt').read()
    
    print turtle.position()
    turtle.penup()
    turtle.setposition(-400,200)
    turtle.pendown()
    turtle.speed(0)
    turtle.delay(0)
    for c in path_data:
        if c in 'NSEW*':
            if c == 'N':
                turtle.setheading(90)
                turtle.forward(1)
            if c == 'S':
                turtle.setheading(270)
                turtle.forward(1)
            if c == 'E':
                turtle.setheading(0)
                turtle.forward(1)
            if c == 'W':
                turtle.setheading(180)
                turtle.forward(1)
            if c == '*':
                if turtle.isdown():
                    turtle.penup()
                else:
                    turtle.pendown()
开发者ID:llnz,项目名称:kiwipycon2014codewars,代码行数:28,代码来源:q4.py


示例3: 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


示例4: drawTriangle

def drawTriangle(turtle,length,levels,xLocation,yLocation):
    test = raw_input("level is" + str(levels)+ "length is "+ str(length))
    if levels == 0:
        return
    else:
        turtle.setposition(xLocation,yLocation)
        length = float(length/2)
        turtle.pendown()
        levels = levels - 1
        point1 = turtle.position()
        x1location = float(point1[0])
        y1location = float(point1[1])
        turtle.forward(100)
        turtle.right(120)
        point2 = turtle.position()
        x2location = float(point2[0])
        y2location = float(point2[1])
        turtle.forward(100)
        turtle.right(120)
        point3 = turtle.position()
        x3location = float(point3[0])
        y3location = float(point3[1])
        turtle.forward(100)
        turtle.penup()
        turtle.setheading(90)
        drawTriangle(turtle,length,levels,x1location/2,y1location/2)
        drawTriangle(turtle,length,levels,x2location/2,y2location/2)
        drawTriangle(turtle,length,levels,x3location/2,y3location/2)
开发者ID:sumanthneerumalla,项目名称:UdacityProjects,代码行数:28,代码来源:recursiveSierpinski.py


示例5: draw_l

def draw_l(word):
    turtle.up()
    turtle.clear()
    turtle.setposition(0, 0)
    turtle.setheading(0)
    turtle.bk(INITIAL_POS[0])
    turtle.down()
    turtle.st()
    stack = []
    for char in word:
        if char == '0':
            turtle.fd(SIZE[0])
        if char == '1':
            turtle.fd(SIZE[0])
        if char == '[':
            stack.append((turtle.position(), turtle.heading()))
            turtle.lt(45)
        if char == ']':
            position, heading = stack.pop()
            turtle.up()
            turtle.setposition(position)
            turtle.setheading(heading)
            turtle.rt(45)
            turtle.down()
    turtle.ht()
开发者ID:RichardBarrell,项目名称:snippets,代码行数:25,代码来源:draw_l.py


示例6: draw_rectangle

def draw_rectangle (turtle,x,y,width,height=None,color="black"):
    """ This function draws
    
    Parameters
    turtle : `turtle.Turtle`
    x : float
    y : float
    width : float
    height : float
    color : string
    
    """
    # store the current turtle position
    store_x,store_y = turtle.position()    
    store_color = turtle.color()[0]

    move(turtle,x,y)    
    
    turtle.color(color)    
    
    # draw the rectangle
    turtle.goto(x,y-height) 
    turtle.goto(x-width,y-height)
    turtle.goto(x-width,y)
    turtle.goto(x,y)
        
    # move(turtle,store_x,store_y) 
    turtle.color(store_color)    
开发者ID:AstroJuniorResearcherMeetings,项目名称:RSG_2014,代码行数:28,代码来源:turtle_squares.py


示例7: 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()
开发者ID:xerebus,项目名称:nedm,代码行数:28,代码来源:fieldpic.py


示例8: drawString

def drawString( dstring, distance, angle ):
    """ Interpret the characters in string dstring as a series
    of turtle commands. Distance specifies the distance
    to travel for each forward command. Angle specifies the
    angle (in degrees) for each right or left command. The list of 
    turtle supported turtle commands is:
    F : forward
    - : turn right
    + : turn left
    [ : save position, heading
    ] : restore position, heading
    """
    stack = []
    for c in dstring:
		if c == 'F':
			turtle.forward(distance)
		elif c == '-':
			turtle.right(angle)
		elif c == '+':
			turtle.left(angle)
		elif c == '[':
			stack.append(turtle.position())
			stack.append(turtle.heading())
		elif c == ']':
			turtle.up()
			turtle.setheading(stack.pop())
			turtle.goto(stack.pop())
			turtle.down()
		turtle.update()
开发者ID:akaralekas,项目名称:cs151-colby,代码行数:29,代码来源:turtle_interpreter.py


示例9: main

def main():
  #设置一个画面
  windows = turtle.Screen()
  #设置背景
  windows.bgcolor('black')
  #生成一个黄色乌龟
  bran = turtle.Turtle()
  bran.shape('turtle')
  bran.color('white')
  
  turtle.home()
  turtle.dot()
  turtle.fd(50); turtle.dot(20, "blue"); turtle.fd(50)
  turtle.position()
  (100.00,-0.00)
  turtle.heading()
开发者ID:ALEX99XY,项目名称:uband-python-s1,代码行数:16,代码来源:B20826-day17-homework.py


示例10: random_walk

def random_walk(n):
    turtle.setposition(0,0)
    for i in range(n):
        turtle.setheading(random.random()*360)
        turtle.forward(10)

    return turtle.position()
开发者ID:lyceum-allotments,项目名称:misc,代码行数:7,代码来源:exercise1.py


示例11: rysuj

def rysuj():
    turtle.tracer(0, 0)  # wylaczenie animacji co KROK, w celu przyspieszenia
    turtle.hideturtle()  # ukrycie glowki zolwika
    turtle.penup() # podnosimy zolwia, zeby nie mazal nam linii podczas ruchu

    ostatnie_rysowanie = 0  # ile kropek temu zostal odrysowany rysunek

    for i in xrange(ILE_KROPEK):
        # losujemy wierzcholek do ktorego bedziemy zmierzac	
        do = random.choice(WIERZCHOLKI)
        # bierzemy nasza aktualna pozycje 
        teraz = turtle.position()
        # ustawiamy sie w polowie drogi do wierzcholka, ktorego wczesniej obralismy
        turtle.setpos(w_polowie_drogi(teraz, do))
        # stawiamy kropke w nowym miejscu
        turtle.dot(1)
        ostatnie_rysowanie += 1
        if ostatnie_rysowanie == OKRES_ODSWIEZENIA:
            # postawilismy na tyle duzo kropek, zeby odswiezyc rysunek
            turtle.update()
            ostatnie_rysowanie = 0

    pozdrowienia()

    turtle.update()
开发者ID:samorajp,项目名称:kompresja_fraktalna,代码行数:25,代码来源:w_polowie_drogi.py


示例12: draw

def draw(cmds, size=2): #output tree
    stack = []
    for cmd in cmds:
        if cmd=='F':
            turtle.forward(size)
        elif cmd=='-':
            t = random.randrange(0,7,1)
            p = ["Red","Green","Blue","Grey","Yellow","Pink","Brown"]
            turtle.color(p[t])
            turtle.left(15) #slope left
        elif cmd=='+':
            turtle.right(15) #slope right
            t = random.randrange(0,7,1) #рандомная пер. для цвета
            p = ["Red","Green","Blue","Grey","Yellow","Pink","Brown"] #ряд цветов
            turtle.color(p[t]) #выбор цвета из ряда
        elif cmd=='X':
            pass
        elif cmd=='[':
            stack.append((turtle.position(), turtle.heading()))
        elif cmd==']':
            position, heading = stack.pop()
            turtle.penup()
            turtle.setposition(position)
            turtle.setheading(heading)  
            turtle.pendown()
    turtle.update()
开发者ID:Papapashu,项目名称:main,代码行数:26,代码来源:python_three.py


示例13: Adjust

def Adjust():
    [x, y] = turtle.position()
    turtle.penup()
    x = x + 90
    turtle.goto(x, 0)
    turtle.pendown()
    turtle.setheading(90)
开发者ID:towardsRevolution,项目名称:Aditya-s-Python-Codes,代码行数:7,代码来源:typography.py


示例14: drawLine

def drawLine(x,y,rotation,width,length):
    turtle.penup()
    turtle.goto(x,y)
    turtle.width(width)
    turtle.setheading(rotation)
    turtle.pendown()
    turtle.forward(length)
    return turtle.position()
开发者ID:hchiam,项目名称:code7,代码行数:8,代码来源:problem3.py


示例15: fly_romskip

def fly_romskip():
    while True:
        x, y = turtle.position()
        if y < -270:
            return

        romskip['fart_y'] += gravitasjon
        turtle.setposition(x + romskip['fart_x'],
                           y + romskip['fart_y'])
开发者ID:gahjelle,项目名称:gahjelle.github.io,代码行数:9,代码来源:rosetta_og_philae.py


示例16: triforceFlower

def triforceFlower(turtle, center, heading, length, color):
    #draws a flower made up of triforces rotated around a point
    turtle.penup()
    turtle.goto(center)
    turtle.pendown()
    turtle.setheading(heading)
    turtle.color(color)
    for k in range(20):
        triforce(turtle, turtle.position(), turtle.heading(), length, turtle.color()[0], turtle.pensize())
        turtle.left(120)
        turtle.right(18)
开发者ID:jyu197,项目名称:comp_sci_101,代码行数:11,代码来源:TurtlePicture.py


示例17: create_field_line

def create_field_line(B, y_m, start_point_px, end_condition):
    '''Go to the start point and call draw_line_piece(B, y_m) until
    end_condition happens. end_condition should be a lambda expresssion
    taking a tuple representing the current position as its only argument.'''

    tt.penup()
    tt.setposition(start_point_px)

    while not end_condition(tuple(tt.position())):
        draw_line_piece(B, y_m)

    draw_arrow()
开发者ID:xerebus,项目名称:nedm,代码行数:12,代码来源:fieldpic.py


示例18: testBasicShapesAndConnecting

def testBasicShapesAndConnecting():    
    turtle.home()
    turtle.speed(1000000)
    turtle.clear()
    turtle.color("blue")

    makeCircle(25)
    parentA = turtle.position()
    
    turtle.penup()
    goRight(75)
    turtle.pendown()
    
    makeSquare(25)
    parentB = turtle.position()
    
    turtle.penup()
    goLeft(32.5)
    goDown(100)
    goLeft(32.5)
    turtle.pendown()
    
    makeSquare(25)
    childA = turtle.position()
    
    turtle.penup()
    goRight(75)
    turtle.pendown()
    
    makeDiamond(25)
    childB = turtle.position()
    
    turtle.penup()
    goRight(75)
    goDown(49)
    turtle.pendown()
    makeDiamond(25)
    childC = turtle.position()
    
    connectFamily([parentA, parentB], [childA, childB, childC], 25)
开发者ID:EddieCunningham,项目名称:PedigreeDataCollection,代码行数:40,代码来源:pedigreeDraw.py


示例19: tree

def tree(level, length):
    if level == 0:
        return

    turtle.forward(length)
    pos = turtle.position()
    heading = turtle.heading()

    turtle.left(45)
    tree(level - 1, length / 2)

    turtle.penup()
    turtle.setposition(pos)
    turtle.setheading(heading)
    turtle.pendown()

    turtle.right(45)
    tree(level - 1, length / 2)
开发者ID:RonsBrain,项目名称:drawing_fractals,代码行数:18,代码来源:fractal.py


示例20: check_direction

def check_direction():
    """Pre-condition: Checks to see what direction the circle
    will be drawn in.

    Post-condition: Finds the position of turtle.
    - Sets conditions for certain cases and sets the heading of
    the turtle accordingly.
    """
    
    x, y = turtle.position()
    if x - 20 < -180:
        turtle.setheading(0)
    elif x + 20 > 180:
        turtle.setheading(180)
    elif y - 20 < -180:
        turtle.setheading(90)
    elif y + 20 > 180:
        turtle.setheading(270)
开发者ID:kayanushpatel,项目名称:Bubbles,代码行数:18,代码来源:bubbles.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python turtle.pu函数代码示例发布时间:2022-05-27
下一篇:
Python turtle.pos函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap