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

Python turtle.setheading函数代码示例

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

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



在下文中一共展示了setheading函数的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: 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


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


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


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


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


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


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


示例9: drawFins

def drawFins(size):
    
    turtle.fillcolor("red")    
    turtle.setheading(90)
    turtle.begin_fill()
    turtle.forward(0.2*size)
    turtle.left(120)
    turtle.forward(0.6*size) 
    turtle.right(120)
    turtle.forward(0.3*size) 
    turtle.right(40)
    turtle.forward(0.8*size)
    turtle.end_fill()    
    
    turtle.setheading(0)
    
    turtle.begin_fill()

    turtle.penup()
    turtle.forward(size)
    turtle.pendown()
    turtle.begin_fill()
    turtle.right(50)
    turtle.forward(0.8*size) 
    turtle.right(40)
    turtle.forward(0.3*size) 
    turtle.right(120)
    turtle.forward(0.6*size)
    turtle.end_fill()
开发者ID:rckc,项目名称:CoderDojoUWA2016,代码行数:29,代码来源:Peter+-+Space+Rocket.py


示例10: draw_circle

def draw_circle(x,y,r,t):
    t.pu()
    t.goto(x+r,y)
    t.setheading(90)
    t.pd()
    t.circle(r)
    t.pu()
开发者ID:wraith1995,项目名称:persistentHomology,代码行数:7,代码来源:ph.py


示例11: makeTree

def makeTree(h, l, b, d, ad):
    
    Base(b)
    
    turtle.color("brown")
    
    
    if h > 0:
        
        if h == 1:
            turtle.color("green")

        if h== 4:
            Apple(b)
        if d == 0:
            
            makeTree(h-1 , l*.75, drawLimb(l, d*ad), d+1,ad)
        else:
            y = turtle.heading()
            
            makeTree(h-1 , l*.75, drawLimb(l*.75, d*ad/2.00), d,ad)
            Base(b)
            d = d*-1
            turtle.setheading(y)
            makeTree(h-1 , l*.75, drawLimb(l*.75, d*ad/2.00), d,ad)
        
    else:
        Base(b)
开发者ID:Drellimal2,项目名称:ascii-old-board-games,代码行数:28,代码来源:TurtleTreewithsign+(1).py


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


示例13: move_to_start

def move_to_start(x_start, y_start):    # в качестве параметром принимает координаты
    x = x_start
    y = y_start
    turtle.penup()                  # отключаем рисование
    turtle.setpos(x, y)             # перемещаем turtle
    turtle.setheading(DIRECT_DOWN)  # разворачиваем на юг
    turtle.pendown()                # включаем рисование
开发者ID:vilyaua,项目名称:studying,代码行数:7,代码来源:home6.py


示例14: circle

def circle(a,b):
    turtle.color("green")
    turtle.pu()
    turtle.goto(a,b)
    turtle.pd()
    turtle.setheading(90)
    turtle.circle(40)
开发者ID:DCoelhoM,项目名称:Tic-Tac-Toe-Python,代码行数:7,代码来源:Tic-Tac-Toe_by_DCM.py


示例15: h

def h(fill=False):
    '''draws a capital H.
     This is a DOCstring, which is a special comment that DOCuments our code.  When you type help() in python it
     displays these strings.  Don't take my word for it... try it yourself!'''
    turtle.setheading(0)
    if fill: bf()
    fd(10)
    lt(90)
    fd(50)
    rt(90)
    fd(20)
    rt(90)  # These things after the .'s are functions we can use, just like this h function!
    fd(50)
    lt(90)
    fd(10)
    lt(90)
    fd(110)
    lt(90)
    fd(10)
    lt(90)
    fd(50)
    rt(90)
    fd(20)
    rt(90)
    fd(50)
    lt(90)
    fd(10)
    lt(90)
    fd(110)
    lt(90)
    if fill: ef()  # single statement 'if' can be put on the same line
    pu()
    fd(50)
    pd()
开发者ID:BoroDojo,项目名称:borodojo-python,代码行数:34,代码来源:fredx.py


示例16: draw_rectangle

def draw_rectangle(x,y,width,height):
    """
    Draws a rectangle with the upper left hand corner starting at point (x,y).
    The said rectangle has the dimensions width x height.
    :param x:
    :param y:
    :param width:
    :param height:
    :return: None
    """
    turtle.penup()
    turtle.setx(x)
    turtle.sety(y)
    turtle.pendown()
    turtle.setheading(0)  # Set heading in x+ direction
    turtle.begin_fill()
    turtle.begin_poly()
    turtle.fd(width)
    turtle.right(90)
    turtle.fd(height)
    turtle.right(90)
    turtle.fd(width)
    turtle.right(90)
    turtle.fd(height)
    turtle.end_poly()
    turtle.end_fill()
    return None
