zoukankan      html  css  js  c++  java
  • Python之turtl库-玫瑰花

    Python之turtl库-玫瑰花

    A01-玫瑰花.jpg

    #!/usr/bin/env python
    # coding: utf-8
    
    # Python turtle库官方文档:https://docs.python.org/2/library/turtle.html
    
    import turtle as t
    
    
    # 定义一个曲线绘制函数
    def DegreeCurve(n, r, d=1):
        for i in range(n):
            t.left(d)
            t.circle(r, abs(d))
    
    
    # 初始位置设定
    t.begin_fill()
    s = 0.2  # size
    t.setup(450 * 5 * s, 750 * 5 * s)
    t.pencolor("black")
    t.fillcolor("red")
    t.speed(100)
    t.penup()
    t.goto(0, 900 * s)
    t.pendown()
    
    # 绘制花朵形状
    t.begin_fill()
    t.circle(200 * s, 30)
    DegreeCurve(60, 50 * s)
    t.circle(200 * s, 30)
    DegreeCurve(4, 100 * s)
    t.circle(200 * s, 50)
    DegreeCurve(50, 50 * s)
    t.circle(350 * s, 65)
    DegreeCurve(40, 70 * s)
    t.circle(150 * s, 50)
    DegreeCurve(20, 50 * s, -1)
    t.circle(400 * s, 60)
    DegreeCurve(18, 50 * s)
    t.fd(250 * s)
    t.right(150)
    t.circle(-500 * s, 12)
    t.left(140)
    t.circle(550 * s, 110)
    t.left(27)
    t.circle(650 * s, 100)
    t.left(130)
    t.circle(-300 * s, 20)
    t.right(123)
    t.circle(220 * s, 57)
    t.end_fill()
    
    # 绘制花枝形状
    t.left(120)
    t.fd(280 * s)
    t.left(115)
    t.circle(300 * s, 33)
    t.left(180)
    t.circle(-300 * s, 33)
    DegreeCurve(70, 225 * s, -1)
    t.circle(350 * s, 104)
    t.left(90)
    t.circle(200 * s, 105)
    t.circle(-500 * s, 63)
    t.penup()
    t.goto(170 * s, -30 * s)
    t.pendown()
    t.left(160)
    DegreeCurve(20, 2500 * s)
    DegreeCurve(220, 250 * s, -1)
    
    # 绘制一个绿色叶子
    t.fillcolor('green')
    t.penup()
    t.goto(670 * s, -180 * s)
    t.pendown()
    t.right(140)
    t.begin_fill()
    t.circle(300 * s, 120)
    t.left(60)
    t.circle(300 * s, 120)
    t.end_fill()
    t.penup()
    t.goto(180 * s, -550 * s)
    t.pendown()
    t.right(85)
    t.circle(600 * s, 40)
    
    # 绘制另一个绿色叶子
    t.penup()
    t.goto(-150 * s, -1000 * s)
    t.pendown()
    t.begin_fill()
    t.rt(120)
    t.circle(300 * s, 115)
    t.left(75)
    t.circle(300 * s, 100)
    t.end_fill()
    t.penup()
    t.goto(430 * s, -1070 * s)
    t.pendown()
    t.right(30)
    t.circle(-600 * s, 35)
    t.done()
    t.end_fill()
    
  • 相关阅读:
    VS2008编写MFC程序--使用opencv2.4()
    November 02nd, 2017 Week 44th Thursday
    November 01st, 2017 Week 44th Wednesday
    October 31st, 2017 Week 44th Tuesday
    October 30th, 2017 Week 44th Monday
    October 29th, 2017 Week 44th Sunday
    October 28th, 2017 Week 43rd Saturday
    October 27th, 2017 Week 43rd Friday
    October 26th, 2017 Week 43rd Thursday
    October 25th, 2017 Week 43rd Wednesday
  • 原文地址:https://www.cnblogs.com/nickchen121/p/10825605.html
Copyright © 2011-2022 走看看