前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >用turtle库绘制图形(chaos)

用turtle库绘制图形(chaos)

作者头像
hacker707
发布2022-11-27 10:32:40
4300
发布2022-11-27 10:32:40
举报

✅作者简介:大家好我是hacker707,大家可以叫我hacker 📃个人主页:hacker707的csdn博客 🔥系列专栏:python基础教程 💬推荐一款模拟面试、刷题神器👉点击跳转进入网站

在这里插入图片描述
在这里插入图片描述

使用Turtle库绘制图形实例如下:

from turtle import *

N = 80


def f(x):
    return 3.9 * x * (1 - x)


def g(x):
    return 3.9 * (x - x ** 2)


def h(x):
    return 3.9 * x - 3.9 * x * x


def jumpto(x, y):
    penup()
    goto(x, y)


def line(x1, y1, x2, y2):
    jumpto(x1, y1)
    pendown()
    goto(x2, y2)


def coosys():
    line(-1, 0, N + 1, 0)
    line(0, -0.1, 0, 1.1)


def plot(fun, start, color):
    pencolor(color)
    x = start
    jumpto(0, x)
    pendown()
    dot(5)
    for i in range(N):
        x = fun(x)
        goto(i + 1, x)
        dot(5)


def main():
    reset()
    setworldcoordinates(-1.0, -0.1, N + 1, 1.1)
    speed(0)
    hideturtle()
    coosys()
    plot(f, 0.35, "blue")
    plot(g, 0.35, "green")
    plot(h, 0.35, "red")
    # Now zoom in:
    for s in range(100):
        setworldcoordinates(0.5 * s, -0.1, N + 1, 1.1)
    return "Done!"


if __name__ == "__main__":
    main()
    mainloop()

运行结果如下:

在这里插入图片描述
在这里插入图片描述
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2022-07-29,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档