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


Python turtle.pos函数代码示例

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


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

示例1: binary_tree

def binary_tree(depth, length, origin = (0,0) ):

	turtle.setposition(origin)
	if length == 0:
		return True
	turtle.right(30)
	turtle.pendown()
	turtle.forward(depth)
	right = turtle.pos()
	turtle.penup()
	turtle.bk(depth)

	turtle.right(120)
	turtle.pendown()
	turtle.forward(depth)
	turtle.penup()
	left = turtle.pos()
	turtle.bk(depth)

	turtle.left(150)

		
	binary_tree(depth/2, length-1, left) 
	binary_tree(depth/2, length-1, right) 

	return True
开发者ID:DanielMevs,项目名称:python_image_processing,代码行数:26,代码来源:p1.py

示例2: hvezdicka

def hvezdicka():
    turtle = MyTurtle('hvezdicka.svg')
    while True:
        turtle.forward(200)
        turtle.left(170)
        if abs(turtle.pos()[0]) < 1 and abs(turtle.pos()[1]) < 1:
            break
开发者ID:vojtadavid,项目名称:IV122,代码行数:7,代码来源:turtlesssss.py

示例3: draw

def draw():
	size = randint(40, 300)
	angles = (144, 150, 157.5, 160, 165)
	angle = sample(angles, 1)[0]
	
	colors = [
		('#922B21', '#E6B0AA'), ('#76448A', '#D2B4DE'), ('#1F618D', '#AED6F1'), ('#515A5A', '#EAEDED'),
		('#148F77', '#D1F2EB'), ('#B7950B', '#F7DC6F'), ('#F39C12', '#FDEBD0'), ('#BA4A00', '#F6DDCC')]
	color = sample(colors, 1)[0]
	tt.color(color[0], color[1])
	
	x_pos = randint(-200,200)
	y_pos = randint(-200,200)
	tt.pu()
	tt.setpos(x_pos, y_pos)
	start_position = tt.pos()
	tt.pd()
	
	tt.begin_fill()
	while True:
		tt.forward(size)
		tt.left(angle)
		if abs(tt.pos() - start_position) < 1:
			break
	tt.end_fill()
开发者ID:car54giam,项目名称:Python,代码行数:25,代码来源:turtle_graphics.py

示例4: triangle_drawer

def triangle_drawer(leftCornerCoord, sideSize, deep=5):
    cornersCoord = []
    initAngle = 60

    # если достигли дна, т.е. deep=0, то закрашиваем треугольник черным
    if deep > 1:
        color = 'white'
    else:
        color = 'black'

    turtle.color('black', color)
    turtle.begin_fill()
    turtle.penup()
    turtle.setpos(leftCornerCoord[0],leftCornerCoord[1])
    turtle.pendown()
    turtle.setheading(initAngle)
    cornersCoord.append(leftCornerCoord)

    turtle.forward(sideSize)
    turtle.right(initAngle*2)
    cornersCoord.append(turtle.pos())

    turtle.forward(sideSize)
    turtle.right(initAngle*2)
    cornersCoord.append(turtle.pos())

    turtle.forward(sideSize)
    turtle.end_fill()

    return cornersCoord
开发者ID:eppel81,项目名称:education,代码行数:30,代码来源:triangle_new.py

示例5: updateParams

def updateParams(shape):
    global size, lastCount, affected, personList, multipleNotShown
    lastCount = lastCount+1
    
    if(shape == 'Circle'):
        # will add less than the actual size's radius just
        # so that we can erase cleanly
        center = turtle.pos()
        
        xLow = center[0]-size*0.95
        xHigh = center[0]+size*0.95
        yLow = center[1]-size*0.95
        yHigh = center[1]+size*0.95

        
        for i in range(int(xLow), int(xHigh)):
            for j in range(int(yLow), int(yHigh)):                
                
                pixelGrid[i,j] = lastCount
                
        # now add the female to personDict
        adding = [Person(1, affected, False, False, -1, 'none', 'none', -1, [], multipleNotShown), center, size]
        personList[lastCount] = adding
        
    elif(shape == 'Square'):
        center = turtle.pos()
        
        xLow = center[0]-size*0.95
        xHigh = center[0]+size*0.95
        yLow = center[1]-size*0.95
        yHigh = center[1]+size*0.95

        
        for i in range(int(xLow), int(xHigh)):
            for j in range(int(yLow), int(yHigh)):                
                
                pixelGrid[i,j] = lastCount
                
        # now add the male to personDict
        adding = [Person(0, affected, False, False, -1, 'none', 'none', -1, [], multipleNotShown), center, size]
        personList[lastCount] = adding
    
    elif(shape == 'Diamond'):
        center = turtle.pos()
        
        xLow = center[0]-size*0.95
        xHigh = center[0]+size*0.95
        yLow = center[1]-size*0.95
        yHigh = center[1]+size*0.95

        
        for i in range(int(xLow), int(xHigh)):
            for j in range(int(yLow), int(yHigh)):
                
                pixelGrid[i,j] = lastCount
                
        adding = [Person(2, affected, False, False, -1, 'none', 'none', -1, [], multipleNotShown), center, size]
        personList[lastCount] = adding
        
    return adding[0]
