Python绘制樱花树 奥运五环

python绘制樱花树>-< !
提示:开始运行后过几秒

from turtle import *
from random import *
from math import *
class Tree:
    def __init__(self):
        setup(1000, 700)
        bgcolor(1, 1, 1)  # 背景色
        # ht()  # 隐藏turtle
        speed(10)  # 速度 1-10渐进,0 最快
        # tracer(1, 100)    # 设置绘图屏幕刷新频率,参数1设置在正常刷新频次的第参数1次刷新,参数2设置每次刷新的时延
        tracer(0, 0)
        pu()  # 抬笔
        backward(100)
        # 保证笔触箭头方向始终不向下,此处使其左转90度,而不是右转
        left(90)  # 左转90度
        backward(300)  # 后退300
    def tree(self, n, l):
        pd()  # 下笔
        # 阴影效果
        t = cos(radians(heading() + 45)) / 8 + 0.25
        pencolor(t, t, t)
        pensize(n / 1.2)
        forward(l)  # 画树枝
        if n > 0:
            b = random() * 15 + 10  # 右分支偏转角度
            c = random() * 15 + 10  # 左分支偏转角度
            d = l * (random() * 0.25 + 0.7)  # 下一个分支的长度
            # 右转一定角度,画右分支
            right(b)
            self.tree(n - 1, d)
            # 左转一定角度,画左分支
            left(b + c)
            self.tree(n - 1, d)
            # 转回来
            right(c)
        else:
            # 画叶子
            right(90)
            n = cos(radians(heading() - 45)) / 4 + 0.5
            pencolor(n, n * 0.8, n * 0.8)
            fillcolor(n, n * 0.8, n * 0.8)
            begin_fill()
            circle(3)
            left(90)
            end_fill()
            # 添加0.3倍的飘落叶子
            if random() > 0.7:
                pu()
                # 飘落
                t = heading()
                an = -40 + random() * 40
                setheading(an)
                dis = int(800 * random() * 0.5 + 400 * random() * 0.3 + 200 * random() * 0.2)
                forward(dis)
                setheading(t)
                # 画叶子
                pd()
                right(90)
                n = cos(radians(heading() - 45)) / 4 + 0.5
                pencolor(n * 0.5 + 0.5, 0.4 + n * 0.4, 0.4 + n * 0.4)
                fillcolor(n, n * 0.8, n * 0.8)
                begin_fill()
                circle(2)
                left(90)
                end_fill()
                pu()
                # 返回
                t = heading()
                setheading(an)
                backward(dis)
                setheading(t)
                # pass
        pu()
        backward(l)  # 退回
def main():
    tree = Tree()
    tree.tree(12, 100)  # 递归7层
    done()
if __name__ == '__main__':
    main()

奥运五环!!!

import turtle as t
t.pencolor("black")
t.width(10)
t.circle(100)#整圆
t.penup()
t.goto(150,0)
t.pencolor("blue")
t.pendown()
t.circle(100)
t.penup()
t.goto(-150,0)
t.pencolor("red")
t.pendown()
t.circle(100)
t.penup()
t.goto(-75,-150)
t.pencolor("green")
t.pendown()
t.circle(100)
t.penup()
t.goto(75,-150)
t.pencolor("yellow")
t.pendown()
t.circle(100)
t.end_fill()
t.exitonclick()

樱花树是借鉴一个不知名大佬的 >-< !

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值