the Tectonic Clock
Posted: Sat Sep 01, 2012 2:38 pm
je ressors un de mes vieux code fait en Purebasic 4.01 ...
je n'ai eu aucune retouche a faire !!
marche toujours , meme sur Seven
pour info a cette epoque la Tectonic n'existait pas ...
; dans ce code : comment faire une fenêtre ronde.. piqué au Soldat inconnu
; comment faire disparaitre le prg de la barre des taches
; 2 formule de calcul de rotations, tres utile dans tout les Jeux Video
; utilisation d'un callback
; une procédure du Soldat pour faire un mélange de couleur , dans la cabane du pécheur ...
; mis en bouteille par Dobro and Co
ps : pour info la couleur du tour de l'horloge doit changer suivant le moment de la journée
et retient sa position si vous la deplacez ... ( a mettre dans le dossier Démarrage du menu démarrer...mais c'est pas obligé
)
on clique avec le bouton droit de la souris pour quitter l'horloge
je n'ai eu aucune retouche a faire !!

marche toujours , meme sur Seven
pour info a cette epoque la Tectonic n'existait pas ...

dans ce code plusieurs choses intéressantes :I pull one of my old code made PureBasic 4.01 ...
I had no editing to do!
still works, even on Seven
for info at this time, the Tectonic did not exist ...
; dans ce code : comment faire une fenêtre ronde.. piqué au Soldat inconnu
; comment faire disparaitre le prg de la barre des taches
; 2 formule de calcul de rotations, tres utile dans tout les Jeux Video
; utilisation d'un callback
; une procédure du Soldat pour faire un mélange de couleur , dans la cabane du pécheur ...
; mis en bouteille par Dobro and Co

ps : pour info la couleur du tour de l'horloge doit changer suivant le moment de la journée

