如何用vb画出简易函数图像

如何用vb画出简易函数图像,第1张

用vb画出简易函数图像的 *** 作步骤为:

(1)新建一个工程,新建一个Form1,在上面添加一个picture控件和一个command控件;

(2)选中此控件,右击"复制",在窗体空白处右击"粘贴",在d出的对话框中选择"是",创建了一个Command控件数组,复制,使窗体上总共出现7个Command控件;

(3)复制代码:

Const Pi = 3.1415926535 '定义圆周率

Dim a, wor

Dim i As Integer

Static Function Loge(X)

Loge = Log(X) / Log(Exp(1))

End Function

'定义用于在Picture1上的一个位置打印字符函数

Private Function PrintWord(X, y, Word As String)

With Picture1

.CurrentX = X

.CurrentY = y

.ForeColor = RGB(0, 0, 255)

End With

Picture1.Print Word

End Function

Private Function DrawDot(Px, Py, Color)

Picture1.PSet (Px, Py), Color

End Function

Sub XY() '建立直角坐标系

Picture1.DrawWidth = 1 '设置线条宽度

Picture1.Cls

'设定用户坐标系,坐标原点在Picture1中心

Picture1.Scale (-10, 10)-(10, -10)

Picture1.Line (-10, 0)-(10, 0), RGB(0, 0, 255)

Picture1.Line -(9.5, 0.5), RGB(0, 0, 255)

Picture1.Line (10, 0)-(9.5, -0.5), RGB(0, 0, 255)

Picture1.ForeColor = RGB(0, 0, 255)

Picture1.Print "X"

'画 X 轴

Picture1.Line (0, -10)-(0, 10), RGB(0, 0, 255)

Picture1.Line -(0.5, 9.5), RGB(0, 0, 255)

Picture1.Line (0, 10)-(-0.5, 9.5), RGB(0, 0, 255)

Picture1.Print "Y"

'画 Y 轴

For lin = -9 To 9

Picture1.Line (lin, 0)-(lin, 0.25)

wor = PrintWord(lin - 0.5, -0.5, Str(lin))

Picture1.Line (0, lin)-(-0.25, lin)

If lin <>0 Then

wor = PrintWord(-0.9, lin, Str(lin))

End If

Next lin

Picture1.DrawWidth = 2

End Sub

Private Sub Command1_Click(Index As Integer)

Select Case Index

Case 0

For a = -3 To 3 Step Pi / 6000

Dot = DrawDot(a, a ^ 2, RGB(0, 0, 0))

Next a

wor = PrintWord(4, 9, "二次曲线 y=x^2")

Case 1

For a = -9 To 9 Step Pi / 6000

Dot = DrawDot(a, a, RGB(0, 0, 0))

Next a

wor = PrintWord(8, 5, "一次曲线 y=x")

Case 2

For a = -9 To 3 Step Pi / 6000

Dot = DrawDot(a, Exp(a), RGB(0, 0, 0))

Next a

wor = PrintWord(4, 9, "指数曲线 y=e^x")

Case 3

For a = 0.0001 To 9 Step Pi / 6000

Dot = DrawDot(a, Loge(a), RGB(0, 0, 0))

Next a

wor = PrintWord(8, 3, "对数曲线 y=ln x")

Case 4

For a = -10 To 10 Step Pi / 6000

Dot = DrawDot(a, Sin(a), RGB(0, 0, 0))

Next a

wor = PrintWord(-5, 2, "正弦曲线 y=sin x")

Case 5

For a = -10 To 10 Step Pi / 6000

Dot = DrawDot(a, Cos(a), RGB(0, 0, 0))

Next a

wor = PrintWord(-9, 2, "余弦曲线 y=cos x")

Case 6

XY

End Select

End Sub

Private Sub Form_Load()

Me.Caption = "数学函数作图?quot"

Me.Show

Me.AutoRedraw = True

Picture1.AutoRedraw = True

Command1(0).Caption = "二次曲线"

Command1(1).Caption = "一次曲线"

Command1(2).Caption = "指数曲线"

Command1(3).Caption = "对数曲线"

Command1(4).Caption = "正弦曲线"

Command1(5).Caption = "余弦曲线"

Command1(6).Caption = "清空"

XY

End Sub

Private Sub Form_Resize()

Picture1.Width = Me.Width * 0.94

Picture1.Height = Me.Height - (Command1(0).Height * 4 + 100)

Command1(0).Top = Me.Height - (Command1(0).Height * 2.5 + 100)

Command1(0).Left = Me.Width * 0.01

For i = 1 To 6

Command1(i).Top = Me.Height - (Command1(0).Height * 2.5 + 100)

Command1(i).Left = Command1(i - 1).Left + 1000

Next

XY

End Sub

一般的vb画函数图像,用的是pset()函数

如你要画y=3*x

(x从1到3)

可以用

for

x=1

to

3

step=0.01

'步伐越小画得越精细

y=3*x

form1.pset(x,y)

next

x

就可以画出该图像来了,其他的函数的画法也一样的


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/8109414.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-13
下一篇 2023-04-13

发表评论

登录后才能评论

评论列表(0条)

保存