Pages

Banner 468

Senin, 10 November 2008

membuat Jam analog

 
-buat satu form namanya form1
-copykan code dibawah ini ke form

Dim Ymouse, Xmouse, dy(30), dx(30), Da(30), Mo(30)
Dim Split1, Day1, Year1, Todaysdate, h, m, d, S, Face, Speed, n, scrll
Dim Dsplit, HandHeight, Handwidth, HandX, HandY, Step, currStep
Dim Test, ClockHeight, ClockWidth, ClockFromMouseY, ClockFromMouseX
Dim Fcol, Mcol, Scol, Hcol, Dcol
'############
'By:eko cahyono (Ym: eko_matrix)
'############

Private Type FL
T(30) As Long
Le(30) As Long
End Type
Dim FL As FL
Private Type HL
T(30) As Long
Le(30) As Long
End Type
Dim HL As HL
Private Type SL
T(30) As Long
Le(30) As Long
End Type
Dim SL As SL
Private Type ML
T(30) As Long
Le(30) As Long
End Type
Dim ML As ML
Private Type DL
T(30) As Long
Le(30) As Long
End Type
Dim DL As DL
Const PI = 3.1415

Private Declare Function GetActiveWindow Lib "user32" () As Long

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Const SW_SHOWNORMAL = 1

Private Sub Timer1_Timer()
dy(0) = dy(0) + (Ymouse - dy(0)) * Speed
dy(0) = Fix(dy(0))
dx(0) = dx(0) + (Xmouse - dx(0)) * Speed
dx(0) = Fix(dx(0))
For i = 1 To Len(d) - 1
dy(i) = dy(i) + (dy(i - 1) - dy(i)) * Speed
dy(i) = Fix(dy(i))
dx(i) = dx(i) + (dx(i - 1) - dx(i)) * Speed
dx(i) = Fix(dx(i))

Next i

secs = Second(Now)
sec = -1.57 + PI * secs / 30
Mins = Minute(Now)
Min = -1.57 + PI * Mins / 30
hr = Hour(Now)
hrs = -1.575 + PI * hr / 6 + PI * Int(Minute(Now)) / 360
For i = 0 To n - 2
FL.T(i) = dy(i) + ClockHeight * Sin(-1.0471 + i * Split1 * PI / 180) + scrll
FL.Le(i) = dx(i) + ClockWidth * Cos(-1.0471 + i * Split1 * PI / 180)

Next i

For i = 0 To Len(h) - 1
HL.T(i) = dy(i) + HandY + (i * HandHeight) * Sin(hrs) + scrll
HL.Le(i) = dx(i) + HandX + (i * Handwidth) * Cos(hrs)

Next i

For i = 0 To Len(m) - 1
ML.T(i) = dy(i) + HandY + (i * HandHeight) * Sin(Min) + scrll
ML.Le(i) = dx(i) + HandX + (i * Handwidth) * Cos(Min)

Next i

For i = 0 To Len(S) - 1
SL.T(i) = dy(i) + HandY + (i * HandHeight) * Sin(sec) + scrll
SL.Le(i) = dx(i) + HandX + (i * Handwidth) * Cos(sec)

Next i

For i = 0 To Len(d) - 1
DL.T(i) = dy(i) + ClockHeight * 1.5 * Sin(currStep + i * Dsplit * PI / 180) + scrll
DL.Le(i) = dx(i) + ClockWidth * 1.5 * Cos(currStep + i * Dsplit * PI / 180)

Next i

currStep = currStep - Step
P
End Sub

Private Function SP(ByVal ST As String, ByVal Nu As Integer, Optional K As Byte = 1) As String
SP = Mid(ST, Nu + 1, K)
End Function

Private Sub P()
Cls
With Form1 'Nama Form
.FontBold = False
.ForeColor = Dcol
For i = 0 To Len(d) - 1
.CurrentY = DL.T(i)
.CurrentX = DL.Le(i)
Print SP(d, i)
Next i
.ForeColor = Fcol
For i = 0 To n - 1
.CurrentY = FL.T(i)
.CurrentX = FL.Le(i)
If (i = 18 Or i = 20 Or i = 22) Then
Print SP(Face, i, 2)
i = i + 1
Else
Print SP(Face, i, 1)
End If
Next i
.FontBold = True
.ForeColor = Scol
For i = 0 To Len(S) - 1
.CurrentY = SL.T(i)
.CurrentX = SL.Le(i)
Print SP(S, i)
Next i
.ForeColor = Mcol
For i = 0 To Len(m) - 1
.CurrentY = ML.T(i)
.CurrentX = ML.Le(i)
Print SP(m, i)
Next i
.ForeColor = Hcol
For i = 0 To Len(h) - 1
.CurrentY = HL.T(i)
.CurrentX = HL.Le(i)
Print SP(h, i)
Next i
End With
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Ymouse = Y + ClockFromMouseY ':event.y+ClockFromMouseY;
Xmouse = X + ClockFromMouseX ':event.x+ClockFromMouseX;
End Sub

Private Sub Form_Load()
Timer1.Interval = 15
Me.BackColor = &H808080
Dcol = vbWhite
Fcol = vbGreen
Scol = vbWhite
Mcol = vbRed
Hcol = vbYellow
ClockHeight = 600
ClockWidth = 600
ClockFromMouseY = 1200
ClockFromMouseX = 600
Da(1) = "SUNDAY": Da(2) = "MONDAY": Da(3) = "TUESDAY": Da(4) = "WEDNESDAY"
Da(5) = "THURSDAY": Da(6) = "FRIDAY": Da(7) = "SATURDAY"
Mo(1) = "JANUARY": Mo(2) = "FEBRUARY": Mo(3) = "MARCH"
Mo(4) = "APRIL": Mo(5) = "MAY": Mo(6) = "JUNE": Mo(7) = "JULY"
Mo(8) = "AUGUST": Mo(9) = "SEPTEMBER": Mo(10) = "OCTOBER"
Mo(11) = "NOVEMBER": Mo(12) = "DECEMBER"
Day1 = Day(Now)
Year1 = Year(Now)

If (Year1 < 2000) Then Year1 = Year1 + 1900
Todaysdate = " " + Da(Weekday(Now)) + " " + Str(Day1) + " " + Mo(Month(Now)) + " " + Str(Year1)
d = Todaysdate
h = "..."
m = "...."
S = "....."
Face = "1 2 3 4 5 6 7 8 9 101112 "
Form1.Font = "Arial"
Form1.FontSize = 9
Speed = 0.6
n = Len(Face) - 2
Ymouse = 0
Xmouse = 0
scrll = 0
Split1 = 360 / n
Dsplit = 360 / Len(d)
HandHeight = ClockHeight / 4.5
Handwidth = ClockWidth / 4.5
HandY = -7
HandX = -2.5
scrll = 0 '2 * ClockHeight
Step = 0.06
currStep = 0
End Sub