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

Python turtle.setposition函数代码示例

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

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



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

示例1: show_particles

    def show_particles(self, particles):
        self.update_cnt += 1
        if UPDATE_EVERY > 0 and self.update_cnt % UPDATE_EVERY != 1:
            return

        turtle.clearstamps()
        turtle.shape('tri')

        # Particle weights are shown using color variation
        show_color_weights = 1 #len(weights) == len(particles)
        draw_cnt = 0
        px = {}
        for i, p in enumerate(particles):
            draw_cnt += 1
            if DRAW_EVERY == 0 or draw_cnt % DRAW_EVERY == 1:
                # Keep track of which positions already have something
                # drawn to speed up display rendering
                scaled_x = int(p.x * self.one_px)
                scaled_y = int(p.y * self.one_px)
                scaled_xy = scaled_x * 10000 + scaled_y
                if not scaled_xy in px:
                    px[scaled_xy] = 1
                    turtle.setposition([p.x + self.width / 2, p.y + self.height / 2])
                    turtle.setheading(p.theta / pi * 180.0)
                    if(show_color_weights):
                        weight = p.w
                    else:
                        weight = 0.0
                    turtle.color(self.weight_to_color(weight))
                    turtle.stamp()
开发者ID:shreeshga,项目名称:gaussian_particlefilter,代码行数:30,代码来源:draw.py


示例2: show_goal_posts

 def show_goal_posts(self, goal_posts):
     for p in goal_posts:
         turtle.color("#FFFF00")
         turtle.setposition(p[0], p[1])
         turtle.shape("circle")
         turtle.stamp()
         turtle.update()
开发者ID:hendrikvgl,项目名称:RoboCup-Spielererkennung,代码行数:7,代码来源:draw.py


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


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


示例5: init

def init():
    global totalWood
    global maxHeight
    trees = int(input("How many trees in your forest?"))
    house = input("Is there a house in the forest (y/n)?")
    turtle.penup()
    turtle.setposition(-330, -100)
    if(trees < 2 and house == "y"):
        print("we need atleast two trees for drawing house")
        turtle.done()
    else:
        position_of_house = random.randint(1, trees - 1)
        counter = 1
        house_drawn = 0
        while counter <= trees :
            if counter - 1 == position_of_house and house_drawn == 0:
                y = drawHouse(100)
                house_drawn = 1
                totalWood = totalWood + y
                spaceBetween(counter, trees)
            else:
                type_of_tree = random.randint(1, 3)
                wood, height = drawTrees(type_of_tree)
                spaceBetween(counter, trees)
                totalWood = totalWood + wood
                counter = counter + 1
                if height > maxHeight:
                    maxHeight = height

    turtle.penup()
    draw_star(maxHeight)
    turtle.hideturtle()
    input("Press enter to exit")
开发者ID:RIT-2015,项目名称:CPS,代码行数:33,代码来源:draw_image.py


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


示例7: tree2

def tree2(iters, xpos, ypos):
	'''Creates lsystem from filename and then creates an arrangement'''
	# creates object from lsystem
	l2 = ls.Lsystem('lsystemextension2.txt')
	
	#number of iterations
	# for growth effect in task 3, made iters a parameter
	num_iter2 = iters
	
	# creates buildstring function
	s2 = l2.buildString(num_iter2)
	
	#specific angle
	angle2 = 30
	
	#creates an object from TI class
	ti = it.TurtleInterpreter()
	
	# sets the colors of the tracer and calls the drawstring function
	# orients the trees  with parameters xpos and ypos
	# My Tree 2 (mylsystem2.txt)
	turtle.pencolor('SandyBrown')
	'''tree with stem color of coral'''
	turtle.up()
	turtle.setposition(xpos,ypos)
	turtle.setheading(90)
	turtle.down()
	ti.drawString(s2,50,angle2)
开发者ID:akaralekas,项目名称:cs151-colby,代码行数:28,代码来源:project8extension3.py


