python创建600×600画布,以画布中心为原点画坐标轴,并按以下公式绘制函数曲线:x=3×wh×t/(4×(1+t×t×t)),y=3xhh×t×t/(4×(1+t×t×t))
时间: 2023-07-15 11:15:30 浏览: 338
python 画函数曲线示例
5星 · 资源好评率100%
以下是实现该功能的 Python 代码:
```python
import tkinter as tk
# 创建画布
canvas_width = 600
canvas_height = 600
master = tk.Tk()
canvas = tk.Canvas(master, width=canvas_width, height=canvas_height)
canvas.pack()
# 坐标轴中心点
center_x = canvas_width / 2
center_y = canvas_height / 2
# 绘制坐标轴
canvas.create_line(0, center_y, canvas_width, center_y, fill="black") # x 轴
canvas.create_line(center_x, 0, center_x, canvas_height, fill="black") # y 轴
# 绘制函数曲线
wh = 100
hh = 100
t = -5
while t <= 5:
x = 3 * wh * t / (4 * (1 + t * t * t))
y = 3 * x * hh * t * t / (4 * (1 + t * t * t))
canvas.create_oval(center_x + x - 1, center_y - y - 1, center_x + x + 1, center_y - y + 1, fill="black")
t += 0.01
# 进入消息循环
tk.mainloop()
```
运行后,会打开一个窗口,显示绘画出来的函数曲线。
阅读全文