猫史档案馆


【Python作品分享】函数图像绘制器【作品秀】

用户:用户名称7个字用户名称7个字查看:0 回复:2 评论:0 创建时间:2022-04-09T19:01:33


【作品展示】

center_image

 

【作品介绍】

哼哼哼啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊114514

 

【作品源代码】

# 跪求点赞,这个喵的坐标转换系统快把我脑浆榨干了
# 目前只有一次函数和二次函数
# 如果反响比较好我会接着弄反比例函数、三次函数、三角函数、反三角函数、对数函数和黎曼函数等
import turtle
import math
print("建议全屏海龟图")
print("")
print("注:有些取值夸张的函数可能会画不出来")
print("")
t = turtle.Pen()
t.pensize(2)
t.speed(0)
def Rectangular_Plane_Coordinate_System():
# 绘制坐标系
    t.penup()
    t.goto(-400,0)
    t.pendown()
    t.goto(400,0)
    t.write("x", font=("Arial", 24, "bold"))
    t.left(135)
    t.forward(10)
    t.backward(10)
    t.right(270)
    t.forward(10)
    t.backward(10)
    t.penup()
    t.goto(0,-400)
    t.left(225)
    t.pendown()
    t.goto(0,400)
    t.write("y", font=("Arial", 24, "bold"))
    t.left(135)
    t.forward(10)
    t.backward(10)
    t.right(270)
    t.forward(10)
    t.penup()
    t.goto(-400,0)
    t.pendown()
    bridge = -40
    t.left(45)
    for i in range(16):
        t.left(90)
        t.forward(7)
        t.write(bridge)
        t.right(180)
        t.forward(7)
        t.left(90)
        t.forward(50)
        bridge += 5
    bridge = -40
    t.up()
    t.goto(0,-400)
    t.down()
    t.left(90)
    p_bridge = -40
    for i in range(16):
        t.right(90)
        t.forward(7)
        t.write(p_bridge)
        t.left(180)
        t.forward(7)
        t.right(90)
        t.forward(50)
        p_bridge += 5
    p_bridge = -40

class function():

    def __init__(self,choice):
        self.choice = choice

        # 选择器
        if choice == "一次函数":
            x1 = int(input("请输入x最小值(大于-40小于0):"))
            x2 = int(input("请输入x最大值(小于40大于0):"))
            k = float(input("请输入k值:"))
            b = float(input("请输入b值(尽量在-40~40):"))
            x1 *= 10
            x2 *= 10
            b *= 10
            function.linear_function(x1,x2,k,b)
        if choice == "二次函数":
            x1 = int(input("请输入x最小值(大于-40小于0):"))
            x2 = int(input("请输入x最大值(小于40大于0):"))
            a = float(input("请输入a值:"))
            b = float(input("请输入b值:"))
            c = float(input("请输入c值:"))
            x1 *= 10
            x2 *= 10
            function.quadratic_function(x1, x2, a, b, c)

    # 一次函数主程序
    def linear_function(x1,x2,k,b):
        Rectangular_Plane_Coordinate_System()
        t.color("blue")
        t.penup()
        t.goto(x1,k*x1 + b)
        t.pendown()
        for i in range(x1,x2):
            y = k*i + b
            t.goto(i,y)
        t.penup()
        t.goto(0,b)
        t.dot(10,"red")
        t.write("(0,{})".format(b),align="left")
        t.goto(-(b/k),0)
        t.dot(10,"red")
        t.write("({},0)".format(-(b/k)),align="left")
        # 重置程序
        Type = input("请输入您想绘制的函数类型(目前只有一次函数和二次函数):")
        t.clear()
        t.setheading(0)
        t.color("black")
        f = function(Type)

    # 二次函数主程序
    def quadratic_function(x1,x2,a,b,c):
        Rectangular_Plane_Coordinate_System()
        t.color("red")
        t.penup()
        t.goto(x1,a*x1*x1 + b*x1 + c)
        t.pendown()
        for i in range(x1,x2):
            y = a*i*i + b*i + c
            t.goto(i*10,y*10)
        t.penup()
        t.goto(0,c*10)
        t.dot(10,"blue")
        t.write("(0,{})".format(c),align="left")
        # 重置程序
        Type = input("请输入您想绘制的函数类型(目前只有一次函数和二次函数):")
        t.clear()
        t.setheading(0)
        t.color("black")
        f = function(Type)


Type = input("请输入您想绘制的函数类型(目前只有一次函数和二次函数):")
f = function(Type)

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 1下一页
AlbertHackerAlbertHacker

【Albert--HackerAI智能评论】偶买噶?【帖子标题或正文含有@HackerAI即可召唤~定制方案喵community/436919】

点赞0


评论


用户名称7个字用户名称7个字

未经优化版本()

点赞0


评论