发布网友
共2个回答
热心网友
Const Pi = 3.1415926535 '定义圆周率
Dim a, wor
'定义用于在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() '画正弦曲线
'用For循环绘点,使其按正弦规律变化。
'步长小,使曲线比较平滑,还能形成动画效果
For a = -2 * Pi To 2 * Pi Step Pi / 6000
Dot = DrawDot(a, Sin(a) * 5, RGB(0, 255, 0))
Next a
wor = PrintWord(3, -6, "正弦曲线 y=Sinx ")
End Sub
Private Sub Command2_Click()
For a = -2 * Pi To 2 * Pi Step Pi / 6000
Dot = DrawDot(a, Cos(a) * 5, RGB(255, 0, 0))
Next a
wor = PrintWord(4, 6, "余弦曲线 y=Cosx ")
End Sub
Private Sub Command3_Click()
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 ")
End Sub
Private Sub Command4_Click()
For a = -8 To 8 Step Pi / 6000
If a = 0 Then GoTo err0 '除数不能为0
Dot = DrawDot(a, 1 / a, RGB(255, 0, 255))
err0:
Next a
wor = PrintWord(6, 2, "双曲线 y=1/x ")
End Sub
Private Sub Command5_Click() '清空屏幕
XY
End Sub
Private Sub Form_Load()
Me.Caption = "数学函数作图 "
Me.Show
Me.AutoRedraw = True
Picture1.BackColor = vbWhite
Command1.Caption = "正弦曲线 "
Command2.Caption = "余弦曲线 "
Command3.Caption = "二次曲线 "
Command4.Caption = "双曲线 "
Command5.Caption = "清空 "
XY
End Sub
Private Sub Form_Resize()
'Picture1.Width = Me.Width * 0.94
End Sub
热心网友
设textbox名称为text1,再创建一个名为picture1的picturebox用于绘图,一个名为command1的按钮
Private Sub Command1_Click()
Dim y1(50) As Single
Dim y2(50) As Single '50是最大数据个数,改为实际值
Dim t, t0 As Single '时间
Dim str, str1
str = Split(Text1, Chr(13))
For i = 0 To UBound(str)
str1 = Split(Trim(str(i)))
y1(i) = Picture1.Top - str1(0)
y2(i) = Picture1.Top - str1(1)
t = 1000 * i '横坐标的放大比例
t0 = 1000 * (i - 1)
If i > 0 Then
Picture1.Line (t0, y1(i - 1))-(t, y1(i)), vbRed
Picture1.Line (t0, y2(i - 1))-(t, y2(i)), vbGreen
End If
Next
End Sub