Page 2 sur 2

Re: Horloge Binaire

Publié : sam. 21/août/2010 13:45
par venom
:lol: lol j'ai penser peut être en faire un écran de veille car le plus gros est fait.
je vais voir plus tard





@++

Re: Horloge Binaire

Publié : mar. 15/févr./2011 0:07
par Backup
je me suis permis de retoucher un peu ton code
parceque repeter autant de fois les memes lignes c'etait pas geant :)

j'ai donc utilisé les sprites , et utilisé la fonction bin() en conjonction avec Stringfield()
ça raccourci le code :)


; by Venom
; arrangé par Dobro ;

Global Dim tableau.S (6)
Enumeration
         #sprite_bleu
         #sprite_rouge
         #window
EndEnumeration

initsprite ()

If openwindow ( #window , 0, 0, 600, 400, "Binary Clock" , #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered )
         openwindowedscreen ( windowid ( #window ),0,0,600,400,1,0,0)
         setframerate (25)
         fontid = loadfont (8, "Arial Black" , 95, #PB_Font_Bold )
        F2 = loadfont (9, "Arial Black" , 9, #PB_Font_Bold )
        
         ; ********* creation de sprite *************
         createsprite ( #sprite_rouge ,55,55)
         startdrawing ( spriteoutput ( #sprite_rouge ))
                c=1
                 For i=27 To 2 Step -2
                         circle (25, 25, i, rgb (0, c, 0))
                        c=c+10
                 Next i
         stopdrawing ()
        
         createsprite ( #sprite_bleu ,50,50)
         startdrawing ( spriteoutput ( #sprite_bleu ))
                 circle (25, 25, 25, rgb (0, 0, 30))
         stopdrawing ()
         ; ***************************************
         addwindowtimer ( #window , 123,1000)
         Repeat
                Event = waitwindowevent (2)
                 Select Event
                        Case#PB_Event_Gadget
                         Case #PB_Event_Timer
                                 If eventtimer () = 123
                                         If startdrawing ( screenoutput ())
                                                        y=320 : x=580
                                                         drawingfont (F2)
                                                         drawtext (x, y, "1" , rgb (0, 255, 0), rgb (0, 0, 0)) :y-50
                                                         drawtext (x, y, "2" , rgb (0, 255, 0), rgb (0, 0, 0)) :y-50
                                                         drawtext (x, y, "4" , rgb (0, 255, 0), rgb (0, 0, 0)) :y-50
                                                         drawtext (x, y, "8" , rgb (0, 255, 0), rgb (0, 0, 0))
                                                         drawingfont ( fontid )
                                                        date$ = formatdate ( "%hh:%ii:%ss" , date ())
                                                         drawtext (0, -30, date$, rgb (0, 100, 0), rgb (0, 0, 0))
                                                        heure_dizaine$= mid ( bin ( val ( left ( stringfield (date$,1, ":" ),1))),1,2)
                                                        heure_unite$= mid ( bin ( val ( right ( stringfield (date$,1, ":" ),1))),1,4)
                                                        minute_dizaine$= mid ( bin ( val ( left ( stringfield (date$,2, ":" ),1))),1,3)
                                                        minute_unite$= mid ( bin ( val ( right ( stringfield (date$,2, ":" ),1))),1,4)
                                                        seconde_dizaine$= mid ( bin ( val ( left ( stringfield (date$,3, ":" ),1))),1,3)
                                                        seconde_unite$= mid ( bin ( val ( right ( stringfield (date$,3, ":" ),1))),1,4)
                                                        
                                                         ;{ ******** dessine le decors **********************
                                                         Restore sprite_bleu:
                                                         ; ++++++++++ dizaine heur bleu +++++++++
                                                         For o=1 To 6
                                                                 Read n
                                                                 Read p
                                                                y=300
                                                                 For i=1 To n
                                                                         displaysprite ( #sprite_bleu ,p,y)
                                                                        y=y-50
                                                                 Next i
                                                         Next o
                                                         ; ++++++++++++++++++++++++++++++++++++++
                                                         ;}
                                                         ;{ affichage de l'heure
                                                         ; ++++++++++ dizaine heur rouge +++++++++
                                                        tableau.S (1)=heure_dizaine$
                                                        tableau.S (2)=heure_unite$
                                                        tableau.S (3)=minute_dizaine$
                                                        tableau.S (4)=minute_unite$
                                                        tableau.S (5)=seconde_dizaine$
                                                        tableau.S (6)=seconde_unite$
                                                         Restore sprite_rouge
                                                         For o=1 To 6
                                                                 Read y
                                                                 Read n
                                                                 Read p
                                                                var$=tableau.S (o)
                                                                 For i=1 To n
                                                                         If len (var$)<n
                                                                                var$= "0" +var$
                                                                         EndIf
                                                                         If mid (var$,i,1)= "1"
                                                                                 displaytransparentsprite ( #sprite_rouge ,p,y)
                                                                         EndIf
                                                                        y=y+50
                                                                 Next i
                                                         Next o
                                                         ; ++++++++++++++++++++++++++++++++++++++
                                                         ;} ++++++++++++++++++++++++++++++++++++++
                                                 stopdrawing ()
                                         EndIf
                                 EndIf
                                 ; ; ++++++++++++++++++++++++++++++++++++++
                                 flipbuffers ()
                                 clearscreen ( rgb (0,0,0))
                 EndSelect
         Until Event = #PB_Event_CloseWindow
EndIf
        
        

DataSection
        sprite_bleu:
        Data.i 2,50,4,100,3,250,4,300,3,450,4,500
        sprite_rouge:
        Data.i 250,2,50,150,4,100,200,3,250,150,4,300,200,3,450,150,4,500
EndDataSection

Re: Horloge Binaire

Publié : mar. 15/févr./2011 9:44
par Backup
petite optimisation supplémentaire
par l'utilisation des Data :)

[Reedit]
et changé le look de mes sprites ;)

[Reedit2]
et arrangé la disposition

Re: Horloge Binaire

Publié : mar. 15/févr./2011 10:44
par Backup
...

Re: Horloge Binaire

Publié : mar. 15/févr./2011 11:33
par flaith
Dobro a écrit :et voici une petite Variante :)
J'aime beaucoup cette variante :D

Re: Horloge Binaire

Publié : mar. 15/févr./2011 13:26
par Backup
Merci :)

code mis a jour a la demande d'un anglais
sans Api pour le timer :) (donc ça doit etre portable sous linux.. en principe)

Re: Horloge Binaire

Publié : mar. 15/févr./2011 14:02
par Cls
Ah oui, très sympa ! :)

Re: Horloge Binaire

Publié : mer. 16/févr./2011 21:15
par venom
wouah sympa tes optimisation et variante Dobro :wink:
sa change du miens :lol: je regarderais sa de plus près.








@++

Re: Horloge Binaire

Publié : mer. 16/févr./2011 22:51
par Cool Dji
Super sympa => cela ferait un très bon exemple pour un pure punch !!