Draw a clock: Difference between revisions

no edit summary
m (syntax highlighting fixup automation)
No edit summary
Line 263:
SDL.Finalise;
end Draw_A_Clock;</syntaxhighlight>
 
 
=={{header|Amazing Hopper}}==
{{Trans|bbcbasic}}
"Clock" dibujado en modo texto con Hopper-Jambo.
[[File:Captura_de_pantalla_de_2022-10-11_01-10-51.png|200px|thumb|right|Caption]]
<syntaxhighlight lang="txt">
/*
Execute with:
$ hopper jm/clock.jambo -x -o bin/clock
$ rxvt -g 500x250 -fn "xft:FantasqueSansMono-Regular:pixelsize=1" -e ./bin/clock
*/
 
#include <jambo.h>
 
Main
Cls
xp=120, yp=160, size=100, hs=0,ms=0,ss=0, w=0, PI_12=0, PI_60=0
lasth=0, lastm=0, lasts=0, lasttime=0
Let (hs:=Mul(0.45, size)), Let (ms:=Mul(0.75,size)), Let (ss:=ms)
Let (PI_12:= Div(M_PI,12))
Let (PI_60:= Div(M_PI,60))
Color back '14'
Gosub 'Draw body clock'
Tic ( last time )
Loop
On time ( 1000 ~= last time ){
Gosub 'draw clock'
}
Until ( Keypressed )
End
 
Subrutines
 
Define 'draw clock'
h=0, m=0,s=0, t=0
Get only time, Move to 't'
Hours(t), Minutes(t), Seconds(t), Move to 'h, m, s'
 
Color back '0'
Draw a line (xp, yp, #(xp+(hs*sin(d2r(lasth)))), #(yp+(hs*cos(d2r(lasth)))) )
Draw a line (#(xp-1), #(yp-1), #(xp+(hs*sin(d2r(lasth)))), #(yp+(hs*cos(d2r(lasth)))) )
Draw a line (#(xp+1), #(yp+1), #(xp+(hs*sin(d2r(lasth)))), #(yp+(hs*cos(d2r(lasth)))) )
Draw a line (xp, yp, #(xp+(ms*sin(d2r(lastm)))), #(yp+(ms*cos(d2r(lastm)))) )
Draw a line (#(xp-1), #(yp-1), #(xp+(ms*sin(d2r(lastm)))), #(yp+(ms*cos(d2r(lastm)))) )
Draw a line (xp, yp, #(xp+(ss*sin(d2r(lasts)))), #(yp+(ss*cos(d2r(lasts)))) )
Let ( lasts := #(s*6-90) )
Let ( lastm := #(m*6-90) )
Let ( lasth := #((h * 30)+(m/12)*6-90) )
Color back '15'
Draw a line (xp, yp, #(xp+(hs*sin(d2r(lasth)))), #(yp+(hs*cos(d2r(lasth)))) )
Draw a line (#(xp-1), #(yp-1), #(xp+(hs*sin(d2r(lasth)))), #(yp+(hs*cos(d2r(lasth)))) )
Draw a line (#(xp+1), #(yp+1), #(xp+(hs*sin(d2r(lasth)))), #(yp+(hs*cos(d2r(lasth)))) )
Color back '3'
Draw a line (xp, yp, #(xp+(ms*sin(d2r(lastm)))), #(yp+(ms*cos(d2r(lastm)))) )
Draw a line (#(xp-1), #(yp-1), #(xp+(ms*sin(d2r(lastm)))), #(yp+(ms*cos(d2r(lastm)))) )
Color back '13'
Draw a line (xp, yp, #(xp+(ss*sin(d2r(lasts)))), #(yp+(ss*cos(d2r(lasts)))) )
Return
 
Define 'Draw body clock'
Draw a circle ( xp, yp, size )
Draw a circle ( xp, yp, {size} Minus '5' )
/* hour circles ticks*/
Loop for( i=1, #( i<=12), ++i )
Let (w:=#(2*i*PI_12))
Loop for ( j=5, #(j>0), --j )
Draw a circle ( #(xp+size*sin(w)), #(yp+size*cos(w)), j )
Next
Next
/* minutes ticks */
Loop for ( i=1, #( i<=60), ++i )
Let (w:=#(2*i*PI_60))
Draw a line ( #(xp+(size-20)*sin(w)), #(yp+(size-20)*cos(w)),\
#(xp+(size-10)*sin(w)), #(yp+(size-10)*cos(w)))
Next
Return
</syntaxhighlight>
 
=={{header|AutoHotkey}}==
543

edits