在Visual Basic 6中旋转一行

时间:2014-12-21 17:51:48

标签: vb6

我想要一条线旋转。我研究了pi和radians,我制作了自己的算法(如果我可以这样称呼它)。我不喜欢使用互联网上已有的代码。我想单独发现它们,但使用逻辑。这是代码:

Dim pi As Double
Dim a, b, c, d, e, x, y As Double
Dim speed, radius As Integer

   Private Sub Form_Load()
       pi = 3.14159265358979
       speed = 1
       radius = 600
   End Sub

   Private Sub Command1_Click()

       Timer1.Enabled = Not Timer1.Enabled
       If Timer1.Enabled = True Then
           Command1.Caption = "Stop"
       Else
           Command1.Caption = "Start"
       End If
   End Sub


   Private Sub Timer1_Timer()

       ForeColor = vbWhite
       timer1.interval=speed
       Refresh

       a = a + 2
       b = Sin((a * pi) / 180)
       c = Cos((a * pi) / 180)
       y = radius * b
       x = radius * c

       Call Label1.Move(6240 + x, 4200 + y)
       If Left(b, 1) = "-" Then
           Label1.Caption = "---"
       Else
           Label1.Caption = "+++"
       End If

       If Left(c, 1) = "-" Then
           Label1.Caption = Label1.Caption & " " & "---"
       Else
           Label1.Caption = Label1.Caption & " " & "+++"
       End If

       Line (3000 + x, 4200 + y)-(6240 + x, 4200 + y)
       Line (3000, 4200)-(3000 + x, 4200 + y)
       Line (6240, 4200)-(6240 + x, 4200 + y)

       For d = 3000 To 6240
           Line (d, 4200)-(3000 + x, 4200 + y)
       Next

       For e = 3000 + x To 6240 + x
           Line (e, 4200 + y)-(6240, 4200)
       Next

   End Sub

我想在x轴上旋转线,而不是z(看起来是z)。我重新计算了一切,但我看不出问题出在哪里。什么是解释公式?

1 个答案:

答案 0 :(得分:2)

我相信你是在追求以下效果:

Option Explicit

Dim D As Long, S As Long, Y As Long

Private Sub Command1_Click()

    Timer1.Enabled = Not Timer1.Enabled
    If Timer1.Enabled = True Then
        Command1.Caption = "Stop"
    Else
        Command1.Caption = "Start"
    End If

End Sub

Private Sub Form_Load()

    D = 1 'Start going down; change to 0 to start going up instead
    Y = 100 'Mid point

End Sub

Private Sub Timer1_Timer()

    If S Then
        If S = 8 Then
            S = 0
        Else
            S = S + 1
            lblRate = "0"
            Exit Sub
        End If
    End If
    Refresh
    If D Then
        If Y < 200 Then
            Select Case Y
            Case Is < 20
                'Begin to accelerate
                Y = Y + 1
                lblRate = "+1"
            Case Is < 40
                'Continue to accelerate
                Y = Y + 2
                lblRate = "+2"
            Case Is < 160
                'Set acceleration to peak
                Y = Y + 3
                lblRate = "+3"
            Case Is < 180
                'Begin to decelerate
                Y = Y + 2
                lblRate = "+2"
            Case Else
                'Continue to decelerate
                Y = Y + 1
                lblRate = "+1"
            End Select
        Else
            'Stop and reverse direction
            D = 0
            S = 1
            lblRate = "0"
        End If
    Else
        If Y > 0 Then
            Select Case Y
            Case Is < 20
                'Begin to accelerate
                Y = Y - 1
                lblRate = "-1"
            Case Is < 40
                'Continue to accelerate
                Y = Y - 2
                lblRate = "-2"
            Case Is < 160
                'Set acceleration to peak
                Y = Y - 3
                lblRate = "-3"
            Case Is < 180
                'Begin to decelerate
                Y = Y - 2
                lblRate = "-2"
            Case Else
                'Continue to decelerate
                Y = Y - 1
                lblRate = "-1"
            End Select
        Else
            'Stop and reverse direction
            D = 1
            S = 1
        End If
    End If
    Line (120, 100)-(120, Y)

End Sub

虽然技术上并未遵循正确计算的曲率,但它更像是围绕X轴旋转的简化版本。

此外,请确保使用像素比例模式而不是Twips,以获得更好的绘图性能。