开发者ID:EddieCunningham,项目名称:PedigreeDataCollection,代码行数:60,代码来源:pedigreeCreate.py

示例6: draw_tree

def draw_tree(x,y):
    startPosX = x
    startPosY = y
    turtle.setpos(x,y)
    turtle.fillcolor("green")
    turtle.begin_fill()
    for i in range(0,4):
        x -=40
        y -=80
        turtle.goto(x,y)
        coords.append(turtle.pos())
        x += 20
        turtle.goto(x,y)
    bottomCorner = turtle.pos()
    x = startPosX
    y = startPosY
    turtle.setpos(x,y)
    for i in range(0,4):
        x +=40
        y -=80
        turtle.goto(x,y)
        coords.append(turtle.pos())
        x -= 20
        turtle.goto(x,y)
    turtle.goto(bottomCorner)
    turtle.end_fill()
开发者ID:nyep,项目名称:learning-prog,代码行数:26,代码来源:turtleTree+[WIP].py

示例7: triangleDrawer

def triangleDrawer(startx, starty, length, head='top'):	
	coordsList = []
	descrTriangle = {}
	if head == 'top':
		head = 120
		t.color("black","black")
	elif head == 'bottom':
		head = 240
		t.color("white","white")
	t.setheading(0)
	t.penup()
	t.begin_fill()
	t.setpos(startx, starty)
	t.pendown()
	coordsList.append(t.pos())
	t.forward(length)
	coordsList.append(t.pos())
	t.setheading(head)
	t.forward(length)
	coordsList.append(t.pos())
	if head == 120:
		t.left(120)
	else:
		t.right(120)	
	t.forward(length)
	t.end_fill()
	descrTriangle['length'] = length
	descrTriangle['coord'] = coordsList
	return descrTriangle
开发者ID:eppel81,项目名称:education,代码行数:29,代码来源:triangle.py

示例8: test_zigzag

 def test_zigzag(self):
     """
     Test that a AsyncTurtle ends up in the correct position
     after several concurrent commands in sequence, and draws
     a zigzag line on the canvas.
     """
     turtle = AsyncTurtle(loop=self.loop)
     tasks = [
         asyncio.ensure_future(turtle.fd(10), loop=self.loop),
         asyncio.ensure_future(turtle.lt(90), loop=self.loop),
         asyncio.ensure_future(turtle.fd(10), loop=self.loop),
         asyncio.ensure_future(turtle.rt(90), loop=self.loop),
         asyncio.ensure_future(turtle.fd(10), loop=self.loop)
     ]
     self.loop.run_until_complete(asyncio.wait(tasks, loop=self.loop))
     self.loop.close()
     self.assertEqual(turtle.pos()[0], 20)
     self.assertEqual(turtle.pos()[1], 10)
     expected_coords = [
         0.0, 0.0,
         10.0, 0.0,
         10.0, -10.0,
         20.0, -10.0
     ]
     # Assume the last item id on the canvas is the line
     # drawn by the turtle. Check if this assumption is valid.
     line_id = max(turtle.screen.cv.find_all())
     self.assertEqual(turtle.screen.cv.coords(line_id), expected_coords)
开发者ID:appeltel,项目名称:aioturtle,代码行数:28,代码来源:test_aioturtle.py

示例9: radar_chart

