VBA编程实例----绘制李萨茹图形
VBA编程
VBA编程实例----绘制李萨茹图形
学过编程的朋友⼀定编写过绘制图形的程序,函数曲线、杨辉三⾓形、⾦刚⽯、李萨茹图形等等。
数学⽼师会遇到很多关于数学图形的问题。有些图形⽤VBA在PPT中绘制,不仅可以绘制图形⽽且还可以演⽰绘笔的运动轨迹,效果极佳。以下⽰例通过绘制“李萨茹图形”说明在PPT中通过VBA编程完成绘制函数曲线的⽅法。
李萨茹曲线是在X轴⽅向和Y轴⽅向振幅不变,但周期不同的⼆维谐振⼦运动的轨迹。数学表达式如下:
X=r1*sin(a*th)
Y=r2*sin(b*th)                      0≤th≤2π
演⽰效果:
添加控件:
源代码:
Private Sub CommandButton1_Click()
Const PI = 3.14
Dim a, b, gra, k As Integer
Dim th As Single
w = 400 '绘图区域宽度
h = 200 '绘图区域⾼度
a = TextBox1.Text
b = TextBox2.Text
k = 400 '画线的密度
For th = 0 To 2 * PI + 0.01 Step PI / k  'th:⾓度, 0≤ th ≥2π        x = 0.4 * w * Sin(a * th) + 365
y = 0.4 * h * Sin(b * th) + 270
With ActivePresentation.SlideShowWindow.View
.PointerColor = RGB(255, 0, 0)
.DrawLine x + 1, y, x, y + 1
End With
With ActivePresentation.Slides(1)
.Shapes.AddLine(x + 1, y, x, y + 1) _
.Line.ForeColor.RGB = RGB(255, 0, 0)
End With
Next
End Sub
Private Sub CommandButton2_Click()
With Application.ActivePresentation.Slides(1).Shapes
For intShape = .Count To 1 Step -1
With .Item(intShape)
vba编程免费教程
If .Type = msoLine Then .Delete
End With
Next
End With
End Sub
Private Sub CommandButton3_Click()
Application.SlideShowWindows(1).View.Exit
End Sub
.

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。