当前位置:   article > 正文

[Python]-python画一朵花

python画花开
import turtle
import math

def p_line(t, n, lenght, angle):
    for i in range(n):
        t.fd(lenght)
        t.lt(angle)

def polygon(t, n, length):
    angle = 360 / n
    p_line(t, n, length, angle)

def arc(t, r, angle):
    arc_lenght = 2 * math.pi * r * abs(angle) / 360
    n = int(arc_lenght / 4) + 1
    step_length = arc_lenght / n
    step_angle = float(angle) / n

    t.lt(step_angle / 2)
    p.line(t, n, step_angle,step_length)
    t.rt(step_angle / 2)

def petal(t, n, angle):
    for i in range(2):
        arc(t, r, angle)
        t.lt(180 - angle)


def flower(t, n, r, angle, p):
    for i in range(n):
        petal(t, n, angle)
        t.lt(p / n)


def leaf(t, r, angle, p):
    t.bengin_fill()
    t.down()
    flower(t, 1, r, angle, p)
    t.end_fill()


def main():
    window = turtle.Screen()
    window.bgcolor('white')
    window.title('Draw a flower')
    lucy = turtle.Turtle()
    lucy.shape('turtle')
    lucy.color('red')
    lucy.write(3)

    flower(lucy, 7, 60, 100, 360)

    lucy.color('brown')
    lucy.rt(90)
    lucy.fd(200)

    lucy.width(1)
    lucy.rt(270)
    lucy.color('green')
    leaf(lucy, 40, 80, 180)
    lucy.rt(140)
    lucy.color('black')
    lucy.fd(30)
    lucy.lt(180)
    lucy.fd(300)

    lucy.rt(120)
    lucy.color('green')
    leaf(lucy, 40, 80, 180)
    lucy.color('black')
    lucy.rt(140)
    lucy.fd(30)
    lucy.ht()
    window.exitonclick()

 

转载于:https://www.cnblogs.com/chenwz/p/10456735.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/70963?site
推荐阅读
相关标签
  

闽ICP备14008679号