def radar_chart(data):
    # Some "typical" test data
    #print "Hello"
    length=len(data) # stores the length of the data provided
    turtle.home()   # Sets the turtle to position (0,0)
    division=360/length #what angle is needed for invidual lines
    poslist=[] #list to store current position
    valpos=[]   #list to store position
    j=0
    turtle.hideturtle() #hides the arrow
        #Draw the foundation of the Radar Chart
    for i in range(length): # Loop until all the given data is plotted
        turtle.forward(200) #move turtle forward
        turtle.dot(10,"black") # Draw the black dot at the end of each data
        nowpos=turtle.pos() # store the current position
        poslist.append(nowpos) #append the current position to list
        #turtle.hideturtle()
        turtle.setpos(nowpos[0]+10,nowpos[1]) #get the turtle to new postion to write data
        turtle.write(data[i], True, align="center") # Write the label of data
        turtle.setpos(nowpos[0],nowpos[1]) #return to the previous position
        turtle.back(200) #return home
        turtle.left(division) # rotate by the specific angle
    turtle.home()    # return to turtle home
    #Connect the ends points of the radar chart
    for i in poslist: #
        turtle.setpos(i[0],i[1])
        #turtle.setpos(i[j],i[j+1])
        #turtle.forward(100)
        #turtle.home()
        #turtle.degree(division)
        #turtle.heading()
        #turtle.forward(100)
    turtle.setpos(poslist[0][0],poslist[0][1])
    turtle.home()
    #Draw green Dots 
    for i in range(length):
        incval=data[i]
        turtle.forward(incval*2)
        turtle.dot(15,"green")
        nowpos=turtle.pos()
        valpos.append(nowpos) 
        turtle.back(incval*2)
        turtle.left(division)
    turtle.begin_poly()
    turtle.fill(True)
    #Fill the green Dots
    for i in valpos:
        turtle.setpos(int(i[0]),int(i[1]))
    turtle.setpos(valpos[0][0],valpos[0][1])
    turtle.end_poly()
    p = turtle.get_poly()
    turtle.register_shape("jpt", p)
    turtle.color("Green", "Green")
    turtle.begin_fill()
    #turtle.p(80)
    turtle.end_fill()
    turtle.fill(False)
开发者ID:aadeshnpn,项目名称:timepass,代码行数:57,代码来源:radar_chart.py

示例10: forward

def forward(d):
	while d != 0:
		def clamp(v):
			if (v>stmax):
				v = stmax
			return v			
		dx = clamp(d)
		turtle.forward(dx)
		emb.addStitch(stitchcode.Point(turtle.pos()[0],turtle.pos()[1]))
		d -= dx
开发者ID:backface,项目名称:stitchcode,代码行数:10,代码来源:generate-spiral.py

示例11: reset

def reset(goal, turtle, info) : 
	turtle.reset()
	turtle.clear()
	goal.reset()
	goal.clear()
	while True :
		goalPos=setGoal(goal)
		pos=turtle.pos()
		if(goalPos[0]<=pos[0]<=goalPos[0]+100 and goalPos[1]<=pos[1]<=goalPos[1]+100) :
			continue
		else :
			info["goalPos"]=goalPos
			info["tracks"]=[turtle.pos()]
			break
开发者ID:jhMoon1115,项目名称:p1_201111222,代码行数:14,代码来源:turtleGame_v1.0.py

示例12: connectFamily

def connectFamily(parents, children, size, offset=0, color='blue'):
    origPosition = turtle.pos()
    origHead = turtle.heading()
    oldColor = turtle.pencolor()
    turtle.pencolor(color)
    turtle.penup()
    
    # parents are a tuple of positions for the parents
    # children are a tuple of positions of the children
    # all positions are from the center of each shape
    if(len(parents) == 2):
        # if we have 2 parents
        parentA = parents[0]
        parentB = parents[1]
        # draw horizontal line between parents
        turtle.goto(parentA)

        goDown(offset)        
        
        goRight(size)
        turtle.pendown()
        goRight(parentB[0]-parentA[0]-2*size)
        goLeft((parentB[0]-parentA[0]-2*size)/2 + offset)
        goDown(2*size)
    else:
        # if unaffected mate == True
        parentA = parents[0]
        turtle.goto(parentA)
        goDown(size)
        turtle.pendown()
    
        goDown(offset)

    currentPosition = turtle.pos()

    for child in children:
        horizDist = currentPosition[0] - child[0]
        verticalDist = currentPosition[1] - child[1] - size
        goLeft(horizDist)
        goDown(verticalDist)
        turtle.penup()
        turtle.goto(currentPosition)
        turtle.pendown()            
        
    turtle.penup()    
    turtle.goto(origPosition)
    turtle.setheading(origHead)
    turtle.pencolor(oldColor)
    turtle.up()
