zoukankan      html  css  js  c++  java
  • 基于python的turtle模块画国旗

    基于python的turtle模块画国旗,愿祖国早日战胜病毒

    • 画国旗是很严肃的问题,一定要按照规定去画
    • 国旗宽高比为:3:2
    • 国旗标准图
    • 绘制五角星需要严格的计算
    • 科学计算器网站:http://www.ab126.com/
    • 知道三角函数值求角度方法,使用excel =ASIN(A1)*180/PI()
    import turtle
    
    # 设置画笔速度和画布大小和位置
    turtle.speed(10)
    turtle.setup(650, 450)
    # 画国旗大背景
    # 移动画笔需要先把笔抬起来
    turtle.up()
    turtle.goto(-300, 200)
    turtle.down()
    turtle.begin_fill()
    turtle.fillcolor("red")
    turtle.pencolor("red")
    # 画出边界
    for i in range(2):
        turtle.forward(600)
        turtle.right(90)
        turtle.forward(400)
        turtle.right(90)
    # 填充国旗颜色
    turtle.end_fill()
    
    # 画大五角星
    turtle.up()
    turtle.goto(-200, 160)
    turtle.seth(-72)
    turtle.down()
    turtle.begin_fill()
    turtle.fillcolor("yellow")
    turtle.pencolor("yellow")
    for x in range(5):
        turtle.forward(120)
        turtle.right(144)
    turtle.end_fill()
    
    # 画第一个小五角星
    turtle.up()
    turtle.goto(-100 - 17.3145, 160 - 6.174)
    turtle.seth(48.96347)
    turtle.down()
    turtle.begin_fill()
    turtle.fillcolor("yellow")
    turtle.pencolor("yellow")
    for x in range(5):
        turtle.forward(38.0417418)
        turtle.right(144)
    turtle.end_fill()
    
    # 画第二个小五角星
    turtle.up()
    turtle.goto(-60 - 19.7948663580, 120 - 2.857143)
    turtle.seth(36.213211)
    turtle.down()
    turtle.begin_fill()
    turtle.fillcolor("yellow")
    turtle.pencolor("yellow")
    for x in range(5):
        turtle.forward(38.0417418)
        turtle.right(144)
    turtle.end_fill()
    
    # 画第三个小五角星
    turtle.up()
    turtle.goto(-60 - 19.5, 60 + 5.714285848)
    turtle.seth(5)
    turtle.down()
    turtle.begin_fill()
    turtle.fillcolor("yellow")
    turtle.pencolor("yellow")
    for x in range(5):
        turtle.forward(38.0417418)
        turtle.right(144)
    turtle.end_fill()
    
    # 画第四个小五角星
    turtle.up()
    turtle.goto(-100 - 17.2, 20 + 15.99999)
    turtle.seth(-35.1301)
    turtle.down()
    turtle.begin_fill()
    turtle.fillcolor("yellow")
    turtle.pencolor("yellow")
    for x in range(5):
        turtle.forward(38.0417418)
        turtle.right(144)
    turtle.end_fill()
    
    # 写文字
    turtle.up()
    turtle.goto(0, -100)
    turtle.pencolor('violet')
    turtle.write('武汉加油,中国加油!', move=True, align='center', font=('华文新魏', 30, 'normal'))
    
    # 隐藏画笔,绘画完成
    turtle.hideturtle()
    turtle.done()
    

    效果图

    版权声明:本文为博主原创文章,转载请附上博文链接!
  • 相关阅读:
    Workbooks 对象的 Open 方法参数说明
    OLDB读取excel的数据类型不匹配的解决方案
    使用OLEDB读取Excel
    C#锁定EXCEL工作表
    smple
    C# 获取当前文件、文件夹的路径及操作环境变量
    与eval()相关的技巧
    不写var的全局变量声明方式的一个副作用(Side Effects When Forgetting var)
    关于国内浏览器的userAgent识别
    for循环的效率改进写法二则
  • 原文地址:https://www.cnblogs.com/zq98/p/15028023.html
Copyright © 2011-2022 走看看