et retient sa position si vous la deplacez ... ( a mettre dans le dossier Démarrage du menu démarrer...mais c'est pas obligé

on clique avec le bouton droit de la souris pour quitter l'horloge
in this code several interesting things:
And in this code: how to make a round window .. Dive the Soldat inconnu
, How to make disappear the prg the taskbar
, 2 formula rotations, very useful in all Games
And use of a callback
And a procedure of Soldat inconnu to a mixture of color, in the cabin of the fisherman's hut ... (untranslatable reference to Francis Cabrel, singer)
, Bottled by Dobro and Co
ps: FYI the color of the clock tower should change depending on the time of day
and retains its position if you move ... (To put in the Startup folder of the Start menu ... but it's not required)
clicking with the right mouse button to exit the clock
Code: Select all
; Code : Dobro
; PureBasic 4.01 ; ça date , mais ça marche toujours en 4.61 !! et meme sur Seven :o)
; Horloge Tectonic (j?étais en avance sur mon temps LOL
; dans ce code : comment faire une fenêtre ronde.. piqué au Soldat inconnu
; comment faire disparaitre le prg de la barre des taches
; 2 formule de calcul de rotations, tres utile dans tout les Jeux Video
; utilisation d'un callback
; une procédure du Soldat pour faire un mélange de couleur , dans la cabane du pécheur ...
;***********************************************
;Titre :Horloge Tectonic
;Auteur : Dobro
;Date :28/08/2013
;Heure :16:17:10
;Version Purebasic : PureBasic 5.11 (Windows - x86)
;Version de l'editeur :EPB V2.40
; Libairies necessaire : Aucune
;***********************************************
Enumeration
#fenetre
#rond
#petitrond
#moyenrond
#Image
#Text_0
#dobro
#minute
#Police
#Police2
EndEnumeration
#CAPTUREBLT = $40000000
Declare.f RotationX(x, angle.f, dist)
Declare.f RotationY(y, angle.f, dist)
Declare Forme(fenetre,forme)
Declare RemoveFromTaskbar(hwnd)
Declare WindowCallback( WindowID ,message,wParam,lParam)
Declare dessin_horloge()
Declare.l ColorBlending(Couleur1.l, Couleur2.l, Echelle.f)
; *********** initialisation *********
Global rezX=200
Global rezy=200
Global xa=rezy/2
Global ya=rezy/2
Global distance=rezy/2-4
Global Perdu=0 ; defini si l'on perds le focus !!
Global Sprite=200
Global degress,degresm,degresh, tops, topm, toph,Pos_wx,Pos_wy, pas,tour_col,compteur
Global coul_dep_matin,coul_arr_matin,coul_dep_amidi,coul_arr_amidi,coul_dep_soir,coul_arr_soir,coul_dep_nuit,coul_arr_nuit
Global tour,i8,c_r,c_v,c_b,memheure
Global NewList buffer.l ()
; matin
coul_dep_matin=RGB($35,$35,$FF) ; bleu_nuit
coul_arr_matin=RGB(255,255,0); au jaune
;apres midi
coul_dep_amidi=RGB(255,255,0) ; du jaune
coul_arr_amidi=RGB($FF,$80,$40) ; a l'orange
;soir
coul_dep_soir=RGB($FF,$80,$40) ; de l'orange
coul_arr_soir=RGB($E7,$3A,$AA) ; au mauve
;nuit
coul_dep_nuit=RGB($E7,$3A,$AA) ; au mauve
coul_arr_nuit=RGB($35,$35,$FF) ; bleu_nuit
Global date
Global Heure
Global Minute
Global Seconde
Global degress,degresm,degresh
date = Date()
Heure=Hour(date)
nombre_minute=Heure*60+Minute(date)
nombre_heure=nombre_minute/60
tour= nombre_minute
LoadFont(#Police, "Comic Sans MS", 8) ; police de la signature
LoadFont(#Police2, "Comic Sans MS", 12) ; police de l'heure
Structure sprite2
x.l
y.l
vitesse.l
couleur_r.l
couleur_v.l
couleur_b.l
EndStructure
Global Dim sprite2.sprite2(Sprite)
ExamineDesktops ()
For i=1 To Sprite-1
sprite2(i)\x=Random(rezX)+1
sprite2(i)\y=Random(rezy)+1
sprite2(i)\vitesse=Random(5)+1
sprite2(i)\ couleur_r=Random(255)+50
sprite2(i)\ couleur_v=Random(255)+50
sprite2(i)\ couleur_b=Random(255)+50
Next i
; *************************************************************************
If OpenFile(1,"Horloge.ini")
Pos_wx=Val(ReadString(1))
Pos_wy=Val(ReadString(1))
CloseFile(1)
EndIf
OpenWindow( #fenetre, 0,0, rezX, rezy, "Horloge",#PB_Window_BorderLess ) ; on ouvre une fenetre
Handle=WindowID(#fenetre)
SetWindowColor(#fenetre, RGB(0,0,0))
SetWindowCallback (@WindowCallback()) ; un callback pour que le dessin reste sur la fenetre (repaint)
RemoveFromTaskbar(FindWindow_(#fenetre,"Horloge")) ; fait disparaitre la fenetre de la barre des taches
Forme (#fenetre,2); ronde
ResizeWindow( #fenetre,Pos_wx,Pos_wy,rezX,rezy)
Repeat ; boucle principale
;
; *************************
date = Date()
Heure=Hour(date)
Minute = Minute(date)
Seconde=Second(date)
Event=WindowEvent() ; on regarde si quelqu'un a cliqué sur la croix pour quitter
If Event <>0
EndIf
If Event= #WM_MOUSEFIRST Or Event= #PB_Event_ActivateWindow Or Event=49310 ; la souris est sur l'horloge
EndIf
Select Event
Case #WM_LBUTTONDOWN ; deplace fenetre
SendMessage_(WindowID(#fenetre), #WM_NCLBUTTONDOWN, #HTCAPTION, 0)
Case #WM_RBUTTONDOWN ; click droit sur l'horloge
Pos_wx = WindowX(#fenetre)
Pos_wy = WindowY(#fenetre)
OpenFile(1,"Horloge.ini")
WriteStringN(1,Str(Pos_wx))
WriteStringN(1,Str(Pos_wy))
CloseFile(1)
End
EndSelect
If Memsecond<>Seconde
SendMessage_(WindowID(#fenetre), #dobro, #HTCAPTION, 0) ; chaque seconde on envoi un message #dobro
EndIf
Memsecond=Seconde
If Memminute<>Minute
SendMessage_(WindowID(#fenetre), #minute, #HTCAPTION, 0) ; chaque minute on envoi un message #minute
EndIf
Memminute=Minute
; ***************************************************
dessin_horloge()
ForEver ;
Return
Procedure.f RotationX(x, angle.f, dist)
ProcedureReturn x + Cos(angle.f*#PI/180)*dist
EndProcedure
Procedure.f RotationY(y, angle.f, dist)
ProcedureReturn y + Sin(angle.f*#PI/180)*dist
EndProcedure
Procedure Forme(fenetre,forme)
If forme=2 ; si on a choisi la forme 2 Ronde
Region = CreateEllipticRgn_( 0, 0, WindowHeight(#fenetre), WindowHeight(#fenetre)) ; Création de la région pour faire une fenêtre ronde !!!
SetWindowRgn_(WindowID(#fenetre), Region, #True) ; On applique la région
DeleteObject_(Region) ; On supprime la région
EndIf
EndProcedure
Procedure RemoveFromTaskbar(hwnd)
If IsWindow_(hwnd)
a=hwnd : b=GetWindowLong_(a,#GWL_HWNDPARENT) : If b<>0 : a=b : EndIf
ShowWindow_(a,#SW_HIDE) : GetWindowRect_(a,win.RECT) : w=win\right-win\left : h=win\bottom-win\top
SetWindowLong_(a,#GWL_EXSTYLE,#WS_EX_TOOLWINDOW) : SetWindowPos_(a,0,0,0,w-1,h-1,#SWP_NOMOVE)
SetWindowPos_(a,0,0,0,w,h,#SWP_NOMOVE|#SWP_SHOWWINDOW) : ProcedureReturn 1
EndIf
EndProcedure
Procedure WindowCallback( WindowID ,message,wParam,lParam)
RES= #PB_ProcessPureBasicEvents
If message= #WM_PAINT ; on repaint la fenetre
dessin_horloge()
ElseIf message= #WM_MOVE ; au cas ou l'on bouge la fenetre
; ******** dessin du rond d'effacement *************
StartDrawing(WindowOutput(#fenetre))
Circle(xa, ya, 100 ,RGB(0,0,0))
StopDrawing()
; **********************************************
; ********* dessin des etoiles *************
For i=1 To Sprite-1
sprite2(i)\y=sprite2(i)\y+sprite2(i)\vitesse
If sprite2(i)\y>WindowHeight(#fenetre)
sprite2(i)\y=0
EndIf
StartDrawing(WindowOutput(#fenetre))
Circle(sprite2(i)\x,sprite2(i)\y,1,RGB(sprite2(i)\ couleur_r,sprite2(i)\ couleur_v,sprite2(i)\ couleur_b))
StopDrawing()
Next i
; ******************************************
dessin_horloge()
ElseIf message =#dobro ; chaque seconde
date = Date()
Heure=Hour(date)
nombre_minute=Heure*60+Minute(date)
nombre_heure=nombre_minute/60
tour= (nombre_minute/6)
If (nombre_minute>=420) And (nombre_minute<=720) ;(de 7 a 12 h)
tour_col=ColorBlending( coul_arr_matin,coul_dep_matin, tour) ; matin /360 car 24/4=6 , 60*6=360
ElseIf (nombre_minute=>780) And (nombre_minute<=1080) ;(de 13 a 18h)
tour_col=ColorBlending( coul_arr_amidi,coul_dep_amidi, tour) ; apres-midi
ElseIf (nombre_minute=>1140) And (nombre_minute<=1440) ;(de 19 a 00h)
tour_col=ColorBlending( coul_arr_soir,coul_dep_soir, tour) ; soir
ElseIf (nombre_minute>=0) And (nombre_minute<=360) ;(de 00 a 06h)
tour_col=ColorBlending( coul_arr_nuit,coul_dep_nuit, tour) ; nuit
EndIf
; ******** dessin du rond d'effacement *************
StartDrawing(WindowOutput(#fenetre))
Circle(xa, ya, 100 ,RGB(0,0,0))
StopDrawing()
; **********************************************
; ********* dessin des etoiles *************
For i=1 To Sprite-1
sprite2(i)\y=sprite2(i)\y+sprite2(i)\vitesse
If sprite2(i)\y>WindowHeight(#fenetre)
sprite2(i)\y=0
EndIf
StartDrawing(WindowOutput(#fenetre))
Circle(sprite2(i)\x,sprite2(i)\y,2,RGB(sprite2(i)\ couleur_r,sprite2(i)\ couleur_v,sprite2(i)\ couleur_b))
StopDrawing()
Next i
; ******************************************
ElseIf message =#minute ; chaque minute
Else
ProcedureReturn #PB_ProcessPureBasicEvents ; rend la main !
EndIf
EndProcedure
;{ ****************** dessin de l'horloge **********************
Procedure dessin_horloge()
; ********************************************************
; AFFICHE LES AIGUILLES
;*********************************************************
degress=Seconde*6
; Ici, le code affiche les secondes
xs= RotationX(xa, degress-90, distance)
Ys= RotationY(ya, degress-90, distance)
; aiguille des secondes
StartDrawing(WindowOutput(#fenetre))
LineXY(xa, ya, xs, Ys , RGB($E9,$32,$92)) ; les secondes rouge
For i=-2 To 2
LineXY(xa+i, ya+i, xs, Ys , RGB($E9,$32,$92)) ; les secondes rouge
Next i
StopDrawing()
; Ici, le code affiche les minutes
degresm =Minute*6
xm= RotationX(xa, degresm-90, distance-25)
Ym= RotationY(ya, degresm-90, distance-25)
; aiguille des minute
StartDrawing(WindowOutput(#fenetre))
LineXY(xa, ya, xm, Ym , RGB($5,$E2,$B6)) ; les minutes verte
For i=-2 To 2
LineXY(xa+i, ya+i, xm, Ym , RGB($5,$E2,$B6)) ; les secondes rouge
Next i
StopDrawing()
; Ici, le code affiche les heures
degresh =Heure*6*5
xh= RotationX(xa, degresh-90, distance-50)
Yh= RotationY(ya, degresh-90, distance-50)
; aiguille des heures
StartDrawing(WindowOutput(#fenetre))
LineXY(xa, ya, xh, Yh , RGB($F5,$F9,$6A)) ; les heures jaune
For i=-2 To 2
LineXY(xa+i, ya+i, xh, Yh , RGB($F5,$F9,$6A)) ; les secondes rouge
Next i
StopDrawing()
; ********************************************************
;*********************************************************
StartDrawing(WindowOutput(#fenetre))
DrawingMode(#PB_2DDrawing_Transparent)
DrawingFont(FontID(#Police))
DrawText(xa-TextWidth("By Dobro")/2, rezy/2+50,"By Dobro", tour_col,RGB($0,$0,$0))
DrawingFont(FontID(#Police2))
DrawText(ya-TextWidth( FormatDate("%hh:%ii:%ss", Date()) )/2, rezy/2, FormatDate("%hh:%ii:%ss", Date()) ,RGB($FF,$FF,$59),RGB($0,$0,$0))
StopDrawing()
For a=1 To 60
degres =degres+6 : If degres=360:degres=0:EndIf : ; cela fait tourner
xc= RotationX(xa, degres, distance)
Yc= RotationY(ya, degres, distance)
quart=quart+1
If quart=15
quart=0
StartDrawing(WindowOutput(#fenetre))
Circle(xc,Yc,8,RGB($FF,$2D,$2D))
StopDrawing()
EndIf
; ***************** Coloration du Tour ***************************
c_r = Red(tour_col)
c_v = Green(tour_col)
c_b = Blue(tour_col) ;
c_rmem=c_r
c_vmem=c_v
c_bmem=c_b
mem_tour_col= tour_col
c_v=c_v+8
If c_v>250
c_v= 1
EndIf
c_b=c_b+8
If c_b>250
c_b= 1
Delay(25)
EndIf
tour_col=RGB(c_r, c_v, c_b)
StartDrawing(WindowOutput(#fenetre))
Circle(xc,Yc,4,tour_col)
StopDrawing()
; **************************************************
min2=min2+1
If min2=5
StartDrawing(WindowOutput(#fenetre))
Circle(xc,Yc,4,RGB($E7,$F0,$39))
StopDrawing()
min2=0
EndIf
Next a
EndProcedure
;} ****************************************************************************
; Mélanger 2 couleurs
ProcedureDLL.l ColorBlending(Couleur1.l, Couleur2.l, Echelle.f)
;Soldat inconu
Protected rouge, vert, bleu, Rouge2, Vert2, Bleu2
rouge = Couleur1 & $FF
vert = Couleur1 >> 8 & $FF
bleu = Couleur1 >> 16
Rouge2 = Couleur2 & $FF
Vert2 = Couleur2 >> 8 & $FF
Bleu2 = Couleur2 >> 16
rouge = Sqr(rouge * rouge * Echelle + Rouge2 * Rouge2 * (1 - Echelle))
vert = Sqr(vert * vert * Echelle + Vert2 * Vert2 * (1 - Echelle))
bleu = Sqr(bleu * bleu * Echelle + Bleu2 * Bleu2 * (1 - Echelle))
ProcedureReturn (rouge | vert <<8 | bleu << 16)
EndProcedure
; EPB