zoukankan      html  css  js  c++  java
  • Python之turtle画同心圆和棋盘

    画饼图

    import turtle
    
    t = turtle.Pen()
    
    for i in range(5):
        t.penup()
        t.goto(0, -i*30)
        t.pendown()
        t.circle(i*30+30)
    
    turtle.done()

    画棋盘

    import turtle
    
    t = turtle.Pen()
    
    widthall = 200
    width = 20
    num = widthall // 20 * 2 + 1
    
    t.speed(10)
    
    for r in range(num):
        t.penup()
        t.goto(-widthall, widthall - width * r)
        t.pendown()
        t.goto(widthall, widthall - width * r)
    
    for c in range(num):
        t.penup()
        t.goto(-widthall + width * c, widthall)
        t.pendown()
        t.goto(-widthall + width * c, -widthall)
    
    turtle.done()

    海龟绘图
    绘制简单的五角星。
    导入turtle模块
    默认情况下,海龟的开始位置在窗口的中间,朝向右下方,笔是向下的。
    然后,控制海龟进行多次转弯,画出线段。
    星形的中心是正五边形,正五边形的每个内角为108°。
    五个等腰山叫醒连接在五边形的外部。
    因为五边形的一侧形成三角形延伸,每个三角形的底角为72°(补角:180°-108°)
    等腰三角形的两个底角度数相同,加起来是144°。所以第三个角必须是36°。
    为了实现急转弯,在星形的每个顶点需要转144°(即180°-36°)。
    因此在每个顶点,有turtle.right(144)。
    import turtle
    t = turtle.Pen()
    
    t.forward(100)
    t.right(144)
    t.forward(100)
    t.right(144)
    t.forward(100)
    t.right(144)
    t.forward(100)
    t.right(144)
    t.forward(100)
    
    turtle.done()

    谢谢

  • 相关阅读:
    Redis安装部署
    传输方式Topic和Queue的对比
    Hudson配置及使用
    linux 绿色版 bes 6.6服务安装
    LINUX磁盘管理
    并发用户数与 TPS 之间的关系
    性能测试场景
    计算并发用户数的五种方法
    让selenium自动化脚本运行的更快的技巧
    Jmeter学习
  • 原文地址:https://www.cnblogs.com/zhzhang/p/9903239.html
Copyright © 2011-2022 走看看