VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Analog clock with shortest code !!!

by Truong - VietNam (1 Submission)
Category: Math/Dates
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Thu 14th June 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Analog clock with shortest code !!!

Rate Analog clock with shortest code !!!




'Get time and draw 3 index step by step
Private Sub Run(O As Object)
  Const PI  As Single = 3.1415
  Dim NewTime As Single
  Dim GocH As Single, GocM As Single, GocS As Single
  Dim H As Single, M As Single, S As Single
  Dim r As Single
  
  NewTime = Time
  
  H = Hour(NewTime)
  M = Minute(NewTime)
  S = Second(NewTime)
  
  GocH = PI * ((H Mod 12) / 6 + M / 360 + S / 4320)
  GocM = PI * (M / 30 + S / 1800)
  GocS = PI * ((Timer + 1.7) / 30)
  
  O.Cls
    
  If (O.ScaleHeight < O.ScaleWidth) Then r = O.ScaleHeight / 2 Else r = O.ScaleWidth / 2
  
  VeKim O, 3.5 * r / 5, GocH, vbBlue, 6     'Kim gio:Hour index
  VeKim O, 5 * r / 6, GocM, vbDesktop, 3  'Kim phut:Min index
  VeKim O, r, GocS, vbRed, 1                  'Kim giay: Sec index
  VeKim O, r / 6, PI + GocS, vbRed, 2      'Duoi kim giay: Tag of Sec index
  Me.Caption = Time
End Sub

'Draw index
Private Sub VeKim(O As Object, r As Single, Goc As Single, Mau As Long, Size As Single)
  Dim Xo As Single, Yo As Single, X As Single, Y As Single
  
  Xo = O.ScaleWidth / 2
  Yo = O.ScaleHeight / 2
  
  X = Xo + r * Sin(Goc)
  Y = Yo - r * Cos(Goc)
  
  O.ForeColor = Mau
  O.DrawWidth = Size
  O.Line (Xo, Yo)-(X, Y)
  
End Sub

Private Sub Form_Resize()
  Run Me
End Sub

Private Sub Timer1_Timer()
  Run Me
End Sub


Download this snippet    Add to My Saved Code

Analog clock with shortest code !!! Comments

No comments have been posted about Analog clock with shortest code !!!. Why not be the first to post a comment about Analog clock with shortest code !!!.

Post your comment

Subject:
Message:
0/1000 characters