Frustrated and bored with everything digital around me... :) (I m not joking). I wanted something "Analogue"... what's better than an Analogue watch. The game came afterwarrds when I finally got bored at staring my creation.
Here is the code..
First let us start with creating a clock. Starting with the design part, I Created a smart frame for my clock in Photoshop. I then added it as the background image of the Form, wrote the numbers on the dial and created three small lines in the middle (the hands of the clock).
Design part finished !! Moving on to the coding part. Let us start with creating a clock
Private Sub Timer1_Timer()
Form1.Caption = Time
sdeg = Second(Time) * 6
mdeg = Minute(Time) * 6
hdeg = Hour(Time) * 6
srad = (3.14 / 180) * sdeg
Line2.X1 = Line2.X2 + (90 * Sin(srad))
Line2.Y1 = Line2.Y2 - (90 * Cos(srad))
mrad = (3.14 / 180) * mdeg
Line1.X1 = Line1.X2 + (80 * Sin(mrad))
Line1.Y1 = Line1.Y2 - (80 * Cos(mrad))
hdeg = Hour(Time) * 30 + (0.5 * Minute(Time))
hrad = (3.14 / 180) * hdeg
Line3.X1 = Line3.X2 + (65 * Sin(hrad))
Line3.Y1 = Line3.Y2 - (65 * Cos(hrad))
That's all the code neede to created a running clock !! Easy Isn't it?
It's all mathematics. First we calculate the angle of the hands in degrees (i.e multiply by 6) since
1 circle = 360 degrees , we have 60 divisions on the clock so difference between 2 consequtive divisions is 6 degrees
Now we convert the angle into radians (pie/180) * angle in degrees (remember primary math lectures :) )
Finally we move the hands by changing there X and Y co-ordinates...If we interchange the Cos with a Sin and vice versa the clock will move anti-clockwise (he he).
That's it our clock is now finished.....It did not do much so I thought of creating a game in it. The game is simple. All you have to do is select any number from 1 to 12 (the numbers on the dial) and then spin the wheel. The wheel will keep spinning on the numbers reversing it's direction after a specified interval unless you click on it to stop it. If the wheel stops on the number which you had selected then you win!!.
This is the concept of our simple Time Pass game... Now for the code
Private Sub Timer2_Timer()
Label1(12).ForeColor = vbGreen
If (i <= 13) Then
Label1(i).ForeColor = vbBlue
Label1(i - 1).ForeColor = vbGreen
i = i + 1
If i = 13 Then
i = 1
If Timer2.Interval >= 10 And Timer2.Interval < 90 Then
Timer2.Interval = Timer2.Interval + 1
If Timer2.Interval = 90 Then
Timer2.Interval = 10
Timer3.Enabled = True
Timer2.Enabled = False
Private Sub Timer3_Timer()
Label1(1).ForeColor = vbGreen
If (j >= 1) Then
Label1(j).ForeColor = vbBlue
Label1(j + 1).ForeColor = vbGreen
j = j - 1
If j = 0 Then
j = 12
If Timer3.Interval <= 90 And Timer3.Interval > 10 Then
Timer3.Interval = Timer3.Interval - 1
If Timer3.Interval = 10 Then
Timer3.Interval = 90
Timer3.Enabled = False
Timer2.Enabled = True
Above we have 2 timers for spinning the wheel. The only difference is that one spins the wheel clockwise and the other anti-clockwise after a specified interval and so on(just to add some un to the spin). The spinning accelerates and deaccelerates as it changes direction.
Now to give the spinning effect all we do is change the color of the current number with blue(all are default green), move onto the next number change it to blue and change the previous back to green. in this we it seems as the wheel is moving. The code is fairly easy to understand..
That's all I had to say.. Don't forget to give your feedback