五月吧论坛【 畅心家园 】[ 音画长廊 ] → 臭老头,来学python画画了!!!

  共有576人关注过本帖树形打印复制链接

主题:臭老头,来学python画画了!!!

美女呀,离线,留言给我吧!
王贞仪
  1楼 二褂中级  242帖  2022/10/14 23:11:56 注册|搜索|短信|好友|勋章|藏票|洗衣||我的勋章


:足行万里书万卷 点击进入抢亲页面公孙龙 点击进入五月兵器几何原本 今日帖数:今日0 帖 点击参与风云风云465-5 届 如是我颠 如是我狂 如是我嗔 如是我媚 如是我妖 苏聍 叶小小 月琅琅 因风初苒苒 玉石满屋 琅孉 希声 二十四节气03惊蛰 红狐狸 豆蔻年华
臭老头,来学python画画了!!!  发帖心情 Post By:2023/5/10 18:45:01 [显示全部帖子]

刚刚忘记穿制服了
[此贴子已经被作者于2023-5-10 18:50:44编辑过]


回到顶部
美女呀,离线,留言给我吧!
王贞仪
  2楼 二褂中级  242帖  2022/10/14 23:11:56 注册|搜索|短信|好友|勋章|藏票|洗衣||我的勋章


:足行万里书万卷 点击进入抢亲页面公孙龙 点击进入五月兵器几何原本 今日帖数:今日0 帖 点击参与风云风云465-5 届 如是我颠 如是我狂 如是我嗔 如是我媚 如是我妖 苏聍 叶小小 月琅琅 因风初苒苒 玉石满屋 琅孉 希声 二十四节气03惊蛰 红狐狸 豆蔻年华
  发帖心情 Post By:2023/5/10 18:45:36 [显示全部帖子]

视频还在审核,先把代码放这里(出处https://zhuanlan.zhihu.com/p/448252423)

import turtle as tu

roo = tu.Turtle()  # 创建对象
wn = tu.Screen()  # 屏幕对象
wn.bgcolor("black")  # 屏幕背景
wn.title("分形树")
roo.left(90)  # 移动
roo.speed(20)  # 速度


def draw(l):  # 以长度'l'作为参数的递归函数
    if l < 10:
        return
    else:
        roo.pensize(2)  # 设置画笔大小
        roo.pencolor("yellow")  # 画笔颜色
        roo.forward(l)  # 朝向
        roo.left(30)  # 移动
        draw(3 * l / 4)  # 绘制
        roo.right(60)  # 移动
        draw(3 * l / 4)  # 绘制
        roo.left(30)  # 移动
        roo.pensize(2)
        roo.backward(l)  # 返回初始位置


draw(20)  # 绘制20次

roo.right(90)
roo.speed(2000)


# recursion
def draw(l):
    if (l < 10):
        return
    else:
        roo.pensize(2)
        roo.pencolor("magenta")  # magenta
        roo.forward(l)
        roo.left(30)
        draw(3 * l / 4)
        roo.right(60)
        draw(3 * l / 4)
        roo.left(30)
        roo.pensize(2)
        roo.backward(l)


draw(20)

roo.left(270)
roo.speed(2000)


# recursion
def draw(l):
    if (l < 10):
        return
    else:
        roo.pensize(2)
        roo.pencolor("red")  # red
        roo.forward(l)
        roo.left(30)
        draw(3 * l / 4)
        roo.right(60)
        draw(3 * l / 4)
        roo.left(30)
        roo.pensize(2)
        roo.backward(l)


draw(20)

roo.right(90)
roo.speed(2000)


# recursion
def draw(l):
    if (l < 10):
        return
    else:
        roo.pensize(2)
        roo.pencolor('#FFF8DC')  # white
        roo.forward(l)
        roo.left(30)
        draw(3 * l / 4)
        roo.right(60)
        draw(3 * l / 4)
        roo.left(30)
        roo.pensize(2)
        roo.backward(l)


draw(20)


########################################################

def draw(l):
    if (l < 10):
        return
    else:

        roo.pensize(3)
        roo.pencolor("lightgreen")  # lightgreen
        roo.forward(l)
        roo.left(30)
        draw(4 * l / 5)
        roo.right(60)
        draw(4 * l / 5)
        roo.left(30)
        roo.pensize(3)
        roo.backward(l)


draw(40)

roo.right(90)
roo.speed(2000)


# recursion
def draw(l):
    if (l < 10):
        return
    else:
        roo.pensize(3)
        roo.pencolor("red")  # red
        roo.forward(l)
        roo.left(30)
        draw(4 * l / 5)
        roo.right(60)
        draw(4 * l / 5)
        roo.left(30)
        roo.pensize(3)
        roo.backward(l)


draw(40)

roo.left(270)
roo.speed(2000)


# recursion
def draw(l):
    if (l < 10):
        return
    else:
        roo.pensize(3)
        roo.pencolor("yellow")  # yellow
        roo.forward(l)
        roo.left(30)
        draw(4 * l / 5)
        roo.right(60)
        draw(4 * l / 5)
        roo.left(30)
        roo.pensize(3)
        roo.backward(l)


draw(40)

roo.right(90)
roo.speed(2000)


# recursion
def draw(l):
    if (l < 10):
        return
    else:
        roo.pensize(3)
        roo.pencolor('#FFF8DC')  # white
        roo.forward(l)
        roo.left(30)
        draw(4 * l / 5)
        roo.right(60)
        draw(4 * l / 5)
        roo.left(30)
        roo.pensize(3)
        roo.backward(l)


draw(40)

def draw(l):
    if (l < 10):
        return
    else:

        roo.pensize(2)
        roo.pencolor("cyan")  # cyan
        roo.forward(l)
        roo.left(30)
        draw(6 * l / 7)
        roo.right(60)
        draw(6 * l / 7)
        roo.left(30)
        roo.pensize(2)
        roo.backward(l)


draw(60)

roo.right(90)
roo.speed(2000)


# recursion
def draw(l):
    if (l < 10):
        return
    else:
        roo.pensize(2)
        roo.pencolor("yellow")  # yellow
        roo.forward(l)
        roo.left(30)
        draw(6 * l / 7)
        roo.right(60)
        draw(6 * l / 7)
        roo.left(30)
        roo.pensize(2)
        roo.backward(l)


draw(60)

roo.left(270)
roo.speed(2000)


# recursion
def draw(l):
    if (l < 10):
        return
    else:
        roo.pensize(2)
        roo.pencolor("magenta")  # magenta
        roo.forward(l)
        roo.left(30)
        draw(6 * l / 7)
        roo.right(60)
        draw(6 * l / 7)
        roo.left(30)
        roo.pensize(2)
        roo.backward(l)


draw(60)

roo.right(90)
roo.speed(2000)


# recursion
def draw(l):
    if (l < 10):
        return
    else:
        roo.pensize(2)
        roo.pencolor('#FFF8DC')  # white
        roo.forward(l)
        roo.left(30)
        draw(6 * l / 7)
        roo.right(60)
        draw(6 * l / 7)
        roo.left(30)
        roo.pensize(2)
        roo.backward(l)


draw(60)
wn.exitonclick()
[此贴子已经被作者于2023-5-10 18:46:42编辑过]


回到顶部