开发者ID:EddieCunningham,项目名称:PedigreeDataCollection,代码行数:49,代码来源:pedigreeDraw.py

示例13: draw_arrow

def draw_arrow(turtle, cell_size, rotation=0):
    pos = turtle.pos()
    turtle.left(rotation)
    turtle.back(cell_size*.2)
    turtle.down()
    turtle.left(90)
    turtle.begin_fill()
    turtle.forward(cell_size*.05)
    turtle.right(90)
    turtle.forward(cell_size*.3)
    turtle.left(90)
    turtle.forward(cell_size*.1)
    turtle.right(120)
    turtle.forward(cell_size*.3)
    turtle.right(120)
    turtle.forward(cell_size*.3)
    turtle.right(120)
    turtle.forward(cell_size*.1)
    turtle.left(90)
    turtle.forward(cell_size*.3)
    turtle.right(90)
    turtle.forward(cell_size*.05)
    turtle.right(90)
    turtle.forward(cell_size*.2)
    turtle.end_fill()
    turtle.up()
    turtle.setpos(pos)
    turtle.right(rotation)
开发者ID:donkirkby,项目名称:donimoes,代码行数:28,代码来源:diagram.py

示例14: play

def play():           # 게임을 실제로 플레이 하는 함수.
    global score
    global playing
    t.forward(10)       # 주인공 거북이 10만큼 앞으로 이동합니다.
    if random.randint(1, 5) == 3: # 1~5사이에서 뽑은 수가 3이면(20%확률)
        ang = te.towards(t.pos())
        te.sethading(ang)        # 악당 거북이가 주인공 거북이를 바라봅니다
    speed = score + 5            # 점수에 5를 더해서 속도를 올립니다.
                                 # 점수가 올라가면 빨라집니다.
                                 
    if speed > 15:               # 속도가 15를 넘지는 않도록 합니다
        speed = 15
    te.forward(speed)
    
    if t.distance(te) < 12:      # 주인공과 악당의 거리가 12보다 작으면
                                 # 게임을 종료합니다.  
        
        text = "Score : " + str(score)
        message("Game Over", text)
        playing = False
        score = 0
    
    
    if t.distance(ts) < 12:      # 주인공과 먹이의 거리가 12보다 작으면(가까우면)
        score = score + 1        # 점수를 올립니다.
        t.write(score)           # 점수를 화면에 표시합니다.
        star_x = random.randint(-230, 230)
        star_y = random.randint(-230, 230)
        ts.goto(star_x, star_y)  # 먹이를 다른 곳으로 옮깁니다.
        
    if playing:
        t.ontimer(play, 100)     # 게임 플레이 중이면 0.1초후
开发者ID:hubls,项目名称:p2_201611092,代码行数:32,代码来源:Turtle+Run+Game.py

示例15: makeDiamond

def makeDiamond(size, person=None, fill=False):
    origPosition = turtle.pos()
    origHead = turtle.heading()
    turtle.penup()
    goDown(size)
    turtle.pendown()
    if(person != None or fill==True):
        if(fill==True or person.affected):
            turtle.begin_fill()
    goNorthEast(2*size/np.sqrt(2))
    goNorthWest(2*size/np.sqrt(2))
    goSouthWest(2*size/np.sqrt(2))
    goSouthEast(2*size/np.sqrt(2))
    if(person != None or fill==True):
        if(fill==True or person.affected):
            turtle.end_fill()
    turtle.penup()
    turtle.goto(origPosition)
    turtle.setheading(origHead)
    if(person != None or fill==True):
        if(fill==True or person.affected):
            turtle.color('black')
        if(person.multipleNotShown == 0):
            turtle.write(str(person.name())+"\n"+probString(person), align="center")
        else:
            turtle.write(str(person.name())+"\n"+probString(person)+"\n\n"+str(person.multipleNotShown), align="center")
    turtle.color('blue')
    turtle.penup()
开发者ID:EddieCunningham,项目名称:PedigreeDataCollection,代码行数:28,代码来源:pedigreeDraw.py


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