Horloge Binaire
Publié : lun. 26/juil./2010 19:41
Bonsoir,
Voici ce qui ma pris une partie de mon après midi. Je ne comprenez jamais se système d'horloge, alors j'en ai programmer une pour y voir plus clair.
Bon par contre je le précise le code doit et j'en suis sur pouvoir s'optimisée un max. La j'ai fait un peut a la barbare via la bibliothèque 2DDrawing sans trop me prendre la tête.
Mais je sais que SPH aime sa l'optimisation
Donc je vous post ça et après libre a vous oui ou non de l'optimiser.
Voilà si vous ne saisissez pas le fonctionnement voici un exemple :

@++
Voici ce qui ma pris une partie de mon après midi. Je ne comprenez jamais se système d'horloge, alors j'en ai programmer une pour y voir plus clair.

Bon par contre je le précise le code doit et j'en suis sur pouvoir s'optimisée un max. La j'ai fait un peut a la barbare via la bibliothèque 2DDrawing sans trop me prendre la tête.
Mais je sais que SPH aime sa l'optimisation



Code : Tout sélectionner
Procedure Timers(hwnd.l, uMsg.l, idEvent.l, dwTime.l)
Select uMsg
Case #WM_TIMER
PostMessage_(hwnd, #WM_USER, idEvent, dwTime)
EndSelect
EndProcedure
If OpenWindow(0, 0, 0, 600, 600, "Binary Clock", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
FontID = LoadFont(8, "Arial Black", 95, #PB_Font_Bold)
SetWindowColor(0, RGB(0, 0, 0))
If CreateImage(0, 600, 600)
If StartDrawing(ImageOutput(0))
; ++++++++++ dizaine heur bleu +++++++++
Circle(50, 550, 50, RGB(0, 0, 30))
Circle(50, 450, 50, RGB(0, 0, 30))
; ++++++++++++++++++++++++++++++++++++++
; ++++++++++ unité heur bleu +++++++++
Circle(150, 550, 50, RGB(0, 0, 30))
Circle(150, 450, 50, RGB(0, 0, 30))
Circle(150, 350, 50, RGB(0, 0, 30))
Circle(150, 250, 50, RGB(0, 0, 30))
; ++++++++++++++++++++++++++++++++++++++
; ++++++++++ dizaine minute bleu +++++++
Circle(250, 550, 50, RGB(0, 0, 30))
Circle(250, 450, 50, RGB(0, 0, 30))
Circle(250, 350, 50, RGB(0, 0, 30))
; ++++++++++++++++++++++++++++++++++++++
; ++++++++++ unité minute bleu +++++++++
Circle(350, 550, 50, RGB(0, 0, 30))
Circle(350, 450, 50, RGB(0, 0, 30))
Circle(350, 350, 50, RGB(0, 0, 30))
Circle(350, 250, 50, RGB(0, 0, 30))
; ++++++++++++++++++++++++++++++++++++++
; ++++++++++ dizaine seconde bleu ++++++
Circle(450, 550, 50, RGB(0, 0, 30))
Circle(450, 450, 50, RGB(0, 0, 30))
Circle(450, 350, 50, RGB(0, 0, 30))
; ++++++++++++++++++++++++++++++++++++++
; ++++++++++ unité seconde bleu +++++++++
Circle(550, 550, 50, RGB(0, 0, 30))
Circle(550, 450, 50, RGB(0, 0, 30))
Circle(550, 350, 50, RGB(0, 0, 30))
Circle(550, 250, 50, RGB(0, 0, 30))
; ++++++++++++++++++++++++++++++++++++++
StopDrawing()
ImageGadget(0, 0, 0, 0, 0, ImageID(0))
EndIf
EndIf
SetTimer_(WindowID(0), 1, 1000, @Timers())
Repeat
Event = WindowEvent()
Select Event
Case#PB_Event_Gadget
Case #WM_USER
If StartDrawing(ImageOutput(0))
SetTimer_(WindowID(0), 1, 1000, @Timers())
DrawingFont(FontID)
date$ = FormatDate("%hh:%ii:%ss", Date())
DrawText(0, -30, date$, RGB(150, 0, 0), RGB(0, 0, 0))
DrawingMode(#PB_2DDrawing_Gradient)
BackColor(RGB(150, 0, 0))
FrontColor(RGB(0, 0, 30))
; ++++++++++ dizaine heur rouge +++++++++
If Val(Mid(FormatDate("%hh", Date()), 1, 1)) = 0
Circle(50, 550, 50, RGB(0, 0, 30))
Circle(50, 450, 50, RGB(0, 0, 30))
ElseIf Val(Mid(FormatDate("%hh", Date()), 1, 1)) = 1
EllipticalGradient(50, 550, 55, 55)
Circle(50, 550, 50, RGB(150, 0, 0))
ElseIf Val(Mid(FormatDate("%hh", Date()), 1, 1)) = 2
EllipticalGradient(50, 450, 55, 55)
Circle(50, 450, 50, RGB(150, 0, 0))
Circle(50, 550, 50, RGB(0, 0, 30))
EndIf
; +++++++++++++++++++++++++++++++++++++
; ++++++++++ unité heur rouge +++++++++
If Val(Mid(FormatDate("%hh", Date()), 2, 1)) = 0
Circle(150, 550, 50, RGB(0, 0, 30))
Circle(150, 450, 50, RGB(0, 0, 30))
Circle(150, 350, 50, RGB(0, 0, 30))
Circle(150, 250, 50, RGB(0, 0, 30))
ElseIf Val(Mid(FormatDate("%hh", Date()), 2, 1)) = 1
EllipticalGradient(150, 550, 55, 55)
Circle(150, 550, 50, RGB(150, 0, 0))
ElseIf Val(Mid(FormatDate("%hh", Date()), 2, 1)) = 2
EllipticalGradient(150, 450, 55, 55)
Circle(150, 450, 50, RGB(150, 0, 0))
Circle(150, 550, 50, RGB(0, 0, 30))
ElseIf Val(Mid(FormatDate("%hh", Date()), 2, 1)) = 3
EllipticalGradient(150, 550, 55, 55)
Circle(150, 550, 50, RGB(150, 0, 0))
EllipticalGradient(150, 450, 55, 55)
Circle(150, 450, 50, RGB(150, 0, 0))
ElseIf Val(Mid(FormatDate("%hh", Date()), 2, 1)) = 4
EllipticalGradient(150, 350, 55, 55)
Circle(150, 350, 50, RGB(150, 0, 0))
Circle(150, 550, 50, RGB(0, 0, 30))
Circle(150, 450, 50, RGB(0, 0, 30))
ElseIf Val(Mid(FormatDate("%hh", Date()), 2, 1)) = 5
EllipticalGradient(150, 350, 55, 55)
Circle(150, 350, 50, RGB(150, 0, 0))
EllipticalGradient(150, 550, 55, 55)
Circle(150, 550, 50, RGB(150, 0, 0))
ElseIf Val(Mid(FormatDate("%hh", Date()), 2, 1)) = 6
EllipticalGradient(150, 350, 55, 55)
Circle(150, 350, 50, RGB(150, 0, 0))
EllipticalGradient(150, 450, 55, 55)
Circle(150, 450, 50, RGB(150, 0, 0))
Circle(150, 550, 50, RGB(0, 0, 30))
ElseIf Val(Mid(FormatDate("%hh", Date()), 2, 1)) = 7
EllipticalGradient(150, 350, 55, 55)
Circle(150, 450, 50, RGB(150, 0, 0))
EllipticalGradient(150, 550, 55, 55)
Circle(150, 450, 50, RGB(150, 0, 0))
EllipticalGradient(150, 550, 55, 55)
Circle(150, 550, 50, RGB(150, 0, 0))
ElseIf Val(Mid(FormatDate("%hh", Date()), 2, 1)) = 8
EllipticalGradient(150, 250, 55, 55)
Circle(150, 250, 50, RGB(150, 0, 0))
Circle(150, 550, 50, RGB(0, 0, 30))
Circle(150, 450, 50, RGB(0, 0, 30))
Circle(150, 350, 50, RGB(0, 0, 30))
ElseIf Val(Mid(FormatDate("%hh", Date()), 2, 1)) = 9
EllipticalGradient(150, 250, 55, 55)
Circle(150, 250, 50, RGB(550, 0, 0))
EllipticalGradient(150, 550, 55, 55)
Circle(150, 550, 50, RGB(150, 0, 0))
EndIf
; +++++++++++++++++++++++++++++++++++++
; +++++++++ dizaine minute rouge +++++++
If Val(Mid(FormatDate("%ii", Date()), 1, 1)) = 0
Circle(250, 550, 50, RGB(0, 0, 30))
Circle(250, 450, 50, RGB(0, 0, 30))
Circle(250, 350, 50, RGB(0, 0, 30))
ElseIf Val(Mid(FormatDate("%ii", Date()), 1, 1)) = 1
EllipticalGradient(250, 550, 55, 55)
Circle(250, 550, 50, RGB(150, 0, 0))
ElseIf Val(Mid(FormatDate("%ii", Date()), 1, 1)) = 2
EllipticalGradient(250, 450, 55, 55)
Circle(250, 450, 50, RGB(150, 0, 0))
Circle(250, 550, 50, RGB(0, 0, 30))
ElseIf Val(Mid(FormatDate("%ii", Date()), 1, 1)) = 3
EllipticalGradient(250, 550, 55, 55)
Circle(250, 550, 50, RGB(150, 0, 0))
EllipticalGradient(250, 450, 55, 55)
Circle(250, 450, 50, RGB(150, 0, 0))
ElseIf Val(Mid(FormatDate("%ii", Date()), 1, 1)) = 4
EllipticalGradient(250, 350, 55, 55)
Circle(250, 350, 50, RGB(150, 0, 0))
Circle(250, 550, 50, RGB(0, 0, 30))
Circle(250, 450, 50, RGB(0, 0, 30))
ElseIf Val(Mid(FormatDate("%ii", Date()), 1, 1)) = 5
EllipticalGradient(250, 350, 55, 55)
Circle(250, 350, 50, RGB(150, 0, 0))
EllipticalGradient(250, 550, 55, 55)
Circle(250, 550, 50, RGB(150, 0, 0))
EndIf
; ++++++++++++++++++++++++++++++++++++++
; +++++++++ unité minute rouge +++++++++
If Val(Mid(FormatDate("%ii", Date()), 2, 1)) = 0
Circle(350, 550, 50, RGB(0, 0, 30))
Circle(350, 450, 50, RGB(0, 0, 30))
Circle(350, 350, 50, RGB(0, 0, 30))
Circle(350, 250, 50, RGB(0, 0, 30))
ElseIf Val(Mid(FormatDate("%ii", Date()), 2, 1)) = 1
EllipticalGradient(350, 550, 55, 55)
Circle(350, 550, 50, RGB(150, 0, 0))
ElseIf Val(Mid(FormatDate("%ii", Date()), 2, 1)) = 2
EllipticalGradient(350, 450, 55, 55)
Circle(350, 450, 50, RGB(150, 0, 0))
Circle(350, 550, 50, RGB(0, 0, 30))
ElseIf Val(Mid(FormatDate("%ii", Date()), 2, 1)) = 3
EllipticalGradient(350, 450, 55, 55)
Circle(350, 450, 50, RGB(150, 0, 0))
EllipticalGradient(350, 550, 55, 55)
Circle(350, 550, 50, RGB(150, 0, 0))
ElseIf Val(Mid(FormatDate("%ii", Date()), 2, 1)) = 4
EllipticalGradient(350, 350, 55, 55)
Circle(350, 350, 50, RGB(150, 0, 0))
Circle(350, 550, 50, RGB(0, 0, 30))
Circle(350, 450, 50, RGB(0, 0, 30))
ElseIf Val(Mid(FormatDate("%ii", Date()), 2, 1)) = 5
EllipticalGradient(350, 350, 55, 55)
Circle(350, 350, 50, RGB(150, 0, 0))
EllipticalGradient(350, 550, 55, 55)
Circle(350, 550, 50, RGB(150, 0, 0))
ElseIf Val(Mid(FormatDate("%ii", Date()), 2, 1)) = 6
EllipticalGradient(350, 350, 55, 55)
Circle(350, 350, 50, RGB(150, 0, 0))
EllipticalGradient(350, 450, 55, 55)
Circle(350, 450, 50, RGB(150, 0, 0))
Circle(350, 550, 50, RGB(0, 0, 30))
ElseIf Val(Mid(FormatDate("%ii", Date()), 2, 1)) = 7
EllipticalGradient(350, 350, 55, 55)
Circle(350, 350, 50, RGB(150, 0, 0))
EllipticalGradient(350, 450, 55, 55)
Circle(350, 450, 50, RGB(150, 0, 0))
EllipticalGradient(350, 550, 55, 55)
Circle(350, 550, 50, RGB(150, 0, 0))
ElseIf Val(Mid(FormatDate("%ii", Date()), 2, 1)) = 8
EllipticalGradient(350, 250, 55, 55)
Circle(350, 250, 50, RGB(150, 0, 0))
Circle(350, 550, 50, RGB(0, 0, 30))
Circle(350, 450, 50, RGB(0, 0, 30))
Circle(350, 350, 50, RGB(0, 0, 30))
ElseIf Val(Mid(FormatDate("%ii", Date()), 2, 1)) = 9
EllipticalGradient(350, 250, 55, 55)
Circle(350, 250, 50, RGB(150, 0, 0))
EllipticalGradient(350, 550, 55, 55)
Circle(350, 550, 50, RGB(150, 0, 0))
EndIf
; ++++++++++++++++++++++++++++++++++++++
; +++++++++ dizaine seconde rouge +++++++
If Val(Mid(FormatDate("%ss", Date()), 1, 1)) = 0
Circle(450, 550, 50, RGB(0, 0, 30))
Circle(450, 450, 50, RGB(0, 0, 30))
Circle(450, 350, 50, RGB(0, 0, 30))
ElseIf Val(Mid(FormatDate("%ss", Date()), 1, 1)) = 1
EllipticalGradient(450, 550, 55, 55)
Circle(450, 550, 50, RGB(150, 0, 0))
ElseIf Val(Mid(FormatDate("%ss", Date()), 1, 1)) = 2
EllipticalGradient(450, 450, 55, 55)
Circle(450, 450, 50, RGB(150, 0, 0))
Circle(450, 550, 50, RGB(0, 0, 30))
ElseIf Val(Mid(FormatDate("%ss", Date()), 1, 1)) = 3
EllipticalGradient(450, 550, 55, 55)
Circle(450, 550, 50, RGB(150, 0, 0))
EllipticalGradient(450, 450, 55, 55)
Circle(450, 450, 50, RGB(150, 0, 0))
ElseIf Val(Mid(FormatDate("%ss", Date()), 1, 1)) = 4
EllipticalGradient(450, 350, 55, 55)
Circle(450, 350, 50, RGB(150, 0, 0))
Circle(450, 450, 50, RGB(0, 0, 30))
Circle(450, 550, 50, RGB(0, 0, 30))
ElseIf Val(Mid(FormatDate("%ss", Date()), 1, 1)) = 5
EllipticalGradient(450, 350, 55, 55)
Circle(450, 350, 50, RGB(150, 0, 0))
EllipticalGradient(450, 550, 55, 55)
Circle(450, 550, 50, RGB(150, 0, 0))
EndIf
; ++++++++++++++++++++++++++++++++++++++
; +++++++++ unité seconde rouge +++++++++
If Val(Mid(FormatDate("%ss", Date()), 2, 1)) = 0
Circle(550, 550, 50, RGB(0, 0, 30))
Circle(550, 450, 50, RGB(0, 0, 30))
Circle(550, 350, 50, RGB(0, 0, 30))
Circle(550, 250, 50, RGB(0, 0, 30))
ElseIf Val(Mid(FormatDate("%ss", Date()), 2, 1)) = 1
EllipticalGradient(550, 550, 55, 55)
Circle(550, 550, 50, RGB(150, 0, 0))
ElseIf Val(Mid(FormatDate("%ss", Date()), 2, 1)) = 2
EllipticalGradient(550, 450, 55, 55)
Circle(550, 450, 50, RGB(150, 0, 0))
Circle(550, 550, 50, RGB(0, 0, 30))
ElseIf Val(Mid(FormatDate("%ss", Date()), 2, 1)) = 3
EllipticalGradient(550, 450, 55, 55)
Circle(550, 450, 50, RGB(150, 0, 0))
EllipticalGradient(550, 550, 55, 55)
Circle(550, 550, 50, RGB(150, 0, 0))
ElseIf Val(Mid(FormatDate("%ss", Date()), 2, 1)) = 4
EllipticalGradient(550, 350, 55, 55)
Circle(550, 350, 50, RGB(150, 0, 0))
Circle(550, 450, 50, RGB(0, 0, 30))
Circle(550, 550, 50, RGB(0, 0, 30))
ElseIf Val(Mid(FormatDate("%ss", Date()), 2, 1)) = 5
EllipticalGradient(550, 350, 55, 55)
Circle(550, 350, 50, RGB(150, 0, 0))
EllipticalGradient(550, 550, 55, 55)
Circle(550, 550, 50, RGB(150, 0, 0))
ElseIf Val(Mid(FormatDate("%ss", Date()), 2, 1)) = 6
EllipticalGradient(550, 350, 55, 55)
Circle(550, 350, 50, RGB(150, 0, 0))
EllipticalGradient(550, 450, 55, 55)
Circle(550, 450, 50, RGB(150, 0, 0))
Circle(550, 550, 50, RGB(0, 0, 30))
ElseIf Val(Mid(FormatDate("%ss", Date()), 2, 1)) = 7
EllipticalGradient(550, 350, 55, 55)
Circle(550, 350, 50, RGB(150, 0, 0))
EllipticalGradient(550, 450, 55, 55)
Circle(550, 450, 50, RGB(150, 0, 0))
EllipticalGradient(550, 550, 55, 55)
Circle(550, 550, 50, RGB(150, 0, 0))
ElseIf Val(Mid(FormatDate("%ss", Date()), 2, 1)) = 8
EllipticalGradient(550, 250, 55, 55)
Circle(550, 250, 50, RGB(150, 0, 0))
Circle(550, 350, 50, RGB(0, 0, 30))
Circle(550, 450, 50, RGB(0, 0, 30))
Circle(550, 550, 50, RGB(0, 0, 30))
ElseIf Val(Mid(FormatDate("%ss", Date()), 2, 1)) = 9
EllipticalGradient(550, 250, 55, 55)
Circle(550, 250, 50, RGB(150, 0, 0))
EllipticalGradient(550, 550, 55, 55)
Circle(550, 550, 50, RGB(150, 0, 0))
EndIf
; ++++++++++++++++++++++++++++++++++++++
StopDrawing()
SetGadgetState(0, ImageID(0))
EndIf
EndSelect
Until Event = #PB_Event_CloseWindow
EndIf

@++