开发者ID:brendanoconnor913,项目名称:pythonwork,代码行数:27,代码来源:Assignment4-turtlegraphics.py


示例17: e

def e(fill=False):
    '''draws a capital E.  Docstrings need to be the first line in a function definition'''
    turtle.setheading(0)
    if fill: bf()
    fd(40)
    lt(90)
    fd(10)
    lt(90)
    fd(30)
    rt(90)
    fd(40)
    rt(90)
    fd(30)
    lt(90)
    fd(10)
    lt(90)
    fd(30)
    rt(90)
    fd(40)
    rt(90)
    fd(30)
    lt(90)
    fd(10)
    lt(90)
    fd(40)
    lt(90)
    fd(110)
    lt(90)
    if fill: ef()
    pu()
    fd(50)
    pd()
开发者ID:BoroDojo,项目名称:borodojo-python,代码行数:32,代码来源:fredx.py


示例18: drawFace

def drawFace(x=200, y=200, face=500):
    turtle.pendown()
    colour = random.choice(faceColors)
    drawHead(face, colour)    # Instruct python to use or method "drawSquare"
    turtle.penup()            # space things out before drawing the next Square
    turtle.setposition(x-face/18,y-face/9)

    turtle.pendown()
    turtle.pencolor("black")
    if(colour == "green"):
        drawCrossEye(face/8)
    else:
        drawRoundEye(face/16) 
    
    turtle.penup()            # space things out before drawing the next Square
    turtle.setposition(x+face/18,y-face/9)

    turtle.pendown()
    if(colour == "green"):
        drawCrossEye(face/8)
    else:
        drawRoundEye(face/16) 
    

    turtle.penup()            # space things out before drawing the next Square
    turtle.setposition(x+face/11,y-face/5.5)

    turtle.pendown()
    turtle.setheading(270)
    drawMouth(face/4)
    turtle.penup()
开发者ID:rckc,项目名称:CoderDojoUWA2016,代码行数:31,代码来源:ManyFaces.py


示例19: drawS

def drawS(turtle, height, width):
    """
    draw the letter S using turtle, with some height and width
    """
    # Pick pen up and move a little to the right
    turtle.penup()
    turtle.setheading(0)
    turtle.forward((1.0/6.0)*width)
    # Put pen down and draw bottom of S
    turtle.pendown()
    turtle.forward((2.0/3.0)*width)
    # Draw first curve
    turtle.left((180.0/math.pi)*math.atan((3.0/2.0)*height/width))
    turtle.forward(math.sqrt(((1.0/6.0)*width)**2+((1.0/4.0)*height)**2))
    turtle.left(180.0-(360.0/math.pi)*math.atan((3.0/2.0)*height/width))
    turtle.forward(math.sqrt(((1.0/6.0)*width)**2+((1.0/4.0)*height)**2))
    turtle.left((180.0/math.pi)*math.atan((3.0/2.0)*height/width))
    # Draw middle of S
    turtle.forward((2.0/3.0)*width)
    # Draw second curve
    turtle.right((180.0/math.pi)*math.atan((3.0/2.0)*height/width))
    turtle.forward(math.sqrt(((1.0/6.0)*width)**2+((1.0/4.0)*height)**2))
    turtle.right(180.0-(360.0/math.pi)*math.atan((3.0/2.0)*height/width))
    turtle.forward(math.sqrt(((1.0/6.0)*width)**2+((1.0/4.0)*height)**2))
    turtle.right((180.0/math.pi)*math.atan((3.0/2.0)*height/width))
    # Draw top of S, pick up pen, and move a little to the right
    turtle.forward((2.0/3.0)*width)
    turtle.penup()
    turtle.forward((1.0/6.0)*width)
开发者ID:RJDSTUART,项目名称:CS20-S16-lab03,代码行数:29,代码来源:lab03.py


示例20: grid

def grid(side):
	turtle.color("blue")
	#horizontal
	for i in range(1, 5):
		move(-side*3, side*3-i*side)
		turtle.fd(6*side)

	#vertical
	turtle.setheading(-90)
	for i in range(1, 6):
		move(-side*3+i*side, side*3)
		turtle.fd(5*side)
	
	#big square
	turtle.color("red")
	turtle.width(2)
	turtle.setheading(0)
	move(-side*3, side*3)
	for i in range(4):
		if (i % 2 == 0):
			cena = side * 6
		else:
			cena = side * 5
		turtle.fd(cena)
		turtle.rt(90)
开发者ID:jpbat,项目名称:freetime,代码行数:25,代码来源:30.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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