zoukankan      html  css  js  c++  java
  • [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()
  • 相关阅读:
    安装jar包到本地仓库和远程仓库
    服务之间的资源权限校验
    函数指针
    malloc分配内存
    cuda_vs_报错无法解析的外部错误
    c语言读写文件
    C++使用using namespace std报错分析与解决方案
    MPI环境配置
    c语言学习
    openMP
  • 原文地址:https://www.cnblogs.com/chenwz/p/10456735.html
Copyright © 2011-2022 走看看