猫史档案馆


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

用户:单纯的疾风雀bps6单纯的疾风雀bps6查看:0 回复:2 评论:0 创建时间:2022-04-04T21:45:28


【作品展示】

center_image

 

【作品介绍】

功能:绘制函数图像,帮助同学更好的理解函数特性

 

【作品源代码】

import turtle as t
import easygui as e
import math as m
t.hideturtle()
t.speed(0)
c = e.buttonbox(msg='选择一种函数', title=' ', choices=('一次', '二次', '指数', 'sin', 'cos',  '对数', '反比例'))
if c == '一次':
    sj = e.multenterbox('y=ax+b', None, ['a=', 'b='])
    def y(x):
        return float(sj[0])*x+float(sj[1])*50
elif c == '二次':
    sj = e.multenterbox('y=ax^2+bx+c', None, ['a=', 'b=', 'c='])
    def y(x):
        return float(sj[0])*(x*0.1)**2+float(sj[1])*x*0.5+int(sj[2])*5
elif c == '指数':
    sj = e.multenterbox('y=a^x', None, ['a='])
    def y(x):
        return float(sj[0])**x
elif c == 'sin':
    sj = e.multenterbox('y=Asin(wx+K)+B', None, ['A=', 'w=', 'k=', 'B='])
    def y(x):
        return float(sj[0])*m.sin(float(sj[1])*x*0.05+float(sj[2])*20)+int(sj[3])*5
elif c == 'cos':
    sj = e.multenterbox('y=Acos(wx+K)+B', None, ['A=', 'w=', 'k=', 'B='])
    def y(x):
        return float(sj[0])*m.cos(float(sj[1])*x*0.05+float(sj[2])*20)+int(sj[3])*5
elif c == '对数':
    sj = e.buttonbox('y=loga(x)', None, choices=('y=log2(x)', 'y=log10(x)'))
    if sj == 'y=log2(x)':
        def y(x):
            if x>0:
                return m.log2(x)*30
            else:
                return 0
    if sj == 'y=log10(x)':
        def y(x):
            if x>0:
                return m.log10(x)*30
            else:
                return 0
elif c == '反比例':
    sj = e.multenterbox('y=k/ax', None, ['a=', 'k='])
    def y(x): 
        if x !=0:
            return (1/(float(sj[0])*x))*float(sj[1])*200
        else:
            return 0
t.speed(0)
t.goto(0, 500)
t.goto(0, (-500))
t.goto(0, 0)
t.goto(800, 0)
t.goto((-800), 0)
t.penup()
t.goto((-800), y(-800))
t.pendown()
for i in range(-800, 800):
    if y(i) >= 999 or y(i) <= -999 or i==0:
        continue
    t.goto(i, y(i))
t.done()

 

【提示】

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

https://python.codemao.cn


回复

上一页1 页 / 共 1下一页
单纯的疾风雀bps6单纯的疾风雀bps6

希望大家可以指出不足之处,共同进步

点赞0


评论


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

可以尝试把刻度表上

点赞0


评论