美文网首页
Python初试-turtle

Python初试-turtle

作者: mnz12138 | 来源:发表于2018-01-27 13:23 被阅读0次

    1、正方形

    import turtle
    t=turtle.Turtle()
    for i in range(4):
        t.forward(100)
        t.left(360/4)
    

    2、五边形

    import turtle
    t=turtle.Turtle()
    for i in range(5):
        t.forward(100)
        t.left(360/5)
    

    3、边框颜色

    import turtle
    t=turtle.Turtle()
    t.color("red")
    for i in range(5):
        t.forward(100)
        t.left(360/5)
    

    4、填充颜色

    import turtle
    t=turtle.Turtle()
    t.color("red","yellow")
    t.begin_fill()
    for i in range(5):
        t.forward(100)
        t.left(360/5)
    t.end_fill()
    

    5、五角星

    import turtle
    t=turtle.Turtle()
    t.color("red","yellow")
    t.begin_fill()
    for i in range(5):
        t.forward(100)
        t.right(144)
    t.end_fill()
    

    6、正方形圈

    import turtle
    t=turtle.Turtle()
    t.speed(10)
    for j in range(10):
          for i in range(4):
            t.down()
            t.forward(10+j*20)
            t.left(90)
        t.up()
        t.goto(-10*(j+1),-10*(j+1))
    

    7、同心圆

    import turtle
    t=turtle.Turtle()
    t.speed(10)
    for i in range(5,0,-1):
        t.up()
        t.goto(0,-30*i)
        t.down()
        t.circle(30*i)
    

    8、填充颜色同心圆

    import turtle
    t=turtle.Turtle()
    t.speed(10)
    colors=["red","blue","yellow","purple","green"]
    for i in range(5,0,-1):
        t.up()
        t.goto(0,-30*i)
        t.color(colors[i%5])
        t.begin_fill()
        t.down()
        t.circle(30*i)
        t.end_fill()
    

    相关文章

      网友评论

          本文标题:Python初试-turtle

          本文链接:https://www.haomeiwen.com/subject/jeknaxtx.html