如何用VB画出二次函数图像和波长图像

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/20 20:32:26
如何用VB画出二次函数图像和波长图像
xV[OA+l'5Ĵ iZj7ŅpKb4^R۠ZW.c3Oki؄lvfϜr섇3jusC.XI--{0VEp.ETWa7d2{rxM~VռL1\*%0 C;7>E8C{|!9o0UmpϢP0!rp.Wͩ}*_I!,Vue%42 %as֓Pbhn/L 4CR55 ya ΀< AW$y/7xLwxc ^QB8bq3$S#E[À+"ߪWgX`Vp ~_OJ>zBPYc5r5נ<4^Fo3|#M*Q[6*]]QFLz0*IPHZ6g2g.8>SKI{P;GErw.phG?Z?AT-v PJ,#%B[Z]j'0@xv{8(ȝo

如何用VB画出二次函数图像和波长图像
如何用VB画出二次函数图像和波长图像

如何用VB画出二次函数图像和波长图像
在窗体上放置一个名为 PicDraw 的图片框,两个按钮,分别命名为 CmdDrawQuad 与 CmdDrawWave,全部代码如下[Visual Basic 6.0]:
Option Explicit
'声明平面直角坐标系的左上角、右下角的坐标
Const sngCrdL_X As Single = -50
Const sngCrdL_Y As Single = 100
Const sngCrdR_X As Single = 100
Const sngCrdR_Y As Single = -50
'声明二次函数的解析式(Y = AX^2 + BX + C)
Const sngA As Single = 1 / 5
Const sngB As Single = 0
Const sngC As Single = 10
'
Sub Prepare()
Dim X As Long,Y As Long
PicDraw.Cls '清空图片框
PicDraw.Scale (sngCrdL_X,sngCrdL_Y)-(sngCrdR_X,sngCrdR_Y) '设置坐标
PicDraw.Line (sngCrdL_X,0)-(sngCrdR_X,0),vbBlue '绘制 X 轴
PicDraw.Line (0,sngCrdL_Y)-(0,sngCrdR_Y),vbBlue '绘制 Y 轴
For X = sngCrdL_X To sngCrdR_X
For Y = sngCrdR_Y To sngCrdL_Y
PicDraw.PSet (X,Y),vbCyan '绘制网格
Next Y
Next X
End Sub
Private Sub CmdDrawQuad_Click()
Prepare
Dim sngX As Single,sngY As Single
Dim LastX As Single,LastY As Single
Dim bDrawing As Boolean
For sngX = sngCrdL_X To sngCrdR_X Step 0.5
LastY = sngY
sngY = CalculateFunction(sngX,sngA,sngB,sngC) '计算与X坐标所对应的Y坐标
If bDrawing Then
PicDraw.Line (LastX,LastY)-(sngX,sngY) '绘制线段
End If
LastX = sngX
bDrawing = True
Next sngX
End Sub
Private Sub CmdDrawWave_Click()
Prepare
Dim sngX As Single,sngY As Single
Dim LastX As Single,LastY As Single
Dim bDrawing As Boolean
For sngX = sngCrdL_X To sngCrdR_X Step 0.5
LastY = sngY
sngY = CalculateWave(sngX,50,50) '计算与X坐标所对应的Y坐标
If bDrawing Then
PicDraw.Line (LastX,LastY)-(sngX,sngY) '绘制线段
End If
LastX = sngX
bDrawing = True
Next sngX
End Sub
声明一点,由于知识水平原因,CalculateWave函数是我自己摸索出来的,如果有问题,请告知,