Vous avez du remarqué que je fais souvent des calendriers et des horloges, mais c'est parce le temps qui passe, ça me passionne.
Code : Tout sélectionner
EnableExplicit
Enumeration
#Fenetre_principale
EndEnumeration
Enumeration
#Trotteuse
#GrandeAiguille
#PetiteAiguille
#Spr_Jour_Sem
#Spr_Jour_Mois
#Spr_H24
#Fond
#Son
EndEnumeration
Enumeration Font
#FontHeure
#FontMinute
#FontHeureGrasse
EndEnumeration
Define.l Evenement, EvenementGadget
Global StyleFen.i=#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered
Global Image.i
Global XC, YC, XCJ, YCJ, XCD, YCD, XCH, YCH, Rayon ;Coordonnées et rayon du point central du cercle
Global X.f, Y.f ;Coordonnées des points sur le cercle
Global N.i, Nj.f, xsec.s, xmin.s, xheure.s, xjour.s, s, m, h, j, jm, TailleImage = 1000, Texte.s, Jour.s, Digit, Tampon.s , h24
;Global PreviousTime, Time
;Coordonnées et rayon du point central du cercle
XC = 400:YC = 400
XCJ = 200:YCJ = 300 ;jours semaine
XCD = 600:YCD = 300 ;jours mois
XCH = 400:YCH = 600 ;cadran 24 heures
If Not (InitSprite() And InitSound() And InitKeyboard())
End
EndIf
OpenWindow(#Fenetre_principale, 0, 0, TailleImage, TailleImage, "Horloge calendrier", StyleFen)
If OpenWindowedScreen(WindowID(#Fenetre_principale), 0, 0, TailleImage, TailleImage, 1, 0, 0)
; CatchSound(#son, ?Son)
; SoundVolume(#son, 10)
CreateSprite(#Spr_Jour_Sem, 800, 800, SpriteQuality(#PB_Sprite_BilinearFiltering))
CreateSprite(#Spr_Jour_Mois, 800, 800, SpriteQuality(#PB_Sprite_BilinearFiltering))
CreateSprite(#Spr_H24, 800, 800, SpriteQuality(#PB_Sprite_BilinearFiltering))
CreateSprite(#Trotteuse, 800, 800, SpriteQuality(#PB_Sprite_BilinearFiltering))
CreateSprite(#GrandeAiguille, 800, 800, SpriteQuality(#PB_Sprite_BilinearFiltering))
CreateSprite(#PetiteAiguille, 800, 800, SpriteQuality(#PB_Sprite_BilinearFiltering))
CreateSprite(#Fond, 800, 800, SpriteQuality(#PB_Sprite_BilinearFiltering))
LoadFont(#FontHeure, "Arial", 30, #PB_Font_Bold)
LoadFont(#FontMinute, "Arial", 15)
LoadFont(#FontHeureGrasse, "Arial", 40, #PB_Font_Bold)
If StartDrawing(SpriteOutput(#Spr_Jour_Sem)) ;-sprite des jours de semaine
LineXY(398, 400, 398, 305, $353535)
LineXY(399, 400, 399, 300, $353535)
LineXY(400, 400, 400, 295, $353535)
LineXY(401, 400, 401, 300, $353535)
LineXY(402, 400, 402, 305, $353535)
Circle(400, 400, 15, $353535)
StopDrawing()
EndIf
If StartDrawing(SpriteOutput(#Spr_Jour_Mois)) ;-sprite des jours du mois
LineXY(398, 400, 398, 305, $353535)
LineXY(399, 400, 399, 300, $353535)
LineXY(400, 400, 400, 295, $353535)
LineXY(401, 400, 401, 300, $353535)
LineXY(402, 400, 402, 305, $353535)
Circle(400, 400, 15, $353535) ;Centre
StopDrawing()
EndIf
If StartDrawing(SpriteOutput(#Spr_H24)) ;-sprite du cadran 24 heures
LineXY(398, 400, 398, 305, $353535)
LineXY(399, 400, 399, 300, $353535)
LineXY(400, 400, 400, 295, $353535)
LineXY(401, 400, 401, 300, $353535)
LineXY(402, 400, 402, 305, $353535)
Circle(400, 400, 15, $353535)
StopDrawing()
EndIf
If StartDrawing(SpriteOutput(#Trotteuse)) ;-sprite de la trotteuse
LineXY(398, 550, 398, 65, $2323C8)
LineXY(399, 550, 399, 60, $2323C8)
LineXY(400, 550, 400, 55, $2323C8)
LineXY(401, 550, 401, 60, $2323C8)
LineXY(402, 550, 402, 65, $2323C8)
Circle(400, 530, 10, $2323C8) ; la
Circle(400, 535, 9, $2323C8) ; queue
Circle(400, 540, 8, $2323C8) ; de
Circle(400, 545, 7, $2323C8) ; la
Circle(400, 550, 6, $2323C8) ; trotteuse
Circle(400, 400, 15, $2323C8) ;le centre de la trotteuse
Circle(400, 400, 25, $2323C8)
StopDrawing()
EndIf
If StartDrawing(SpriteOutput(#GrandeAiguille)) ;-sprite de la grande aiguille
LineXY(390, 400, 390, 20, $1)
LineXY(390, 20, 400, 12, $1) ;\
LineXY(400, 12, 410, 20, $1) ;/
LineXY(410, 20, 410, 400, $1)
LineXY(410, 400, 390, 400, $1)
FillArea(400, 300, $1, $1)
Circle(400, 400, 10, $1)
StopDrawing()
EndIf
If StartDrawing(SpriteOutput(#PetiteAiguille)) ;-sprite petite aiguille
LineXY(390, 160, 390, 410, $1)
LineXY(390, 160, 400, 145, $1) ;pointe \
LineXY(400, 145, 410, 160, $1) ;pointe /
LineXY(410, 160, 410, 410, $1)
LineXY(390, 410, 410, 410, $1)
FillArea(400, 300, $1, $1)
StopDrawing()
EndIf
If StartDrawing(SpriteOutput(#Fond)) ;- fond
Circle(400, 400, 800, $404040) ;Couleur de fond de l'image
;Point central
Circle(400, 400, 400, $AA4E30) ;contour horloge
Circle(XCH, YCH, 110, $80DD80) ;cadran 24 heures
;-Les secondes (0 à 59)
Rayon = 350
For N = 0 To 364 Step 6
X = XC + Rayon * Cos(N * #PI / 180)
Y = YC + Rayon * Sin(N * #PI / 180)
Circle(X,Y,3, $97FB98)
Next
;-Les jours de semaine (lundi à dimanche)
Circle(XCJ, YCJ, 110, $80DD80) ;contour semainier
DrawText(390-XCJ,290-100, "Dim",255, $80DD80)
DrawRotatedText(475-XCJ,320-100, "Lun",311,1)
DrawRotatedText(485-XCJ,430-100, "Mar",87,1)
DrawRotatedText(425-XCJ,485-100, "Mer",25,1)
DrawRotatedText(350-XCJ,475-100, "Jeu",335,1)
DrawRotatedText(310-XCJ,407-100, "Ven",290,1)
DrawRotatedText(300-XCJ,350-100, "Sam",60,1)
;-Les Chiffres des jours (1 à 31)
Circle(XCD, YCD, 110, $80DD80)
Digit=0
Rayon = 100
Nj.f = 0
While Nj < 360
Digit+1
X = XCD + Rayon * Cos(Nj * #PI / 180)
Y = YCD + Rayon * Sin(Nj * #PI / 180)
Tampon=Str(Digit)
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(X-TextWidth(Tampon)/2, Y-TextHeight(Tampon)/2, Tampon, $1)
DrawingMode(#PB_2DDrawing_Default)
Nj + 11.613
Wend
;-Les Chiffres des heures (1 à 12)
Digit=2
Rayon = 270
DrawingFont(FontID(#FontHeure))
For N = 0 To 345 Step 30
Digit+1
If Digit>12
Digit = Mod(12,4) + 1
EndIf
X = XC + Rayon * Cos(N * #PI / 180)
Y = YC + Rayon * Sin(N * #PI / 180)
Tampon=Str(Digit)
DrawingMode(#PB_2DDrawing_Transparent)
If Digit % 3 <> 0
DrawText(X-TextWidth(Tampon)/2, Y-TextHeight(Tampon)/2, Tampon, RGB(255, 255, 255))
ElseIf Digit % 3 = 0
DrawingFont(FontID(#FontHeureGrasse))
DrawText(X-TextWidth(Tampon)/2, Y-TextHeight(Tampon)/2, Tampon, RGB(255, 255, 255))
DrawingFont(FontID(#FontHeure))
EndIf
DrawingMode(#PB_2DDrawing_Default)
Next
;-Les Chiffres du petit cadran (1 à 24)
Digit=5
Rayon = 100
DrawingFont(FontID(#FontMinute))
For N = 0 To 360 Step 15
Digit+1
If Digit>23
Digit = 0
EndIf
X = XCH + Rayon * Cos(N * #PI / 180)
Y = YCH + Rayon * Sin(N * #PI / 180)
Tampon=Str(Digit)
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(X-TextWidth(Tampon)/2, Y-TextHeight(Tampon)/2, Tampon, 0)
DrawingMode(#PB_2DDrawing_Default)
Next
;-Les Chiffres des minutes (0 à 59)
Digit=15
Rayon = 390
DrawingFont(FontID(#FontMinute))
For N = 0 To 359 Step 6
Digit+1
If Digit>60
Digit = 1
EndIf
X = XC + Rayon * Cos(N * #PI / 180)
Y = YC + Rayon * Sin(N * #PI / 180)
Tampon=Str(Digit-1)
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(X-TextWidth(Tampon)/2, Y-TextHeight(Tampon)/2, Tampon, RGB(255, 255, 255))
DrawingMode(#PB_2DDrawing_Default)
Next
StopDrawing()
EndIf
EndIf
Repeat ;Evemement 2D
; Libération de la file d'attente de la fenetre
Repeat
Evenement = WindowEvent()
Select Evenement
Case #PB_Event_CloseWindow
End
EndSelect
Until Evenement=0
;Deroulement 2D
ClearScreen(RGB(0, 0, 0))
xsec.s = FormatDate("%ss", Date())
xmin.s = FormatDate("%ii", Date())
xheure.s = FormatDate("%hh", Date())
xjour.s = FormatDate("%dd", Date())
jm = (Val(xjour)-1)*11.613
If Val(xheure) > 11
xheure = Str(Val(xheure)-12)
EndIf
s = Val(xsec) * 6
m = (Val(xmin) * 60 + Val(xsec)) / 10
h = (Val(xheure) * 60 + Val(xmin)) / 2
j = DayOfWeek(Date()) * (360 / 7)
h24 = (Val(xheure) * 60 + Val(xmin)) / 4 ; système 24 h
ZoomSprite(#Trotteuse, TailleImage, TailleImage)
ZoomSprite(#GrandeAiguille, TailleImage, TailleImage)
ZoomSprite(#PetiteAiguille, TailleImage, TailleImage)
ZoomSprite(#Spr_Jour_Sem, TailleImage, TailleImage)
ZoomSprite(#Spr_Jour_Mois, TailleImage, TailleImage)
ZoomSprite(#Fond, TailleImage, TailleImage)
RotateSprite(#Trotteuse, s, #PB_Absolute)
RotateSprite(#GrandeAiguille, m, #PB_Absolute)
RotateSprite(#PetiteAiguille, h, #PB_Absolute)
RotateSprite(#Spr_Jour_Sem, j, #PB_Absolute)
RotateSprite(#Spr_Jour_Mois, jm+90, #PB_Absolute)
Select Hour(Date())
Case 0 To 11
RotateSprite(#Spr_H24, h24, #PB_Absolute)
Case 12 To 23
RotateSprite(#Spr_H24, h24-180, #PB_Absolute)
EndSelect
Debug Hour(Date())
DisplayTransparentSprite(#Fond, 0, 0, 255)
DisplayTransparentSprite(#Spr_Jour_Sem, -250, -120, 255)
DisplayTransparentSprite(#Spr_Jour_Mois, 250, -125, 255)
DisplayTransparentSprite(#Spr_H24, 100, 350, 255)
DisplayTransparentSprite(#PetiteAiguille, 0, 0, 255)
DisplayTransparentSprite(#GrandeAiguille, 0, 0, 255)
DisplayTransparentSprite(#Trotteuse, 0, 0, 255)
; Time = s
; If Time - PreviousTime > 0 Or Time - PreviousTime < 0
; PreviousTime = s
; PlaySound(#son)
; EndIf
If ExamineKeyboard()
If KeyboardReleased(#PB_Key_Escape)
End
EndIf
EndIf
FlipBuffers()
ForEver
;DataSection
; Son:
; IncludeBinary #PB_Compiler_FilePath + "\Data\Tic.Wav"
; FinSon:
;EndDataSection
; IDE Options = PureBasic 5.50 beta 2 (Windows - x86)
; EnableThread
; EnableXP
; UseIcon = ..\..\Gfx\icones\Chrono.ico
; Executable = ..\..\..\Compil\Horloge Calendrier complete.exe
; EnableUnicode