Code : Tout sélectionner
EnableExplicit
Enumeration
#Fenetre_principale
EndEnumeration
Enumeration
#Trotteuse
#Fnd_Secondes
#GrandeAiguille
#Fnd_Minutes
#PetiteAiguille
#Fnd_Heures12
#Spr_Jour_Sem
#fnd_Jour_Sem
#Spr_Jour_Mois
#Fnd_Jour_Mois
#Spr_H24
#Fnd_Heures24
#Fond
#Son
EndEnumeration
Enumeration Font
#FontHeure
#FontMinute
#FontSeconde
#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, X24, Y24, Rayon, ;Coordonnées et rayon du point central du cercle
XCS, YCS, XCM, YCM, XCH, YCH ;Secondes, Minutes, Heures
Global X.f, Y.f ;Coordonnées des points sur le cercle
Global I, N, 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, X0, Y0, X1, Y1, Couleur
Global PreviousTime, Time
;Coordonnées et rayon du point central du cercle
XC = 400:YC = 400
XCS = 400:YCS = 110
XCJ = 200:YCJ = 300 ;jours semaine
XCD = 200:YCD = 520 ;jours mois
X24 = 400:Y24 = 690 ;cadran 24 heures
XCM = 600:YCM = 300 ;cadran minutes
XCH = 600:YCH = 520 ;cadran 12 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)
CreateSprite(#Spr_Jour_Mois, 800, 800)
CreateSprite(#Spr_H24, 800, 800)
CreateSprite(#Trotteuse, 800, 800)
CreateSprite(#GrandeAiguille, 800, 800)
CreateSprite(#PetiteAiguille, 800, 800)
CreateSprite(#Fond, 800, 800)
CreateSprite(#Fnd_Secondes, 800, 800)
CreateSprite(#Fnd_Minutes, 800, 800)
CreateSprite(#Fnd_Heures12, 800, 800)
CreateSprite(#Fnd_Heures24, 800, 800)
CreateSprite(#fnd_Jour_Sem, 800, 800)
CreateSprite(#Fnd_Jour_Mois, 800, 800)
LoadFont(#FontHeure, "Arial", 30, #PB_Font_Bold)
LoadFont(#FontMinute, "Arial", 10)
LoadFont(#FontSeconde, "Arial", 6)
LoadFont(#FontHeureGrasse, "Arial", 40, #PB_Font_Bold)
If StartDrawing(SpriteOutput(#Spr_Jour_Sem)) ;-sprite des jours de semaine
Restore Aiguille
For i = 0 To 4
Read X0
Read Y0
Read X1
Read Y1
Read Couleur
LineXY(X0, Y0, X1, Y1, Couleur)
Next i
Circle(400, 400, 15, Couleur)
StopDrawing()
EndIf
If StartDrawing(SpriteOutput(#Spr_Jour_Mois)) ;-sprite des jours du mois
Restore Aiguille
For i = 0 To 4
Read X0
Read Y0
Read X1
Read Y1
Read Couleur
LineXY(X0, Y0, X1, Y1, Couleur)
Next i
Circle(400, 400, 15, Couleur) ;Centre
StopDrawing()
EndIf
If StartDrawing(SpriteOutput(#Spr_H24)) ;-sprite du cadran 24 heures
Restore Aiguille
For i = 0 To 4
Read X0
Read Y0
Read X1
Read Y1
Read Couleur
LineXY(X0, Y0, X1, Y1, Couleur)
Next i
Circle(400, 400, 15, Couleur)
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, 60, $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)
Circle(400, 400, 60, 1)
StopDrawing()
EndIf
If StartDrawing(SpriteOutput(#Fnd_Secondes))
Circle(XCS, YCS, 110, $80DD80) ;cadran trotteuse
;-Les secondes (0 à 59)
Digit = 15
Rayon = 105
For N = 0 To 364 Step 6
X = XC + Rayon * Cos(N * #PI / 180) - 4
Y = YC + Rayon * Sin(N * #PI / 180) - 295
;Circle(X,Y,3, $FB9798)
DrawingFont(FontID(#FontSeconde))
DrawText(X, Y,Str(Digit), $1, $80DD80)
Digit + 1
If Digit=60
Digit = 0
EndIf
Next
StopDrawing()
EndIf
If StartDrawing(SpriteOutput(#Fnd_Minutes))
Circle(XCM, YCM, 110, $80DD80) ;cadran minutes
Circle(XCM, YCM, 15, $1)
;-Les Chiffres des minutes (0 à 59)
Digit=15
Rayon = 105
DrawingFont(FontID(#FontSeconde))
For N = 0 To 359 Step 6
Digit+1
If Digit>60
Digit = 1
EndIf
X = XC + Rayon * Cos(N * #PI / 180) + (XCM/3)
Y = YC + Rayon * Sin(N * #PI / 180) - (YCM/3)
Tampon=Str(Digit-1)
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(X-TextWidth(Tampon)/2, Y-TextHeight(Tampon)/2, Tampon, RGB(0, 0, 0))
DrawingMode(#PB_2DDrawing_Default)
Next
StopDrawing()
EndIf
If StartDrawing(SpriteOutput(#Fnd_Heures12))
Circle(XCH, YCH, 110, $80DD80) ;cadran heures
Circle(XCH, YCH, 15, $1)
;-Les Chiffres des heures (1 à 12)
Digit=2
Rayon = 90
DrawingFont(FontID(#FontMinute))
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) + (XCH/3)
Y = YC + Rayon * Sin(N * #PI / 180) + (YCH/3) - 50
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
StopDrawing()
EndIf
If StartDrawing(SpriteOutput(#Fnd_Heures24))
Circle(X24, Y24, 110, $80DD80) ;cadran 24 heures
;-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 = X24 + Rayon * Cos(N * #PI / 180)
Y = Y24 + 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
StopDrawing()
EndIf
If StartDrawing(SpriteOutput(#fnd_Jour_Sem))
Circle(XCJ, YCJ, 110, $80DD80) ;cadran jours de semaine
;-Les jours de semaine (lundi à dimanche)
DrawingFont(FontID(#FontMinute))
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)
StopDrawing()
EndIf
If StartDrawing(SpriteOutput(#Fnd_Jour_Mois))
Circle(XCD, YCD, 110, $80DD80) ;cadran jours du mois
;-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
StopDrawing()
EndIf
If StartDrawing(SpriteOutput(#Fond)) ;- fond
SpriteQuality(#PB_Sprite_BilinearFiltering)
Box(0, 0, 800, 800, $4EAA30) ;contour horloge
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(#Fnd_Secondes, TailleImage, TailleImage)
ZoomSprite(#Fnd_Minutes, TailleImage, TailleImage)
ZoomSprite(#Fnd_Heures12, TailleImage, TailleImage)
ZoomSprite(#Fnd_Heures24, TailleImage, TailleImage)
ZoomSprite(#Fnd_Jour_Mois, TailleImage, TailleImage)
ZoomSprite(#fnd_Jour_Sem, TailleImage, TailleImage)
ZoomSprite(#Trotteuse, 290, 290)
ZoomSprite(#GrandeAiguille, 270, 270)
ZoomSprite(#PetiteAiguille, 270, 270)
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
DisplayTransparentSprite(#Fond, 0, 0, 255)
DisplayTransparentSprite(#Fnd_Secondes, -10, 0, 255)
DisplayTransparentSprite(#Fnd_Minutes, 115, -50, 255)
DisplayTransparentSprite(#Fnd_Heures12, 115, 70, 255)
DisplayTransparentSprite(#Fnd_Heures24, 0, 0, 255)
DisplayTransparentSprite(#Fnd_Jour_Mois, -110, 50, 255)
DisplayTransparentSprite(#fnd_Jour_Sem, -110, -40, 255)
DisplayTransparentSprite(#Spr_Jour_Sem, -360, -170, 255)
DisplayTransparentSprite(#Spr_Jour_Mois, -365, 200, 255)
DisplayTransparentSprite(#Spr_H24, 100, 470, 255)
DisplayTransparentSprite(#PetiteAiguille, 730, 585, 255)
DisplayTransparentSprite(#GrandeAiguille, 730, 192, 255)
DisplayTransparentSprite(#Trotteuse, 350, -10, 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:
Aiguille:
Data.i 398, 400, 398, 305, $1
Data.i 399, 400, 399, 300, $1
Data.i 400, 400, 400, 295, $1
Data.i 401, 400, 401, 300, $1
Data.i 402, 400, 402, 305, $1
EndDataSection