主题:完善的超酷模拟时钟(源代码已上传,附详解)希望大家共同完善
利用三角函数计算坐标打点画图编写的模拟时钟 [em1]
其实很简单,只用画出指针各点坐标,源代码已经重新上传到附件,希望大家共同完善!
'详细解释代码如下:
Dim pi As Single, XX As Single, YY As Integer, XX1 As Single, YY1 As Single
Dim PX As Single, PY As Single
'计算通过半径和角度计算指针各点坐标
Sub aa(r As Integer, a As Single)
XX = r * Sin(a) + PX
YY = PY - r * Cos(a)
End Sub
'图方便多写一个重载
Sub aa1(r As Integer, a As Single)
XX1 = r * Sin(a) + PX
YY1 = PY - r * Cos(a)
End Sub
Private Sub Form_Activate()
Call Timer1_Timer
End Sub
Private Sub Form_Load()
pi = 3.14159265358979
'圆心位置初始化
PX = Me.Width / 2 - 25
PY = Me.Height / 2 - 400
End Sub
Private Sub Timer1_Timer()
Form1.Cls
Form1.ForeColor = 5977634
Form1.DrawWidth = 1
Dim i As Single, j As Integer
'画时针
Form1.DrawWidth = 15
i = Hour(Now) + Minute(Now) / 60
'通过循环打点画出从粗到细指针效果
For j = 0 To 1700 Step 10
Call aa(j, pi * i / 6) '计算指针各点坐标
If j Mod 150 = 0 And Form1.DrawWidth > 1 Then
Form1.DrawWidth = Form1.DrawWidth - 1 '调节指针粗细分布
End If
Form1.PSet (XX, YY) '画点
Next j
'画分针
Form1.DrawWidth = 10
i = Minute(Now) + Second(Now) / 60
Form1.ForeColor = &H800000
For j = 0 To 2500 Step 10
Call aa(j, pi * i / 30)
If j Mod 350 = 0 And Form1.DrawWidth > 1 Then
Form1.DrawWidth = Form1.DrawWidth - 1
End If
Form1.PSet (XX, YY)
Next j
'画秒针
Form1.ForeColor = &H8000&
Form1.DrawWidth = 10
i = Second(Now)
'画秒针从尾半截到圆心
For j = 600 To 0 Step -10
Call aa1(j, pi * i / 30 + pi)
If j Mod 200 = 0 And Form1.DrawWidth > 5 Then
Form1.DrawWidth = Form1.DrawWidth - 1
End If
Form1.PSet (XX1, YY1)
Next j
'画秒针从圆心到针尖
For j = 0 To 3050 Step 10
Call aa(j, pi * i / 30)
If j Mod 750 = 0 And Form1.DrawWidth > 1 Then
Form1.DrawWidth = Form1.DrawWidth - 1
End If
Form1.PSet (XX, YY)
Next j
'处理圆心效果
Form1.DrawWidth = 25
Form1.PSet (PX, PY)
Form1.ForeColor = &H404040
Form1.DrawWidth = 15
Form1.PSet (PX, PY)
Form1.ForeColor = &HE0E0E0
Form1.DrawWidth = 5
Form1.PSet (PX, PY)
End Sub
[em1][em1][em1][em1]
其实很简单,只用画出指针各点坐标,源代码已经重新上传到附件,希望大家共同完善!
'详细解释代码如下:
Dim pi As Single, XX As Single, YY As Integer, XX1 As Single, YY1 As Single
Dim PX As Single, PY As Single
'计算通过半径和角度计算指针各点坐标
Sub aa(r As Integer, a As Single)
XX = r * Sin(a) + PX
YY = PY - r * Cos(a)
End Sub
'图方便多写一个重载
Sub aa1(r As Integer, a As Single)
XX1 = r * Sin(a) + PX
YY1 = PY - r * Cos(a)
End Sub
Private Sub Form_Activate()
Call Timer1_Timer
End Sub
Private Sub Form_Load()
pi = 3.14159265358979
'圆心位置初始化
PX = Me.Width / 2 - 25
PY = Me.Height / 2 - 400
End Sub
Private Sub Timer1_Timer()
Form1.Cls
Form1.ForeColor = 5977634
Form1.DrawWidth = 1
Dim i As Single, j As Integer
'画时针
Form1.DrawWidth = 15
i = Hour(Now) + Minute(Now) / 60
'通过循环打点画出从粗到细指针效果
For j = 0 To 1700 Step 10
Call aa(j, pi * i / 6) '计算指针各点坐标
If j Mod 150 = 0 And Form1.DrawWidth > 1 Then
Form1.DrawWidth = Form1.DrawWidth - 1 '调节指针粗细分布
End If
Form1.PSet (XX, YY) '画点
Next j
'画分针
Form1.DrawWidth = 10
i = Minute(Now) + Second(Now) / 60
Form1.ForeColor = &H800000
For j = 0 To 2500 Step 10
Call aa(j, pi * i / 30)
If j Mod 350 = 0 And Form1.DrawWidth > 1 Then
Form1.DrawWidth = Form1.DrawWidth - 1
End If
Form1.PSet (XX, YY)
Next j
'画秒针
Form1.ForeColor = &H8000&
Form1.DrawWidth = 10
i = Second(Now)
'画秒针从尾半截到圆心
For j = 600 To 0 Step -10
Call aa1(j, pi * i / 30 + pi)
If j Mod 200 = 0 And Form1.DrawWidth > 5 Then
Form1.DrawWidth = Form1.DrawWidth - 1
End If
Form1.PSet (XX1, YY1)
Next j
'画秒针从圆心到针尖
For j = 0 To 3050 Step 10
Call aa(j, pi * i / 30)
If j Mod 750 = 0 And Form1.DrawWidth > 1 Then
Form1.DrawWidth = Form1.DrawWidth - 1
End If
Form1.PSet (XX, YY)
Next j
'处理圆心效果
Form1.DrawWidth = 25
Form1.PSet (PX, PY)
Form1.ForeColor = &H404040
Form1.DrawWidth = 15
Form1.PSet (PX, PY)
Form1.ForeColor = &HE0E0E0
Form1.DrawWidth = 5
Form1.PSet (PX, PY)
End Sub
[em1][em1][em1][em1]