Holorge à aiguille en picwin

Contenu du snippet

Comme le titre l'indique il s'agit d'une horloge a aiguille faite dans une picwin.
Le temps est égrener avec un timer 0 1
elle a deux autres fonction :
-compte a rebours
-chronometre
Il y a une possibilité de remise a l'heure manuelle et automatique (a l'heure de l'ordinateur)
On peut rajouter un affichage digitale ( comme sur la capture )
Les heures sont en rouge ainsi que les minutes
les secondes sont en vert

Upadate :
pour lancer l'horloge en mode horloge taper /clock -t
pour lancer l'horloge en mode chronomètre taper /clock -c
pour lancer l'horloge en mode compte a rebours taper /clock -r
(cette derniere fonction n'est pas tout a fait au point)

Source / Exemple :


alias clock { 
  if ( !$hget(t).size ) { hmake t 20 }
  hload -i t horloge.ini h
  if ( $1 = -c) { hadd -m t h 0 | hadd -m t m 0 | hadd -m t s 0 }
  elseif ( $1 = -t ) { exact_h }
  elseif ( $1 = -r ) { 
    var %time = $$?="entrez un temps au format heure:minute:seconde" 
    hadd -m t s $gettok(%time,3,58) 
    hadd -m t m $gettok(%time,2,58) 
    hadd -m t h $iif( $gettok(%time,1,58) < 12 ,$gettok(%time,1,58),$calc($gettok(%time,1,58) -12))
  }
  if ( $window(@horloge)) { clear @horloge }
  else { window -ap @horloge $calc($window(-1).w -218) 0 218 240 }
  put_number | put_h | put_m | put_s | hadd -m t state $1
  var %h = $hget(t,h),%m = $iif($len($hget(t,m)) = 1,0 $+ $hget(t,m),$hget(t,m)),%s = $iif($len($hget(t,s)) = 1,0 $+ $hget(t,s),$hget(t,s))
  set %time $+(%h,:,%m,:,%s)
  .timercercle 0 1 wth2 $1
}

alias wth2 { 
  drawline @horloge 0 0 100 100 $calc(100- 70*$cos($pos.s)) $calc(100- 70*$sin($pos.s))
  if ($1) { goto $1 }
  :-c
  :-t
  hinc t s
  put_s
  draw_aiguille
  if ( $hget(t,s) = 60  ) { hadd -m t s 0 | drawline @horloge 0 0 100 100 $calc(100- 60*$cos($pos.m)) $calc(100- 60*$sin($pos.m)) | hinc t m | put_m }
  if ( $hget(t,m) = 60 ) { hadd -m t m 0 | drawline @horloge 0 0 100 100 $calc(100- 40*$cos($pos.h)) $calc(100- 40*$sin($pos.h)) | hinc t h | if ( $ghet(t,s) != $gettok($time,3,58) ) && ( $1 = -c ) && ( $hget(t,auto) = on ) { exact_h | put_number } | refresh_m | put_m | put_h }
  if ( $hget(t,h) = 13 ) { hadd -m t h 1 | put_number | put_h  }
  goto end
  :-r
  hdec t s
  put_s
  draw_aiguille
  if ( $hget(t,s) = -1  ) { hadd -m t s 59 | drawline @horloge 0 0 100 100 $calc(100- 60*$cos($pos.m)) $calc(100- 60*$sin($pos.m)) | hdec t m | put_m }
  if ( $hget(t,m) = -1 ) { hadd -m t m 59 | drawline @horloge 0 0 100 100 $calc(100- 40*$cos($pos.h)) $calc(100- 40*$sin($pos.h)) | hdec t h | put_m | put_h | refresh_m }
  if ( $hget(t,h) <= 0 ) { hadd -m t h 0 }
  if ( $hget(t,h) = 0 ) && ( $hget(t,m) = 0) && ( $hget(t,s) = 0 ) { echo -a [Horloge] Compte a rembours terminé | .timercercle off | clock -t }
  :end
  if ($hget(t,digit) = on) {
    var %h = $hget(t,h),%m = $iif($len($hget(t,m)) = 1,0 $+ $hget(t,m),$hget(t,m)),%s = $iif($len($hget(t,s)) = 1,0 $+ $hget(t,s),$hget(t,s))
    drawrect @horloge 1 0 76 150 44 12
    drawtext @horloge 0 arial 9 80 150 %time
    drawtext @horloge 1 arial 9 80 150 $+(%h,:,%m,:,%s)
    set %time $+(%h,:,%m,:,%s)
  }
}

alias exact_h { hadd -m t s $gettok($time,3,58) | hadd -m t m $gettok($time,2,58) | hadd -m t h $iif($gettok($time,1,58) <= 12,$ifmatch,$calc($ifmatch -12)) }
alias pos.s { var %itr = 1.5,%i = 2,%r = $iif($hget(t,s) != 0 ,$ifmatch,60) | while ( %i <= %r ) { inc %i | if ( %itr <= 4.7) { inc %itr 0.11 } | else { inc %itr 0.1 } } | return %itr }
alias pos.m { var %itr = 1.5,%i = 2,%r = $iif($hget(t,m) != 0 ,$ifmatch,60) | while ( %i <= %r ) { inc %i | if ( %itr <= 4.7) { inc %itr 0.11 } | else { inc %itr 0.1 } } | return %itr }
alias pos.h { if ( $hget(t,h) = 12) { return 1.5 } | var %itr = 2,%i = 2,%m = $hget(t,h)  | while (%i <= %m ) { inc %i 1 | inc %itr 0.54 } | return %itr }
alias draw_aiguille {
  drawline @horloge 1 0 100 100 $calc(100- 70*$cos($pos.s)) $calc(100- 70*$sin($pos.s))
  drawline @horloge 1 0 100 100 $calc(100- 60*$cos($pos.m)) $calc(100- 60*$sin($pos.m))
  drawline @horloge 1 0 100 100 $calc(100- 40*$cos($pos.h)) $calc(100- 40*$sin($pos.h))
}

alias put_s { 
  var %itr = 1.5,%i = 1,%m = $hget(t,m),%s = $hget(t,s)
  while ( %itr <= 7.7 ) { 
    if ( %i = %m ) || ((%m = 0) && (%s = 1)) { goto end }
    elseif ( %i = $calc(%s -1)) || ( %i = $calc(%s +1)) { drawtext @horloge 1 arial 8 $int($calc(100- (100* $cos(%itr)))) $int($calc(100- (100* $sin(%itr)))) $iif(%i <= 59,%i,0) }
    elseif ( %i = %s) { drawtext @horloge 3 arial 8 $int($calc(100- (100* $cos(%itr)))) $int($calc(100- (100* $sin(%itr)))) $iif(%i <= 59,%i,0) }
    if ( %s = 1 ) { drawtext @horloge 1 arial 8 $int($calc(100- (100* $cos(7.7)))) $int($calc(100- (100* $sin(7.7)))) 0 }
    :end
    inc %i 1
    if ( %itr <= 4.7) { inc %itr 0.11 }
    else { inc %itr 0.1 }
  }
}

alias put_m { 
  var %itr = 1.5,%i = 1,%m = $hget(t,m)
  while ( %itr <= 7.7 ) { 
    if ( %i = $calc(%m -1)) || ( %i = $calc(%m +1)) { drawtext @horloge 1 arial 8 $int($calc(100- (100* $cos(%itr)))) $int($calc(100- (100* $sin(%itr)))) $iif(%i <= 59,%i,0) }
    elseif ( %i = %m) { drawtext @horloge 4 arial 8 $int($calc(100- (100* $cos(%itr)))) $int($calc(100- (100* $sin(%itr)))) $iif(%i <= 59,%i,0) }
    elseif ( %m = 0 ) { drawtext @horloge 4 arial 8 $int($calc(100- (100* $cos(7.7)))) $int($calc(100- (100* $sin(7.7)))) 0  }
    inc %i 1
    if ( %itr <= 4.7) { inc %itr 0.11 }
    else { inc %itr 0.1 }
  }
}

alias put_h { 
  if ( $hget(t,h) = 12) { 
    drawtext @horloge 4 arial 8 $int($calc(100- (80* $cos(1.5)))) $int($calc(100- (80* $sin(1.5)))) 12
    drawtext @horloge 1 arial 8 $int($calc(100- (80* $cos(7.4)))) $int($calc(100- (80* $sin(7.4)))) 11
  }
  else {
    var %itr = 2,%i = 1,%h = $hget(t,h)
    while (%itr <= 7.7) {
      if ( %i = $calc(%h  -1)) || ( %i = $calc(%h +1)) { drawtext @horloge 1 arial 8 $int($calc(100- (80* $cos(%itr)))) $int($calc(100- (80* $sin(%itr)))) %i }
      elseif ( %i = %h) { drawtext @horloge 4 arial 8 $int($calc(100- (80* $cos(%itr)))) $int($calc(100- (80* $sin(%itr)))) %i }
      inc %i 1
      inc %itr 0.54
    }
    drawtext @horloge 1 arial 8 $int($calc(100- (80* $cos(1.5)))) $int($calc(100- (80* $sin(1.5)))) 12
  }
}

alias put_number {
  clear @horloge
  var %itr = 2,%i = 1
  while (%itr <= 7.7) {
    drawtext @horloge 1 arial 8 $int($calc(100- (80* $cos(%itr)))) $int($calc(100- (80* $sin(%itr)))) %i
    inc %i 1
    inc %itr 0.54
  }
  drawtext @horloge 1 arial 8 $int($calc(100- (80* $cos(1.5)))) $int($calc(100- (80* $sin(1.5)))) 12
  refresh_m
}

alias refresh_m { 
  var %itr = 1.5,%i = 1
  while ( %itr <= 7.7 ) { 
    drawtext @horloge 1 arial 8 $int($calc(100- (100* $cos(%itr)))) $int($calc(100- (100* $sin(%itr)))) $iif(%i <= 59,%i,0)
    inc %i 1
    if ( %itr <= 4.7) { inc %itr 0.11 }
    else { inc %itr 0.1 }
  }
}

menu @horloge { 
  Arreter l'horloge : .timercercle off | hsave -i t horloge.ini h | hfree t
  Fermer l'horloge : .timercercle off | window -c @horloge | if ($hget(t).size ) { hsave -i t horloge.ini h | hfree t }
  $iif($hget(t,state) = -t,Mettre a l'heure de l'ordinateur) : exact_h | put_number | put_h | put_m 
  Mode de l'horloge
  .Horloge : clock -t
  .Chronometre : clock -c
  .Compte a rebour : clock -r
  Ecriture Digitale $hget(t,digit)
  .$iif($hget(t,digit) = on,Désactivée,Activé) : { if ( $hget(t,digit) = on ) { hadd -m t digit off | echo -a $hget(t,digit) } | else { hadd -m t digit on | echo -a $hget(t,digit) } }
  $iif($hget(t,state) = -t,Remise a l'heure) 
  .Heure :  { 
    :start1
    var %h = $$?="entrez une heure s'il vous plus entre 0 et 12"
    if (%h > 12) { goto start1 }
    else { hadd -m t m %h }
  }
  .Minute : { 
    :start2
    var %m = $$?="entrez un nombre de minute s'il vous plait entre 0 et 59" 
    if (%m > 59 ) { goto start2 }
    else { hadd -m t m %m }
  }
  .Seconde : {
    :start3
    var %s = $$?="entrez un nombre de seconde s'il vous plait entre 0 et 59" 
    if (%s > 59) { goto start3 }
    else { hadd -m t m %s }
  }
  .Automatique $hget(t,auto)
  ..$iif($hget(t,auto) = on,desactivée,activée) : if ( $hget(t,auto) = on ) { hadd -m t auto off } | else { hadd -m t auto on }
}

Conclusion :


Ce n'est pas réellement un addon, des modules peuven etre ajouter, comme la mise a l'heure en prenant l'heure d'une horloge atomique ( en socket )
ou alors l'utilisation du fomat gmt etc etc

J'ai un enorme problème avec le compte a rebours, je n'arrive pas a éffacéles aiguilles des minutes, c'est assez problématique... :(

je devrais pouvoir regler ça un jour ou l'autre.

Aussi note importante. J'ai mis peu de module parce que la précision de l'horloge diminue avec la longueur de l'alias lancé par le timer. d'ou les sauts de label qui "racoursisseent" le code sans passer par des if trop long.

Donc si vous voulez rajouter des modules a l'horloge prenez garde a ceci.

Update 1:
Dragoon1 m'a fait remarquer la présence de certains bugs. Ils ont été corrigés.

Upadte 2:
Suite aux remarques de PaDa correction des bugs rencontrés.

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.