zdravím. Mám menší problém s kalibraci hodinových ručiček. Vteřinová a minutová mi funguje,ale hodinová se nějak zasekává, lépe řečeno,nefunguje mi, a nevim uz v čem je problém :(
Kod vypadá nejak takto:
Public Class Form1
Dim X, Xm, Xh As Integer
Dim Y, Ym, Yh As Integer
Dim sekundy As Integer
Dim Minuty As Integer
Dim Hodiny As Integer
Function SourX(ByVal r As Double, ByVal Alfa As Double) As Integer
SourX = r * Math.Cos(Alfa * Math.PI / 180)
End Function
Function SourY(ByVal r As Double, ByVal Alfa As Double) As Integer
SourY = r * Math.Sin(Alfa * Math.PI / 180)
End Function
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim Datum As Date
Datum = Datum.Now
Label1.Text = Datum
Dim Grafika As Graphics
Dim Pero As Pen
Dim Pero2 As Pen
Dim Pero3 As Pen
Dim Pero4 As Pen
Dim r As Integer
sekundy = sekundy + 1
If sekundy = 60 Then
sekundy = 0
End If
If sekundy = 45 Then
Minuty = Minuty + 1
End If
If Minuty = 45 Then
Hodiny = Hodiny + 1
End If
Pero = New Pen(Color.White, 4)
Pero2 = New Pen(Color.Red, 2)
Pero3 = New Pen(Color.Green, 3)
Pero4 = New Pen(Color.Blue, 4)
Grafika = Graphics.FromHwnd(Me.Handle)
Grafika.ScaleTransform(1, 1)
Grafika.TranslateTransform(Me.Size.Width() \ 2, Me.Size.Height() \ 2)
r = Me.Size.Width() \ 4
Grafika.DrawLine(Pero, 0, 0, X, Y)
X = SourX(r, 6 * sekundy)
Y = SourY(r, 6 * sekundy)
Grafika.DrawLine(Pero2, 0, 0, X, Y)
Grafika.DrawLine(Pero, 0, 0, Xm, Ym)
Xm = SourX(r, 6 * Minuty)
Ym = SourY(r, 6 * Minuty)
Grafika.DrawLine(Pero3, 0, 0, Xm, Ym)
Grafika.DrawLine(Pero, 0, 0, Xh, Yh)
Xh = SourX(r, 6 * Hodiny)
Yh = SourY(r, 6 * Hodiny)
Grafika.DrawLine(Pero4, 0, 0, Xh, Yh)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Interval = 1
sekundy = 45
Minuty = 45
Hodiny = 45
End Sub
End Class
(Interval = 1 proto,abych,nemusel vždy dlouho čekat na jeden cyklus.)
Fórum › Visual Basic
Hodinové ručičky

Díky, ta mechanika funguje, ručičky se otáči tak jak by měli, jen me vrtá hlavou, proč hodinová ručička tikne vždy,kdyz je minutová na 3jce (na analogových hodinách)
Problém bude asi v této podmínce :
If Minuty = 60 Then
Minuty = 0
Hodiny = Hodiny + 5
End If
Jelikož, kdyz minuty jsou 60,tak to ten program chápe jako 60 tzn analogová ručička na 3jce,tím pádem poskoči hodinovka +5. Když změním podmínku na 45,tak se to chová uplně jinak. :(
Protože nula stupňů je na třech hodinách, základní škola. Můžeš 0..60 posunout na -15..45, ale na to se vykašli. Čas počítej jako čas, pak to převeď na úhel a nakonec posuň o těch 90 stupňů.
Sec = Sec + 1
If Sec = 60 Then Sec = 0 : Min = Min + 1
If Min = 60 Then Min = 0 : Hrs = Hrs + 1
If Hrs = 12 Then Hrs = 0
ClockX = Me.ClientSize.Width \ 2
ClockY = Me.ClientSize.Height \ 2
ClockR = IIf(Me.ClientSize.Width < Me.ClientSize.Height, Me.ClientSize.Width \ 4, Me.ClientSize.Height \ 4)
gr = Graphics.FromHwnd(Me.Handle)
gr.TranslateTransform(ClockX, ClockY)
SecX = SourX(ClockR, Sec * (360 / 60) - 90)
SecY = SourY(ClockR, Sec * (360 / 60) - 90)
MinX = SourX(ClockR, Min * (360 / 60) - 90)
MinY = SourY(ClockR, Min * (360 / 60) - 90)
HrsX = SourX(ClockR, Hrs * (360 / 12) - 90)
HrsY = SourY(ClockR, Hrs * (360 / 12) - 90)
gr.Clear(Me.BackColor)
gr.DrawLine(penSec, 0, 0, SecX, SecY)
gr.DrawLine(penMin, 0, 0, MinX, MinY)
gr.DrawLine(penHrs, 0, 0, HrsX, HrsY)

Přidej příspěvek
Toto téma je starší jak čtvrt roku – přidej svůj příspěvek jen tehdy, máš-li k tématu opravdu co říct!
Ano, opravdu chci reagovat → zobrazí formulář pro přidání příspěvku
×Vložení zdrojáku
×Vložení obrázku
×Vložení videa
Aktuálně jsou podporována videa ze serverů YouTube, Vimeo a Dailymotion.
×






























































Uživatelé prohlížející si toto vlákno
Uživatelé on-line: 0 registrovaných, 1 host
Podobná vlákna
C# projekt - cena, způsob platby (provize/hodinově/za celek) — založil pr0gr4mm3r
Moderátoři diskuze