模拟电子钟 带语音报时功能
Private Function huamiao ( a As Integer )
'用同背景相同的颜色,在前一次的位置上,从新画直线,抹除前一次画的线 x =(1–Sin((a+1)/60*2*3.1415926))*(Form1.ScaleHeight/2–200)+200 y =(1–Cos((a+1)/60*2*3.1415926))*(Form1.ScaleHeight/2–200)+200
Line(Form1.ScaleHeight/2,Form1.ScaleHeight/2)-(x,y),QBColor ( 7 ) '然后开始画後一秒的线
x =(1–Sin(a/60 * 2 * 3.1415926 ) ) * (Form1.ScaleHeight/2–200)+200 y =(1–Cos(a/60 * 2 * 3.1415926 ) ) * (Form1.ScaleHeight/2–200)+200 Line(Form1.ScaleHeight/2,Form1.ScaleHeight/2)-(x,y),QBColor ( 1 ) huamiao = a - 1 End Function
Private Sub Timer1 _ Timer ( ) mz =Second(time)
mz =60–mz ‘因为三角函数中,角度的变化方向,正好与钟表的方向相反,
‘所以60减去就相当于将角度变为负值,也就是说,和原来的角度增长方向正好相反,与钟表的增长方向相同。 mz = huamiao ( mz ) End Sub
下面是运行效果:
好了,现在我们可以加上,分针和时针了.下面是源代码和运行结果:
' = = = = = = = = = = = = = = = = = = = = = = ' 以下语句能画出表盘 ‘ 六十个点表示六十个刻度,
' = = = = = = = = = = = = = = = = = = = = = = Private Sub huayuan ( ) Dim x As Double Dim y As Double
For i = 0 To 60
x = ( 1 – Sin ( i / 60 * 2 * 3.1415926 ) ) * ( Form1.ScaleHeight / 2 – 100 ) + 100 y = ( 1 – Cos ( i / 60 * 2 * 3.1415926 ) ) * ( Form1.ScaleHeight / 2 – 100 ) + 100 PSet ( x , y ) , QBColor ( 12 ) Next i
End Sub
‘ = = = = = = = = = = = = = = = = = = = = = = = = = = ‘下面代码作用是画出时针走的路线 ‘时针是12个刻度,表示是12个钟点
‘ = = = = = = = = = = = = = = = = = = = = = = = = = = Private Function xianshishi ( a As Integer ) '抹除前一次画的线