根据端口输入的摩擦系数值,此值随时间不断变化,画曲线!横坐标为时间,单位为秒,间隔为30秒,纵轴为摩擦系数0.1为间隔,画出曲线.

解决方案 »

  1.   

    先给你个例子,另外一个实时采集的暂无法找到,请给消息提个醒,找到给你!
    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 SubPrivate 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 SubPrivate Sub Command5_Click() '清空屏幕
    XY
    End SubPrivate 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 SubPrivate Sub Form_Resize()
    'Picture1.Width = Me.Width * 0.94
    End Sub