24小时热门版块排行榜    

查看: 411  |  回复: 0

Echo_hit

新虫 (小有名气)

[交流] 【求助】有关VB编写的sin光栅程序

谁能帮忙解释一下这段程序编写的sin光栅的思路,呼呼。。。
另外如果假如我输入周期=33,投影仪分辨率为1024*768。是不是光栅的周期是(768/33)pixel/line,若投射屏幕最终宽对应91.3cm,那么周期就是(913/33)mm/line。



Private Sub Command1_Click()
Dim c
Dim number As Integer
Dim du
Picture1.ScaleMode = 3 '设置picture控件使用 象素

Picture1.DrawWidth = 1 '设置在picture里画线,线使用的宽度为1象素
number = Picture1.Height '线条数目,如:显示器800*600即高600象素,画线时就画600条
du = 360 * Val(Text1) / number '每条所占的度数=360*周期/条数

For i = 0 To number
    c = 127.5 * ((Sin((du * i + Val(Text2.Text)) / 180 * 3.14)) + 1) 'du*i为第i条的度数,val(text2.text)是移象的度数,val函数是将字符转为数值
    Picture1.ForeColor = RGB(c, c, c)
    Picture1.Line (0, i)-(Picture1.Width, i) '画线,(0为起始点x,i起始点y)-(picture1.width为终点x,i为终点y)
Next
'Text1.SetFocus
End Sub
Private Sub Picture1_DblClick()
    Form2.Text1.Text = Text1.Text '保持两窗体的周期一样
    Form2.Text2.Text = Text2.Text '保持两窗体的移象度数一样
    Load Form2 '加载form2窗体
    Form2.Show
    Unload Me
End Sub

Private Sub Text2_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyLeft Then
    Text1.Text = Text1.Text - 1
ElseIf KeyCode = vbKeyRight Then
    Text1.Text = Text1.Text + 1
ElseIf KeyCode = vbKeyUp Then
    Text2.Text = Text2.Text + 90
ElseIf KeyCode = vbKeyDown Then
    Text2.Text = Text2.Text - 90
End If

End Sub

Private Sub Text2_KeyPress(KeyAscii As Integer)
If (KeyAscii <= Asc(9) And KeyAscii >= Asc(0)) Or KeyAscii = 8 Or KeyAscii = Asc("." Then
Else
    KeyAscii = 0
End If
End Sub
Private Sub Timer1_Timer() '定时刷新,1秒
If Text1.Text = "" Then Text1.Text = 0
If Text2.Text = "" Then Text2.Text = 0
Command1_Click
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer) '限制键盘输入,只允许0-1或退格键或.
If (KeyAscii <= Asc(9) And KeyAscii >= Asc(0)) Or KeyAscii = 8 Or KeyAscii = Asc("." Then
Else
    KeyAscii = 0
End If
End Sub
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyLeft Then '键盘方向键,向左,减一周期
    Text1.Text = Text1.Text - 1
ElseIf KeyCode = vbKeyRight Then
    Text1.Text = Text1.Text + 1
ElseIf KeyCode = vbKeyUp Then '键盘方向键,向上,加5度
    Text2.Text = Text2.Text + 90
ElseIf KeyCode = vbKeyDown Then
    Text2.Text = Text2.Text - 90
End If
End Sub
回复此楼

» 猜你喜欢

兰生幽谷,不因无人而不芳
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 Echo_hit 的主题更新
普通表情 高级回复 (可上传附件)
信息提示
请填处理意见