学过编程的朋友一定编写过绘制图案的程序,函数曲线、杨辉三角形、金刚石、李萨茹图形等等。
数学教师会遇到关于数学图形如何绘制的问题,一般是从网上下载现成的Flash课件再插入PPT中播放。其实有些图形的绘制不需要难度较高的软件,直接在PPT中用简单的VBA编程便可搞定,并能得到极佳效果。
例如李萨茹曲线的绘制:
该曲线的轨迹是XY轴振幅不变,周期变化的二维谐振子运动,其数学表达式如下:
X=r1*sin(a*th)
Y=r2*sin(b*th)
0≤th≤2π
在PPT中用VBA编程演示:
制作方法:
1.插入控件:
2.按Alt+F11,打开Visual
Basic编辑器,插入模块,在代码区写入代码:
Private Sub Commanon1_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 Commanon2_Click()
With Application.ActivePresentation.Slides(1).Shapes
For
intShape = .Count To 1 Step -1
With .Item(intShape)
If .Type = msoLine Then .Delete
End With
Next
End With
End Sub
Private Sub Commanon3_Click()
Application.SlideShowWindows(1).View.Exit
End Sub
注:运行前先将宏的安全级别设降为“低”
该博文2009年12月3日发表于百度空间
加载中,请稍候......