24小时热门版块排行榜    

查看: 419  |  回复: 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 的主题更新
普通表情 高级回复 (可上传附件)
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 301求调剂 +6 yy要上岸呀 2026-03-17 6/300 2026-03-17 23:58 by 星空星月
[考研] 材料与化工求调剂 +6 为学666 2026-03-16 6/300 2026-03-17 20:15 by peike
[考研] 299求调剂 +4 △小透明* 2026-03-17 4/200 2026-03-17 20:09 by peike
[考研] 268求调剂 +8 一定有学上- 2026-03-14 9/450 2026-03-17 17:47 by laoshidan
[考研] 293求调剂 +6 世界首富 2026-03-11 6/300 2026-03-17 17:04 by ruiyingmiao
[考研] 有没有道铁/土木的想调剂南林,给自己招师弟中~ +3 TqlXswl 2026-03-16 7/350 2026-03-17 15:23 by TqlXswl
[考研] 环境工程调剂 +6 大可digkids 2026-03-16 6/300 2026-03-16 17:16 by barlinike
[考研] 321求调剂 +5 大米饭! 2026-03-15 5/250 2026-03-16 16:33 by houyaoxu
[考研] 311求调剂 +5 26研0 2026-03-15 5/250 2026-03-16 16:21 by a不易
[考研] 0703一志愿211 285分求调剂 +5 ly3471z 2026-03-13 5/250 2026-03-16 16:16 by 哦哦123
[考研] 285求调剂 +6 ytter 2026-03-12 6/300 2026-03-16 15:05 by njzyff
[考研] 0703化学调剂 290分有科研经历,论文在投 +7 腻腻gk 2026-03-14 7/350 2026-03-16 10:12 by houyaoxu
[考研] 26考研一志愿中国石油大学(华东)305分求调剂 +3 嘉年新程 2026-03-15 3/150 2026-03-15 13:58 by 哈哈哈哈嘿嘿嘿
[考研] 080500,材料学硕302分求调剂学校 +4 初识可乐 2026-03-14 5/250 2026-03-14 21:08 by peike
[考研] 中科大材料专硕319求调剂 +3 孟鑫材料 2026-03-13 3/150 2026-03-14 18:10 by houyaoxu
[基金申请] 有必要更换申报口吗 20+3 fannyamoy 2026-03-11 3/150 2026-03-14 00:52 by zhanghaozhu
[考研] [0860]321分求调剂,ab区皆可 +4 宝贵热 2026-03-13 4/200 2026-03-13 22:01 by 星空星月
[考研] 求b区学校调剂 +3 周56 2026-03-11 3/150 2026-03-13 16:20 by JourneyLucky
[考研] 310求调剂 +3 【上上签】 2026-03-11 3/150 2026-03-13 16:16 by JourneyLucky
[考研] 化工学硕306求调剂 +9 42838695 2026-03-12 9/450 2026-03-13 10:16 by houyaoxu
信息提示
请填处理意见