• 使用turtle库绘制图形


    1.使用turtle库绘制红色五角星图形

    import turtle
    n = eval(input("请输入五角星的长度"))
    turtle.begin_fill() #开始填充颜色
    i = 0
    while i < 5:
        turtle.forward(n)
        turtle.right(180-36)
        i += 1
    turtle.color("red") # 退出填充颜色
    turtle.end_fill()
    turtle.done()
    

      

    2.使用turtle库绘制六角形图形

    from turtle import *
    color("black","red") 
    
    begin_fill()
    pu()
    fd(-200)
    pd()
    seth(30)
    fd(300)
    seth(-90)
    fd(300)
    seth(150)
    fd(300)
    end_fill()
     
    pu()
    seth(90)
    fd(150)
    seth(0)
    fd(87)
    begin_fill()
    
    pd()
    seth(-90)
    fd(300)
    seth(30)
    fd(300)
    seth(150)
    fd(300)
    end_fill()
    done()
    

      

    3.使用turtle库绘制叠加等边三角形图形

    import turtle as t
    t.setup(600, 600, None,None)
    t.pu()
    t.fd(-120)
    t.pensize(5)
    t.width(5)
    t.pencolor("darkgreen")
    t.pd()
    t.fd(250)
    t.seth(120)
    t.pencolor("black")
    t.fd(250)
    t.seth(-120)
    t.pencolor("blue")
    t.fd(250)
    t.pencolor("purple")
    t.fd(250)
    t.seth(0)
    t.pencolor("green")
    t.fd(250)
    t.pencolor("gold")
    t.fd(250)
    t.seth(120)
    t.pencolor("yellow")
    t.fd(250)
    t.seth(-120)
    t.pencolor("grey")
    t.fd(250)
    t.seth(120)
    t.pencolor("pink")
    t.fd(250)
    

      

  • 相关阅读:
    类和对象
    数组
    随笔3
    设计把所有的奇数移动到所有偶数前面的算法
    选择排序
    队列的链式存储结构
    循环队列
    一起玩算法(把所有相同的数字后移)
    判断序列B是否是序列A的连续子序列
    power bi创建切片器导航
  • 原文地址:https://www.cnblogs.com/cnn-ljc/p/12468209.html
Copyright © 2020-2023  润新知