编写一个完整的程序,要求如下: 创建正方形画布(建议600*600),以画布中心为原点画出坐标轴,按以下公式绘制函数曲线: x = wh×((1+cos(5t)+ sin2(4t))×sin(3t))/5 y = hh×((1+cos(2t)+ sin2(4t))×cos(3t))/5 其中wh、hh的取值分别为画布的半宽和半高,t的取值范围为0至2π,步长为0.01。
时间: 2024-02-21 15:56:43 浏览: 42
这里为您提供一个Python语言编写的程序,可以实现您所要求的功能:
```python
import tkinter as tk
import math
# 画布尺寸
WIDTH = 600
HEIGHT = 600
# 创建画布
root = tk.Tk()
canvas = tk.Canvas(root, width=WIDTH, height=HEIGHT, bg='white')
canvas.pack()
# 画坐标轴
canvas.create_line(WIDTH/2, 0, WIDTH/2, HEIGHT)
canvas.create_line(0, HEIGHT/2, WIDTH, HEIGHT/2)
# 计算函数曲线
wh = WIDTH / 2
hh = HEIGHT / 2
t = 0
x0 = wh * ((1 + math.cos(5*t) + math.sin(2*4*t)) * math.sin(3*t)) / 5 + wh
y0 = hh * ((1 + math.cos(2*t) + math.sin(2*4*t)) * math.cos(3*t)) / 5 + hh
while t < 2 * math.pi:
t += 0.01
x = wh * ((1 + math.cos(5*t) + math.sin(2*4*t)) * math.sin(3*t)) / 5 + wh
y = hh * ((1 + math.cos(2*t) + math.sin(2*4*t)) * math.cos(3*t)) / 5 + hh
canvas.create_line(x0, y0, x, y)
x0, y0 = x, y
# 运行主循环
root.mainloop()
```
运行程序后,您可以在窗口中看到一个正方形画布,中心为原点,带有坐标轴。程序会按照您所给出的函数公式绘制函数曲线,并在窗口中展示。