示例8: tree1

def tree1(iters, xpos, ypos):
	'''Creates lsystem from filename and then creates an arrangement'''
	# creates object from lsystem
	l1 = ls.Lsystem('lsystemextension1.txt')
	
	#number of iterations
	# for growth effect in task 3, made iters a parameter
	num_iter1 = iters
	
	#creates buildstring function
	s1 = l1.buildString(num_iter1)
	
	#specific angle
	angle = 15
	
	#creates an object from TI class
	ti = it.TurtleInterpreter()
	
	# sets the colors of the tracer and calls the drawstring function
	# orients the trees with parameters xpos and ypos
	# My Tree 1 (mylsystem1.txt)
	turtle.pencolor('DarkOliveGreen')
	turtle.pensize(2)
	'''tree with stem color of olivedrab'''
	turtle.up()
	turtle.setposition(xpos,ypos)
	turtle.setheading(90)
	turtle.down()
	ti.drawString(s1,7,angle)
开发者ID:akaralekas,项目名称:cs151-colby,代码行数:29,代码来源:project8extension3.py


示例9: show_robot

 def show_robot(self, robot):
     turtle.color("green")
     turtle.shape('turtle')
     turtle.setposition([robot.x + self.width / 2, robot.y + self.height / 2])
     turtle.setheading(robot.theta / pi * 180.0)
     turtle.stamp()
     turtle.update()
开发者ID:shreeshga,项目名称:gaussian_particlefilter,代码行数:7,代码来源:draw.py


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


示例11: show_particles

    def show_particles(self, particles):
        self.update_cnt += 1
        if UPDATE_EVERY > 0 and self.update_cnt % UPDATE_EVERY != 1:
            return

        # turtle.clearstamps()
        turtle.shape('tri')

        draw_cnt = 0
        px = {}
        for p in particles:
            draw_cnt += 1
            if DRAW_EVERY == 0 or draw_cnt % DRAW_EVERY == 1:
                # Keep track of which positions already have something
                # drawn to speed up display rendering
                scaled_x1 = int(p.x1 * self.one_px)
                scaled_y1 = int(p.y1 * self.one_px)
                scaled_xy1 = scaled_x1 * 10000 + scaled_y1
                if not scaled_xy1 in px:
                    px[scaled_xy1] = 1
                    turtle.setposition(*p.xy1)
                    turtle.setheading(math.degrees(p.h))
                    turtle.color("Red")
                    turtle.stamp()

                    turtle.setposition(*p.xy2)
                    turtle.setheading(math.degrees(p.h))
                    turtle.color("Blue")
                    turtle.stamp()
开发者ID:hmc-lair,项目名称:multitarget_state_estimator,代码行数:29,代码来源:draw.py


示例12: show_robot

 def show_robot(self, robot):
     turtle.color("green")
     turtle.shape('turtle')
     turtle.setposition(*robot.xy)
     turtle.setheading(robot.h)
     turtle.stamp()
     turtle.update()
开发者ID:wellfare,项目名称:particle_filter_demo,代码行数:7,代码来源:draw.py


示例13: main

def main():
	'''Creates lsystem from filename and then creates an arrangement'''
	# creates object from lsystem
	l = ls.Lsystem('lsystemextension2.txt')
	
	#number of iterations
	# for growth effect in task 3, made iters a parameter
	num_iter = 4
	
	
	# creates buildstring function
	s = l.buildString(num_iter)
	
	#specific angle
	angle = 30
	
	#creates an object from TI class
	ti = it.TurtleInterpreter()
	
	# sets the colors of the tracer and calls the drawstring function
	turtle.pencolor('ForestGreen')
	'''tree with stem color of forestgreen'''
	turtle.up()
	turtle.setposition(0,0)
	turtle.setheading(90)
	turtle.down()
	ti.drawString(s, 50 ,angle)
	
	
	
	ti.hold()
