当前位置:编程学习 > VB >>

请教 请教

请问 :我要把这个雷达扫描动画程序   修改为 半圆 来回扫描效果   怎么修改啊? 希望各位高抬贵手,谢谢!!
Dim CAngle As Integer    'Current Angle (Not Class Angle)
  
Private Sub Form_Load()    '初始化
    CAngle = 0
    Me.BackColor = vbBlack
    Me.BorderStyle = 3
    Me.FillColor = vbYellow
    Me.ForeColor = vbGreen
    Me.FillStyle = 1
    Me.ScaleMode = 3       'Pixel
    Me.Width = 4590
    Me.Height = 4980
    Timer1.Interval = 10
End Sub
  
Private Sub Timer1_Timer()
    Cls
    Circle (150, 150), 130
    If CAngle = 179 Then CAngle = 0 Else CAngle = CAngle - 1
    Raida CAngle               '绘制雷达
    RaidaTarget 0.5, 20        '定义雷达目标1
    RaidaTarget 0.7, 200       '定义雷达目标2
    RaidaTarget 0.2, 100       '定义雷达目标3
    RaidaTarget 0.9, 257       '定义雷达目标4
End Sub
  
Private Sub Raida(ByVal angle As Integer)          '根据所给角度绘制雷达
    Dim x As Single, y As Single, a As Single, _
ae As Single, g As Integer
       
    g = 0
       
    ae = angle - 45
    For a = ae To angle
        x = Cos(D2R(a)) * 130 + 150
        y = Sin(D2R(a)) * 130 + 150
        g = (a - ae) / 20 * 255
        Line (150, 150)-(x, y), RGB(0, g, 0)
    Next a
End Sub
  
Private Sub RaidaTarget(ByVal Row As Single, ByVal Thita As Integer) '根据雷达扫描区域绘制目标
    Dim x As Integer, y As Integer
    x = Cos(D2R(Thita)) * Row * 130 + 150
    y = Sin(D2R(Thita)) * Row * 130 + 150
    Form1.FillStyle = 0
    If Me.Point(x, y) <> 0 Then Circle (x, y), 5, RGB(255, 255, 0)   '如果雷达扫到目标则显示
    Form1.FillStyle = 1
End Sub

Public Function D2R(ByVal d As Integer) As Single
    D2R = CDbl(d) * (3.14159265359 / 180)
End Function --------------------编程问答--------------------
Option Explicit
    Dim CAngle As Integer 'Current Angle (Not Class Angle)
   
Private Sub Form_Load() '初始化
    CAngle = 0
    Me.BackColor = vbBlack
    Me.BorderStyle = 3
    Me.FillColor = vbYellow
    Me.ForeColor = vbGreen
    Me.FillStyle = 1
    Me.ScaleMode = 3 'Pixel
    Me.Width = 4590
    Me.Height = 4980
    Timer1.Interval = 10
    Timer2.Interval = 10
    Timer2.Enabled = False
End Sub

Private Sub Timer2_Timer()
    Cls
    Circle (150, 150), 130
    If CAngle = 0 Then
        Timer2.Enabled = False
        Timer1.Enabled = True
    Else
        CAngle = CAngle + 1
    End If
    Raida CAngle '绘制雷达
    RaidaTarget 0.5, 20 '定义雷达目标1
    RaidaTarget 0.7, 200 '定义雷达目标2
    RaidaTarget 0.2, 100 '定义雷达目标3
    RaidaTarget 0.9, 257 '定义雷达目标4
End Sub
   
Private Sub Timer1_Timer()
    Cls
    Circle (150, 150), 130
    If CAngle < -180 Then
        Timer1.Enabled = False
        Timer2.Enabled = True
    Else
        CAngle = CAngle - 1
    End If
    Raida CAngle '绘制雷达
    RaidaTarget 0.5, 20 '定义雷达目标1
    RaidaTarget 0.7, 200 '定义雷达目标2
    RaidaTarget 0.2, 100 '定义雷达目标3
    RaidaTarget 0.9, 257 '定义雷达目标4
End Sub
   
Private Sub Raida(ByVal angle As Integer) '根据所给角度绘制雷达
    Dim x As Single, y As Single, a As Single, _
    ae As Single, g As Integer
    g = 0
    ae = angle - 45
    For a = ae To angle
    x = Cos(D2R(a)) * 130 + 150
    y = Sin(D2R(a)) * 130 + 150
    g = (a - ae) / 20 * 255
    Line (150, 150)-(x, y), RGB(0, g, 0)
    Next a
End Sub
   
Private Sub RaidaTarget(ByVal Row As Single, ByVal Thita As Integer) '根据雷达扫描区域绘制目标
    Dim x As Integer, y As Integer
    x = Cos(D2R(Thita)) * Row * 130 + 150
    y = Sin(D2R(Thita)) * Row * 130 + 150
    Form1.FillStyle = 0
    If Me.Point(x, y) <> 0 Then Circle (x, y), 5, RGB(255, 255, 0) '如果雷达扫到目标则显示
    Form1.FillStyle = 1
End Sub

Public Function D2R(ByVal d As Integer) As Single
    D2R = CDbl(d) * (3.14159265359 / 180)
End Function

补充:VB ,  控件
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,