开发者ID:akaralekas,项目名称:cs151-colby,代码行数:31,代码来源:project8extension2.py


示例14: rectangle

def rectangle(length = 50, width = 30, x = 0, y = 0, color = 'black', fill = False):
    turtle.pensize(3)
    turtle.speed('fastest')
    turtle.hideturtle()
    if fill == True:
        turtle.color(color)
        for i in range(width): 
            turtle.setposition(x, (y+i))
            turtle.pendown()
            turtle.setposition((x+length), (y+i))
            turtle.penup()
    else:
        turtle.penup()
        turtle.goto(x,y)
        turtle.color(color)
        turtle.pendown()
        turtle.forward(length)
        turtle.left(90)
        turtle.forward(width)
        turtle.left(90)
        turtle.forward(length)
        turtle.left(90)
        turtle.forward(width)
        turtle.left(90)
        turtle.penup()

    return
开发者ID:JakenHerman,项目名称:python-homework,代码行数:27,代码来源:GraphicsAndPatternLibrary.py


示例15: show_sharks

    def show_sharks(self, sharks):
        self.update_cnt += 1
        if UPDATE_EVERY > 0 and self.update_cnt % UPDATE_EVERY != 1:
            return

        turtle.clearstamps()
        draw_cnt = 0
        px = {}
        for shark in sharks:
            draw_cnt += 1
            shark_shape = 'classic' if shark.tracked else 'classic'
            if DRAW_EVERY == 0 or draw_cnt % DRAW_EVERY == 0:
                # Keep track of which positions already have something
                # drawn to speed up display rendering
                scaled_x = int(shark.x * self.one_px)
                scaled_y = int(shark.y * self.one_px)
                scaled_xy = scaled_x * 10000 + scaled_y
                turtle.color(shark.color)
                turtle.shape(shark_shape)
                turtle.resizemode("user")
                turtle.shapesize(1.5,1.5,1)
                if not scaled_xy in px:
                    px[scaled_xy] = 1
                    turtle.setposition(*shark.xy)
                    turtle.setheading(math.degrees(shark.h))
                    turtle.stamp()
开发者ID:hmc-lair,项目名称:multitarget_state_estimator,代码行数:26,代码来源:draw.py


示例16: plano2d

def plano2d():
  turtle.penup()

  for i in range(13):
    y = 264 - (44 *i)
    turtle.penup()
    turtle.setposition(-264,y)
    turtle.pendown()
    turtle.forward(528)
  
  turtle.right(90)

  for i in range(13):
    x = -264 + (44*i)
    turtle.penup()
    turtle.setposition(x,264)
    turtle.pendown()
    turtle.forward(528)
  
  turtle.penup()
  turtle.home()
  turtle.pendown()
  turtle.color("blue")         
  turtle.pensize(3)

  for i in range(4):
    grados = 90 * (i+1)
    turtle.home()
    turtle.left(grados)
    turtle.forward(264) 
开发者ID:joenco,项目名称:compiladorg,代码行数:30,代码来源:figuras.py


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


示例18: show_shark

 def show_shark(self, shark):
     turtle.color(shark.color)
     turtle.shape('turtle')
     turtle.setposition(*shark.xy)
     turtle.setheading(math.degrees(shark.h))
     turtle.stamp()
     turtle.update()
开发者ID:hmc-lair,项目名称:multitarget_state_estimator,代码行数:7,代码来源:draw.py


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


示例20: show_robot

 def show_robot(self, robot):
     turtle.color("blue")
     turtle.shape('square')
     turtle.setposition(*robot.xy)
     turtle.setheading(math.degrees(robot.h))
     turtle.stamp()
     turtle.update()
开发者ID:hmc-lair,项目名称:multitarget_state_estimator,代码行数:7,代码来源:draw.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python turtle.setup函数代码示例发布时间:2022-05-27
下一篇:
Python turtle.setpos函数代码示例发布时间: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