Draw a clock: Difference between revisions

Content deleted Content added
Chkas (talk | contribs)
Chkas (talk | contribs)
 
(88 intermediate revisions by 37 users not shown)
Line 21:
 
=={{header|ActionScript}}==
<syntaxhighlight lang="actionscript">
<lang ActionScript>
package {
Line 160:
 
}
</syntaxhighlight>
</lang>
 
=={{header|Ada}}==
{{libheader|SDLAda}}
<syntaxhighlight lang="ada">with Ada.Numerics.Elementary_Functions;
with Ada.Calendar.Formatting;
with Ada.Calendar.Time_Zones;
 
with SDL.Video.Windows.Makers;
with SDL.Video.Renderers.Makers;
with SDL.Events.Events;
 
procedure Draw_A_Clock is
use Ada.Calendar;
use Ada.Calendar.Formatting;
Window : SDL.Video.Windows.Window;
Renderer : SDL.Video.Renderers.Renderer;
Event : SDL.Events.Events.Events;
Offset : Time_Zones.Time_Offset;
 
procedure Draw_Clock (Stamp : Time)
is
use SDL.C;
use Ada.Numerics.Elementary_Functions;
Radi : constant array (0 .. 59) of int := (0 | 15 | 30 | 45 => 2,
5 | 10 | 20 | 25 | 35 | 40 | 50 | 55 => 1,
others => 0);
Diam : constant array (0 .. 59) of int := (0 | 15 | 30 | 45 => 5,
5 | 10 | 20 | 25 | 35 | 40 | 50 | 55 => 3,
others => 1);
Width : constant int := Window.Get_Surface.Size.Width;
Height : constant int := Window.Get_Surface.Size.Height;
Radius : constant Float := Float (int'Min (Width, Height));
R_1 : constant Float := 0.48 * Radius;
R_2 : constant Float := 0.35 * Radius;
R_3 : constant Float := 0.45 * Radius;
R_4 : constant Float := 0.47 * Radius;
Hour : constant Hour_Number := Formatting.Hour (Stamp, Offset);
Minute : constant Minute_Number := Formatting.Minute (Stamp, Offset);
Second : constant Second_Number := Formatting.Second (Stamp);
 
function To_X (A : Float; R : Float) return int is
(Width / 2 + int (R * Sin (A, 60.0)));
 
function To_Y (A : Float; R : Float) return int is
(Height / 2 - int (R * Cos (A, 60.0)));
 
begin
SDL.Video.Renderers.Makers.Create (Renderer, Window.Get_Surface);
Renderer.Set_Draw_Colour ((0, 0, 150, 255));
Renderer.Fill (Rectangle => (0, 0, Width, Height));
Renderer.Set_Draw_Colour ((200, 200, 200, 255));
for A in 0 .. 59 loop
Renderer.Fill (Rectangle => (To_X (Float (A), R_1) - Radi (A),
To_Y (Float (A), R_1) - Radi (A), Diam (A), Diam (A)));
end loop;
Renderer.Set_Draw_Colour ((200, 200, 0, 255));
Renderer.Draw (Line => ((Width / 2, Height / 2),
(To_X (5.0 * (Float (Hour) + Float (Minute) / 60.0), R_2),
To_Y (5.0 * (Float (Hour) + Float (Minute) / 60.0), R_2))));
Renderer.Draw (Line => ((Width / 2, Height / 2),
(To_X (Float (Minute) + Float (Second) / 60.0, R_3),
To_Y (Float (Minute) + Float (Second) / 60.0, R_3))));
Renderer.Set_Draw_Colour ((220, 0, 0, 255));
Renderer.Draw (Line => ((Width / 2, Height / 2),
(To_X (Float (Second), R_4),
To_Y (Float (Second), R_4))));
Renderer.Fill (Rectangle => (Width / 2 - 3, Height / 2 - 3, 7, 7));
end Draw_Clock;
 
function Poll_Quit return Boolean is
use type SDL.Events.Event_Types;
begin
while SDL.Events.Events.Poll (Event) loop
if Event.Common.Event_Type = SDL.Events.Quit then
return True;
end if;
end loop;
return False;
end Poll_Quit;
 
begin
Offset := Time_Zones.UTC_Time_Offset;
 
if not SDL.Initialise (Flags => SDL.Enable_Screen) then
return;
end if;
 
SDL.Video.Windows.Makers.Create (Win => Window,
Title => "Draw a clock",
Position => SDL.Natural_Coordinates'(X => 10, Y => 10),
Size => SDL.Positive_Sizes'(300, 300),
Flags => SDL.Video.Windows.Resizable);
loop
Draw_Clock (Clock);
Window.Update_Surface;
delay 0.200;
exit when Poll_Quit;
end loop;
 
Window.Finalize;
SDL.Finalise;
end Draw_A_Clock;</syntaxhighlight>
 
 
=={{header|Amazing Hopper}}==
{{Trans|bbcbasic}}
{{Trans|baCon}}
"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>
 
#define ONESECOND 1000
 
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 ( ONE SECOND ~= 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}}==
Line 166 ⟶ 372:
this code from http://www.autohotkey.com/forum/viewtopic.php?p=231836#231836
draws a very nice clock with GDI+
<langsyntaxhighlight AHKlang="ahk">; gdi+ ahk analogue clock example written by derRaphael
; Parts based on examples from Tic's GDI+ Tutorials and of course on his GDIP.ahk
 
Line 310 ⟶ 516:
Gdip_Shutdown(pToken)
ExitApp
Return</langsyntaxhighlight>
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f DRAW_A_CLOCK.AWK [-v xc="*"]
BEGIN {
Line 363 ⟶ 570:
}
}
</syntaxhighlight>
</lang>
{{out|Sample run and output}}
<pre>
Line 377 ⟶ 584:
#### #### ####### #### #### ####
</pre>
 
=={{header|BASIC}}==
 
==={{header|AmigaBASIC}}===
[[File:Amigabasic clock.png|thumb|Output]]
<syntaxhighlight lang="qbasic">xp=320:yp=95:size=150
CIRCLE (xp,yp),size,,,,.5
lasth=0:lastm=0:lasts=0
hs=.25*size:ms=.45*size:ss=ms
pi=3.141592
 
FOR i=1 TO 12
w=2*i*pi/12
CIRCLE (xp+size*SIN(w),yp+size/2*COS(w)),size/15
NEXT
 
ON TIMER(1) GOSUB Clock
TIMER ON
 
loop: GOTO loop
 
Clock:
t$=TIME$
h=VAL(MID$(t$,1,2))
m=VAL(MID$(t$,4,2))
s=VAL(MID$(t$,7,2))
LOCATE 1,1:PRINT t$
LINE (xp,yp)-(xp+2*hs*SIN(lasth),yp-hs*COS(lasth)),0
LINE (xp,yp)-(xp+2*ms*SIN(lastm),yp-ms*COS(lastm)),0
LINE (xp,yp)-(xp+2*ss*SIN(lasts),yp-ss*COS(lasts)),0
lasth=2*pi*(h/12+m/720)
lastm=2*pi*m/60
lasts=2*pi*s/60
LINE (xp,yp)-(xp+2*hs*SIN(lasth),yp-hs*COS(lasth)),1
LINE (xp,yp)-(xp+2*ms*SIN(lastm),yp-ms*COS(lastm)),1
LINE (xp,yp)-(xp+2*ss*SIN(lasts),yp-ss*COS(lasts)),2
RETURN</syntaxhighlight>
 
==={{header|BaCon}}===
Using GTK3 as a graphical toolkit.
<syntaxhighlight lang="bacon">OPTION GUI TRUE
PRAGMA GUI gtk3
 
CONST HLEN = 140
CONST ALEN = 90
 
id = GUIDEFINE(" \
{ type=WINDOW name=window callback=delete-event resizable=0 title=\"Analog Clock\" } \
{ type=DRAWING_AREA name=drawing parent=window callback=draw width-request=300 height-request=300 } ")
 
WHILE TRUE
SELECT GUIEVENT$(id)
CASE "window"
BREAK
CASE "drawing"
CALL Draw
ENDSELECT
WEND
 
SUB Draw
 
LOCAL context TYPE GdkDrawingContext*
LOCAL cr TYPE cairo_t*
LOCAL gdk TYPE GdkWindow*
 
' Get drawing window
CALL GUIGET(id, "drawing", "window", &gdk)
 
' Setup drawing context
context = gdk_window_begin_draw_frame(gdk, gdk_window_get_clip_region(gdk))
 
' Get cairo context
cr = gdk_drawing_context_get_cairo_context(context)
 
' Clear
CALL cairo_set_source_rgba(cr, 1, 1, 1, 1)
CALL cairo_rectangle(cr, 0, 0, 300, 300)
CALL cairo_fill(cr)
 
' Draw centre
CALL cairo_set_source_rgba(cr, 0, 0, 0, 1)
CALL cairo_arc(cr, 150, 150, 10, 0, 2*PI)
CALL cairo_fill(cr)
 
' Draw second
s = SECOND(NOW)*6-90
CALL cairo_set_line_width(cr, 1)
CALL cairo_move_to(cr, 150, 150)
CALL cairo_line_to(cr, 150 + HLEN*COS(RAD(s)), 150 + HLEN*SIN(RAD(s)))
CALL cairo_stroke(cr)
CALL cairo_fill(cr)
 
' Draw minute
m = MINUTE(NOW)*6-90
CALL cairo_set_line_width(cr, 2)
CALL cairo_move_to(cr, 150, 150)
CALL cairo_line_to(cr, 150 + HLEN*COS(RAD(m)), 150 + HLEN*SIN(RAD(m)))
CALL cairo_stroke(cr)
CALL cairo_fill(cr)
 
' Draw hour
h = IIF(HOUR(NOW)>12, HOUR(NOW)-12, HOUR(NOW))*30+(MINUTE(NOW)/12)*6-90
CALL cairo_move_to(cr, 150, 150)
CALL cairo_line_to(cr, 150 + ALEN*COS(RAD(h)), 150 + ALEN*SIN(RAD(h)))
CALL cairo_stroke(cr)
CALL cairo_fill(cr)
 
' Finish drawing
CALL gdk_window_end_draw_frame(gdk, context)
 
' Draw each second
ALARM Draw, 1000
 
ENDSUB
</syntaxhighlight>
 
==={{header|uBasic/4tH}}===
This program requires an ANSI terminal for the best results.
<syntaxhighlight lang="uBasic/4tH">Dim @c(3)
' clock digits
@c(0) := " _ _ _ _ __ _ _ "
@c(1) := "/ \\ /| ) _)|_||_ / /(_)(_) * "
@c(2) := "\\_/ | /_ _) | _)(_) / (_) / * "
 
p = 0 ' previous time equals zero
 
Do ' repeat forever
Do
t = Time() % 86400 ' get the time and encode it
t = ((t / 3600) * 10000) + ((t % 3600) / 60) * 100 + ((t % 3600) % 60)
Until t > p ' until a second has been passed
Loop
 
p = t : Print "\e[2J\e[H" ' set old time to new time
' clear screen
For x = 0 To 2 ' for all rows
d = t ' preserve time
For y = 5 To 0 Step -1 ' get all digit columns
Print Show(FUNC(_Figure(d/(10^y), x)));
If y%2 = 0 Then If y Then Print Show(FUNC(_Figure(10, x)));
d = d%(10^y) ' get next digit column
Next : Print ' next column, terminate row
Next ' next row
Loop ' next second
End
' get figure row/column
_Figure: Param (2) : Return (Clip(Chop(@c(b@), a@ * 3), (10-a@) * 3))</syntaxhighlight>
{{Out}}
<pre> _ _ _ _ _
/ \(_) * / \|_| * |_ (_)
\_/ / * \_/ | * _)(_)</pre>
 
==={{header|BBC BASIC}}===
<syntaxhighlight lang="bbcbasic">
CLS
xp=320:yp=160:size=150
CIRCLE xp, yp, size
lasth=0:lastm=0:lasts=0
hs=.25*size:ms=.45*size:ss=ms
 
FOR i=1 TO 12
w=2*i*PI/12
CIRCLE FILL xp+size*SIN(w), yp+size*COS(w),size/15
NEXT
 
lasttime$ = TIME$
WHILE TRUE
IF lasttime$ <> TIME$ THENPROCclock:lasttime$=TIME$
WAIT
ENDWHILE
 
DEFPROCclock
t$=TIME$
h=VAL(MID$(t$,17,2))
m=VAL(MID$(t$,20,2))
s=VAL(MID$(t$,23,2))
PRINT TAB(0,0);t$
GCOL 0,0
LINE xp, yp, xp+2*hs*SIN(lasth), yp+hs*COS(lasth)
LINE xp, yp, xp+2*ms*SIN(lastm), yp+ms*COS(lastm)
LINE xp, yp, xp+2*ss*SIN(lasts), yp+ss*COS(lasts)
lasth=2*PI*(h/12+m/720)
lastm=2*PI*m/60
lasts=2*PI*s/60
GCOL 0, 1
LINE xp, yp, xp+2*hs*SIN(lasth), yp+hs*COS(lasth)
LINE xp, yp, xp+2*ms*SIN(lastm), yp+ms*COS(lastm)
GCOL 0, 2
LINE xp, yp, xp+2*ss*SIN(lasts), yp+ss*COS(lasts)
ENDPROC
</syntaxhighlight>
 
==={{header|Commodore BASIC}}===
To be entered in upper/lowercase mode but run in uppercase + graphics mode.
<langsyntaxhighlight lang="commodorebasic">10 gosub 1500: rem setup clock digit strings
20 ti$ = "123456"
25 rem do some other stuff after this line
Line 411 ⟶ 809:
1540 z$(4) = "B B B B B B BB BB B B"
1550 z$(5) = "JCKCCCJCCCCK BCCKJCKJCK CK"
1560 return</langsyntaxhighlight>
 
==={{header|IS-BASIC}}===
<langsyntaxhighlight ISlang="is-BASICbasic">100 PROGRAM "Clock.bas"
110 OPTION ANGLE DEGREES
120 LET CH=1:LET CH2=2
Line 434 ⟶ 832:
290 CLOSE #2
300 CLOSE #1
310 TEXT</langsyntaxhighlight>
 
=={{header|Batch File}}==
<langsyntaxhighlight lang="dos">::Draw a Clock Task from Rosetta Code Wiki
::Batch File Implementation
::
Line 444 ⟶ 842:
title Sample Batch Clock
setlocal enabledelayedexpansion
chcp 65001
 
::Set the characters...
set "#0_1=ÛÛÛÛÛ█████"
set "#0_2=Û Û"
set "#0_3=Û Û"
set "#0_4=Û Û"
set "#0_5=ÛÛÛÛÛ█████"
 
set "#1_1= Û"
set "#1_2= Û"
set "#1_3= Û"
set "#1_4= Û"
set "#1_5= Û"
 
set "#2_1=ÛÛÛÛÛ█████"
set "#2_2= Û"
set "#2_3=ÛÛÛÛÛ█████"
set "#2_4=Û "
set "#2_5=ÛÛÛÛÛ█████"
 
set "#3_1=ÛÛÛÛÛ█████"
set "#3_2= Û"
set "#3_3=ÛÛÛÛÛ█████"
set "#3_4= Û"
set "#3_5=ÛÛÛÛÛ█████"
 
set "#4_1=Û Û"
set "#4_2=Û Û"
set "#4_3=ÛÛÛÛÛ█████"
set "#4_4= Û"
set "#4_5= Û"
 
set "#5_1=ÛÛÛÛÛ█████"
set "#5_2=Û "
set "#5_3=ÛÛÛÛÛ█████"
set "#5_4= Û"
set "#5_5=ÛÛÛÛÛ█████"
 
set "#6_1=ÛÛÛÛÛ█████"
set "#6_2=Û "
set "#6_3=ÛÛÛÛÛ█████"
set "#6_4=Û Û"
set "#6_5=ÛÛÛÛÛ█████"
 
set "#7_1=ÛÛÛÛÛ█████"
set "#7_2= Û"
set "#7_3= Û"
set "#7_4= Û"
set "#7_5= Û"
 
set "#8_1=ÛÛÛÛÛ█████"
set "#8_2=Û Û"
set "#8_3=ÛÛÛÛÛ█████"
set "#8_4=Û Û"
set "#8_5=ÛÛÛÛÛ█████"
 
set "#9_1=ÛÛÛÛÛ█████"
set "#9_2=Û Û"
set "#9_3=ÛÛÛÛÛ█████"
set "#9_4= Û"
set "#9_5=ÛÛÛÛÛ█████"
 
set "#C_1= "
set "#C_2=Û"
set "#C_3= "
set "#C_4=Û"
set "#C_5= "
 
Line 542 ⟶ 941:
echo.
timeout /t 1 /nobreak >nul
goto :clock_loop</langsyntaxhighlight>
{{Out}}
<pre>
Line 554 ⟶ 953:
=={{header|C}}==
Draws a crude clock in terminal. C99, compiled with <code>gcc -std=c99</code>.
<langsyntaxhighlight Clang="c">#include <stdio.h>
#include <stdlib.h>
#include <math.h>
Line 646 ⟶ 1,045:
draw(s);
return 0;
}</langsyntaxhighlight>
===Clock in xlib (for X windows)===
<syntaxhighlight lang="c">// clockrosetta.c - https://rosettacode.org/wiki/Draw_a_clock
 
// # Makefile
// CFLAGS = -O3 -Wall -Wfatal-errors -Wpedantic -Werror
// LDLIBS = -lX11 -lXext -lm
// all: clockrosetta
 
#define SIZE 500
 
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/select.h>
#include <time.h>
#include <X11/extensions/Xdbe.h>
#include <math.h>
 
static XdbeBackBuffer dbewindow = 0;
static Display *display;
static Window window;
static int needseg = 1;
static double d2r;
static XSegment seg[61];
static GC gc;
static int mw = SIZE / 2;
static int mh = SIZE / 2;
 
static void
draw(void)
{
struct tm *ptm;
int i;
double angle;
double delta;
int radius = (mw < mh ? mw : mh) - 2;
XPoint pt[3];
double onetwenty = 3.1415926 * 2 / 3;
XdbeSwapInfo swapi;
time_t newtime;
 
if(dbewindow == 0)
{
dbewindow = XdbeAllocateBackBufferName(display, window, XdbeBackground);
XClearWindow(display, window);
}
 
time(&newtime);
ptm = localtime(&newtime);
 
if(needseg)
{
d2r = atan2(1.0, 0.0) / 90.0;
for(i = 0; i < 60; i++)
{
angle = (double)i * 6.0 * d2r;
delta = i % 5 ? 0.97 : 0.9;
seg[i].x1 = mw + radius * delta * sin(angle);
seg[i].y1 = mh - radius * delta * cos(angle);
seg[i].x2 = mw + radius * sin(angle);
seg[i].y2 = mh - radius * cos(angle);
}
needseg = 0;
}
 
angle = (double)(ptm->tm_sec) * 6.0 * d2r;
seg[60].x1 = mw;
seg[60].y1 = mh;
seg[60].x2 = mw + radius * 0.9 * sin(angle);
seg[60].y2 = mh - radius * 0.9 * cos(angle);
XDrawSegments(display, dbewindow, gc, seg, 61);
 
angle = (double)ptm->tm_min * 6.0 * d2r;
pt[0].x = mw + radius * 3 / 4 * sin(angle);
pt[0].y = mh - radius * 3 / 4 * cos(angle);
pt[1].x = mw + 6 * sin(angle + onetwenty);
pt[1].y = mh - 6 * cos(angle + onetwenty);
pt[2].x = mw + 6 * sin(angle - onetwenty);
pt[2].y = mh - 6 * cos(angle - onetwenty);
XFillPolygon(display, dbewindow, gc, pt, 3, Nonconvex, CoordModeOrigin);
 
angle = (double)(ptm->tm_hour * 60 + ptm->tm_min) / 2.0 * d2r;
pt[0].x = mw + radius / 2 * sin(angle);
pt[0].y = mh - radius / 2 * cos(angle);
pt[1].x = mw + 6 * sin(angle + onetwenty);
pt[1].y = mh - 6 * cos(angle + onetwenty);
pt[2].x = mw + 6 * sin(angle - onetwenty);
pt[2].y = mh - 6 * cos(angle - onetwenty);
XFillPolygon(display, dbewindow, gc, pt, 3, Nonconvex, CoordModeOrigin);
 
swapi.swap_window = window;
swapi.swap_action = XdbeBackground;
XdbeSwapBuffers(display, &swapi, 1);
}
 
int
main(int argc, char *argv[])
{
Atom wm_both_protocols[1];
Atom wm_delete;
Atom wm_protocols;
Window root;
XEvent event;
XSetWindowAttributes attr;
fd_set fd;
int exposed = 0;
int more = 1;
struct timeval tv;
 
display = XOpenDisplay(NULL);
 
if(display == NULL)
{
fprintf(stderr,"Error: The display cannot be opened\n");
exit(1);
}
 
root = DefaultRootWindow(display);
wm_delete = XInternAtom(display, "WM_DELETE_WINDOW", False);
wm_protocols = XInternAtom(display, "WM_PROTOCOLS", False);
 
attr.background_pixel = 0x000000;
attr.event_mask = KeyPress | KeyRelease |
ButtonPressMask | ButtonReleaseMask | ExposureMask;
 
window = XCreateWindow(display, root,
0, 0, SIZE, SIZE, 0,
CopyFromParent, InputOutput, CopyFromParent,
CWBackPixel | CWEventMask,
&attr
);
 
XStoreName(display, window, "Clock for RosettaCode");
 
wm_both_protocols[0] = wm_delete;
XSetWMProtocols(display, window, wm_both_protocols, 1);
 
gc = XCreateGC(display, window, 0, NULL);
XSetForeground(display, gc, 0xFFFF80);
 
XMapWindow(display, window);
 
while(more)
{
if(QLength(display) > 0)
{
XNextEvent(display, &event);
}
else
{
int maxfd = ConnectionNumber(display);
 
XFlush(display);
FD_ZERO(&fd);
FD_SET(ConnectionNumber(display), &fd);
 
event.type = LASTEvent;
tv.tv_sec = 0;
tv.tv_usec = 250000;
if(select(maxfd + 1, &fd, NULL, NULL, &tv) > 0)
{
if(FD_ISSET(ConnectionNumber(display), &fd))
{
XNextEvent(display, &event);
}
}
}
 
switch(event.type)
{
case Expose:
exposed = 1;
draw();
break;
 
case ButtonRelease:
case KeyRelease:
more = 0;
case ButtonPress: // ignore
case KeyPress: // ignore
break;
 
case LASTEvent: // the timeout comes here
if(exposed) draw();
break;
 
case ConfigureNotify:
mw = event.xconfigure.width / 2;
mh = event.xconfigure.height / 2;
needseg = 1;
break;
 
 
case ClientMessage: // for close request from WM
if(event.xclient.window == window &&
event.xclient.message_type == wm_protocols &&
event.xclient.format == 32 &&
event.xclient.data.l[0] == wm_delete)
{
more = 0;
}
break;
 
// default:
// printf("unexpected event.type %d\n", event.type);;
}
}
 
XCloseDisplay(display);
exit(0);
}
 
// END</syntaxhighlight>
 
=={{header|C sharp|C#}}==
<syntaxhighlight lang="csharp">using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
 
public class Clock : Form
{
static readonly float degrees06 = (float)Math.PI / 30;
static readonly float degrees30 = degrees06 * 5;
static readonly float degrees90 = degrees30 * 3;
 
readonly int margin = 20;
 
private Point p0;
 
public Clock()
{
Size = new Size(500, 500);
StartPosition = FormStartPosition.CenterScreen;
Resize += (sender, args) => ResetSize();
ResetSize();
var timer = new Timer() { Interval = 1000, Enabled = true };
timer.Tick += (sender, e) => Refresh();
DoubleBuffered = true;
}
 
private void ResetSize()
{
p0 = new Point(ClientRectangle.Width / 2, ClientRectangle.Height / 2);
Refresh();
}
 
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
 
drawFace(e.Graphics);
 
var time = DateTime.Now;
int second = time.Second;
int minute = time.Minute;
int hour = time.Hour;
 
float angle = degrees90 - (degrees06 * second);
DrawHand(e.Graphics, Pens.Red, angle, 0.95);
 
float minsecs = (minute + second / 60.0F);
angle = degrees90 - (degrees06 * minsecs);
DrawHand(e.Graphics, Pens.Black, angle, 0.9);
 
float hourmins = (hour + minsecs / 60.0F);
angle = degrees90 - (degrees30 * hourmins);
DrawHand(e.Graphics, Pens.Black, angle, 0.6);
}
 
private void drawFace(Graphics g)
{
int radius = Math.Min(p0.X, p0.Y) - margin;
g.FillEllipse(Brushes.White, p0.X - radius, p0.Y - radius, radius * 2, radius * 2);
 
for (int h = 0; h < 12; h++)
DrawHand(g, Pens.LightGray, h * degrees30, -0.05);
 
for (int m = 0; m < 60; m++)
DrawHand(g, Pens.LightGray, m * degrees06, -0.025);
}
 
private void DrawHand(Graphics g, Pen pen, float angle, double size)
{
int radius = Math.Min(p0.X, p0.Y) - margin;
 
int x0 = p0.X + (size > 0 ? 0 : Convert.ToInt32(radius * (1 + size) * Math.Cos(angle)));
int y0 = p0.Y + (size > 0 ? 0 : Convert.ToInt32(radius * (1 + size) * Math.Sin(-angle)));
 
int x1 = p0.X + Convert.ToInt32(radius * (size > 0 ? size : 1) * Math.Cos(angle));
int y1 = p0.Y + Convert.ToInt32(radius * (size > 0 ? size : 1) * Math.Sin(-angle));
 
g.DrawLine(pen, x0, y0, x1, y1);
}
 
[STAThread]
static void Main()
{
Application.Run(new Clock());
}
}</syntaxhighlight>
 
=={{header|C++}}==
[[File:clock_cpp.png]]
<langsyntaxhighlight lang="cpp">
#include <windows.h>
#include <string>
Line 982 ⟶ 1,684:
}
//--------------------------------------------------------------------------------------------------
</syntaxhighlight>
</lang>
 
=={{header|C#ContextFree}}==
<syntaxhighlight lang="text">
<lang csharp>using System;
startshape START
using System.Drawing;
 
using System.Drawing.Drawing2D;
TIME_IN_SECONDS = 60
using System.Windows.Forms;
 
shape START {
public class Clock : Form
SECOND_HAND[r (TIME_IN_SECONDS*-6)]
CIRCLE[s 50 50]
}
 
 
shape SECOND_HAND
{
TRIANGLE [[z 1 s 1 30 y 0.26 b 1]]
static readonly float degrees06 = (float)Math.PI / 30;
}
static readonly float degrees30 = degrees06 * 5;
static readonly float degrees90 = degrees30 * 3;
 
</syntaxhighlight>
readonly int margin = 20;
 
=={{header|Delphi}}==
private Point p0;
{{libheader| Winapi.Windows}}
{{libheader| System.SysUtils}}
{{libheader| System.Classes}}
{{libheader| Vcl.Graphics}}
{{libheader| Vcl.Forms}}
{{libheader| Vcl.ExtCtrls}}
{{Trans|C#}}
Form application
 
<syntaxhighlight lang="delphi">
public Clock()
unit main;
{
Size = new Size(500, 500);
StartPosition = FormStartPosition.CenterScreen;
Resize += (sender, args) => ResetSize();
ResetSize();
var timer = new Timer() { Interval = 1000, Enabled = true };
timer.Tick += (sender, e) => Refresh();
DoubleBuffered = true;
}
 
interface
private void ResetSize()
{
p0 = new Point(ClientRectangle.Width / 2, ClientRectangle.Height / 2);
Refresh();
}
 
uses
protected override void OnPaint(PaintEventArgs e)
Winapi.Windows, System.SysUtils, System.Classes, Vcl.Graphics, Vcl.Forms,
{
Vcl.ExtCtrls;
base.OnPaint(e);
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
 
type
drawFace(e.Graphics);
TClock = class(TForm)
tmrTimer: TTimer;
procedure FormResize(Sender: TObject);
procedure tmrTimerTimer(Sender: TObject);
private
{ Private declarations }
const
degrees06 = PI / 30;
degrees30 = degrees06 * 5;
degrees90 = degrees30 * 3;
margin = 20;
var
p0: TPoint;
MinP0XY: Integer;
class function IfThen(Condition: Boolean; TrueValue, FalseValue: Integer):
Integer; overload; static;
class function IfThen(Condition: Boolean; TrueValue, FalseValue: Double):
Double; overload; static;
procedure Paint; override;
procedure DrawHand(Color: TColor; Angle, Size: Double; aWidth: Integer = 2);
procedure DrawFace;
procedure DrawCenter;
procedure DrawNumbers(Angle: Double; Value: Integer);
public
{ Public declarations }
end;
 
var
var time = DateTime.Now;
Clock: TClock;
int second = time.Second;
int minute = time.Minute;
int hour = time.Hour;
 
implementation
float angle = degrees90 - (degrees06 * second);
DrawHand(e.Graphics, Pens.Red, angle, 0.95);
 
{$R *.dfm}
float minsecs = (minute + second / 60.0F);
angle = degrees90 - (degrees06 * minsecs);
DrawHand(e.Graphics, Pens.Black, angle, 0.9);
 
{ TClock }
float hourmins = (hour + minsecs / 60.0F);
angle = degrees90 - (degrees30 * hourmins);
DrawHand(e.Graphics, Pens.Black, angle, 0.6);
}
 
procedure TClock.DrawCenter;
private void drawFace(Graphics g)
var
{
radius: Integer;
int radius = Math.Min(p0.X, p0.Y) - margin;
begin
g.FillEllipse(Brushes.White, p0.X - radius, p0.Y - radius, radius * 2, radius * 2);
radius := 6;
with Canvas do
begin
pen.Color := clNone;
Brush.Color := clBlack;
Ellipse(p0.x - radius, p0.y - radius, p0.x + radius, p0.y + radius);
end;
end;
 
procedure TClock.DrawFace;
for (int h = 0; h < 12; h++)
var
DrawHand(g, Pens.LightGray, h * degrees30, -0.05);
radius, h, m: Integer;
begin
radius := MinP0XY - margin;
with Canvas do
begin
Pen.Color := clBlack;
Pen.Width := 2;
Brush.Color := clWhite;
Ellipse(p0.x - radius, p0.y - radius, p0.x + radius, p0.y + radius);
for m := 0 to 59 do
DrawHand(clGray, m * degrees06, -0.08, 2);
 
for (int mh := 0; m <to 60;11 m++)do
begin
DrawHand(g, Pens.LightGray, m * degrees06, -0.025);
DrawHand(clBlack, h * degrees30, -0.09, 3);
}
DrawNumbers((h + 3) * degrees30, 12 - h);
end;
end;
end;
 
procedure TClock.DrawHand(Color: TColor; Angle, Size: Double; aWidth: Integer = 2);
private void DrawHand(Graphics g, Pen pen, float angle, double size)
var
{
int radius, =x0, Math.Min(p0.Xy0, p0.Y)x1, -y1: marginInteger;
begin
radius := MinP0XY - margin;
 
int x0 := p0.X + (sizeIfThen(Size > 0 ?, 0, : Convert.ToInt32Round(radius * (1Size + size1) * Math.Coscos(angleAngle))));
int y0 := p0.Y + (sizeIfThen(Size > 0 ?, 0, : Convert.ToInt32Round(radius * (1Size + size1) * Math.Sinsin(-angleAngle))));
 
int x1 := p0.X + Convert.ToInt32round(radius * IfThen(sizeSize > 0, ? size :Size, 1) * Math.Coscos(angleAngle));
int y1 := p0.Yy + Convert.ToInt32round(radius * IfThen(sizeSize > 0, ? size :Size, 1) * Math.Sinsin(-angleAngle));
 
with Canvas do
g.DrawLine(pen, x0, y0, x1, y1);
}begin
Pen.Color := Color;
pen.Width := aWidth;
MoveTo(x0, y0);
LineTo(x1, y1);
end;
end;
 
procedure TClock.DrawNumbers(Angle: Double; Value: Integer);
[STAThread]
var
static void Main()
radius, x0, y0, x1, y1, h, w: Integer;
{
Size: Double;
Application.Run(new Clock());
s: }string;
begin
}</lang>
radius := MinP0XY - margin;
Size := 0.85;
s := (Value).ToString;
 
x1 := p0.X + round(radius * Size * cos(Angle));
=={{header|Easyprog.online}}==
y1 := p0.y + round(radius * Size * sin(-Angle));
[https://easyprog.online/ide/run.html?code=func%20draw%20hour%20min%20sec%20.%20.%0A%23%20dial%0Acolor%20333%0Alinewidth%2090%0Apoint%2050%2050%0Acolor%20797%0Alinewidth%2088%0Apoint%2050%2050%0Acolor%20333%0Alinewidth%202%0Apoint%2050%2050%0Alinewidth%200.5%0Afor%20i%20range%2060%0Aa%23%20%3D%20i%20%2A%206%0Apoint%2050%20%2B%20sin%20a%23%20%2A%2040%2050%20-%20cos%20a%23%20%2A%2040%0A.%0Alinewidth%202%0Afor%20i%20range%2012%0Aa%23%20%3D%20i%20%2A%2030%0Apoint%2050%20%2B%20sin%20a%23%20%2A%2040%2050%20-%20cos%20a%23%20%2A%2040%0A.%0A%23%20hour%0Alinewidth%202%0Acolor%20000%0Aa%23%20%3D%20%28hour%20%2A%2060%20%2B%20min%29%20/%202%0Amove%2050%2050%0Aline%2050%20%2B%20sin%20a%23%20%2A%2032%2050%20-%20cos%20a%23%20%2A%2032%0A%23%20min%0Alinewidth%201.5%0Aa%23%20%3D%20%28sec%20%2B%20min%20%2A%2060%29%20/%2010%0Amove%2050%2050%0Aline%2050%20%2B%20sin%20a%23%20%2A%2040%2050%20-%20cos%20a%23%20%2A%2040%0A%23%20sec%0Alinewidth%201%0Acolor%20700%0Aa%23%20%3D%20sec%20%2A%206%0Amove%2050%2050%0Aline%2050%20%2B%20sin%20a%23%20%2A%2040%2050%20-%20cos%20a%23%20%2A%2040%0A.%0Aon%20timer%0Aif%20t%24%20%3C%3E%20sys%20%22time%22%0At%24%20%3D%20sys%20%22time%22%0Ah%24%20%3D%20sys%20%22time%3A%22%20%26%20t%24%0Asec%20%3D%20number%20substr%20h%24%2017%202%0Amin%20%3D%20number%20substr%20h%24%2014%202%0Ahour%20%3D%20number%20substr%20h%24%2011%202%0Aif%20hour%20%3E%2012%0Ahour%20-%3D%2012%0A.%0Acall%20draw%20hour%20min%20sec%0Atimer%200.98%0Aelse%0Atimer%200.01%0A.%0A.%0Atimer%200 Run it]
 
with Canvas do
<lang easyprog.online>func draw hour min sec . .
# dialbegin
radius := 5;
color 333
Font.Size := 12;
linewidth 90
w := TextWidth(s);
point 50 50
h := TextHeight(s);
color 797
 
linewidth 88
x0 := x1 - (w div 2);
point 50 50
y0 := y1 - (h div 2);
color 333
 
linewidth 2
TextOut(x0, y0, s);
point 50 50
end;
linewidth 0.5
end;
for i range 60
 
a# = i * 6
procedure TClock.FormResize(Sender: TObject);
point 50 + sin a# * 40 50 - cos a# * 40
begin
.
p0 := Tpoint.create(ClientRect.CenterPoint);
linewidth 2
MinP0XY := p0.x;
for i range 12
if MinP0XY a#> =p0.Y i * 30then
MinP0XY := p0.y;
point 50 + sin a# * 40 50 - cos a# * 40
Refresh();
.
end;
# hour
 
linewidth 2
class function TClock.IfThen(Condition: Boolean; TrueValue, FalseValue: Double): Double;
color 000
begin
a# = (hour * 60 + min) / 2
if Condition then
move 50 50
exit(TrueValue);
line 50 + sin a# * 32 50 - cos a# * 32
exit(FalseValue);
# min
end;
linewidth 1.5
 
a# = (sec + min * 60) / 10
class function TClock.IfThen(Condition: Boolean; TrueValue, FalseValue: Integer): Integer;
move 50 50
begin
line 50 + sin a# * 40 50 - cos a# * 40
if Condition then
# sec
exit(TrueValue);
linewidth 1
exit(FalseValue);
color 700
end;
a# = sec * 6
 
move 50 50
procedure TClock.Paint;
line 50 + sin a# * 40 50 - cos a# * 40
var
t: TDateTime;
second, minute, hour: Integer;
angle, minsecs, hourmins: Double;
begin
inherited;
 
t := time;
second := trunc(Frac(t * 24 * 60) * 60);
minute := trunc(Frac(t * 24) * 60);
hour := trunc(t * 24);
 
DrawFace;
 
angle := degrees90 - (degrees06 * second);
DrawHand(clred, angle, 0.95, 3);
 
minsecs := (minute + second / 60.0);
 
angle := degrees90 - (degrees06 * minsecs);
DrawHand(clGreen, angle, 0.8, 4);
 
hourmins := (hour + minsecs / 60.0);
angle := degrees90 - (degrees30 * hourmins);
DrawHand(clBlue, angle, 0.6, 5);
 
DrawCenter;
 
Caption := Format('%.2d:%.2d:%.2d', [hour, minute, second]);
end;
 
procedure TClock.tmrTimerTimer(Sender: TObject);
begin
Refresh;
end;
 
end.
 
</syntaxhighlight>
 
Resources:
<syntaxhighlight lang="delphi">
object Clock: TClock
Left = 0
Top = 0
Caption = 'Draw_a_clock'
ClientHeight = 462
ClientWidth = 484
Color = clBtnFace
DoubleBuffered = True
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
Position = poDesktopCenter
OnResize = FormResize
PixelsPerInch = 96
TextHeight = 13
object tmrTimer: TTimer
OnTimer = tmrTimerTimer
Left = 16
Top = 8
end
end
</syntaxhighlight>
 
 
{{out}}
[https://i.postimg.cc/QXNfPV6B/Draw-a-clock-Delphi.png]
 
=={{header|EasyLang}}==
 
[https://easylang.online/apps/clock.html Run it]
 
<syntaxhighlight>
proc draw hour min sec . .
# dial
color 333
move 50 50
circle 45
color 797
circle 44
color 333
for i range0 60
a = i * 6
move 50 + sin a * 40 50 + cos a * 40
circle 0.25
.
for i range0 12
a = i * 30
move 50 + sin a * 40 50 + cos a * 40
circle 1
.
# hour
linewidth 2
color 000
a = (hour * 60 + min) / 2
move 50 50
line 50 + sin a * 32 50 + cos a * 32
# min
linewidth 1.5
a = (sec + min * 60) / 10
move 50 50
line 50 + sin a * 40 50 + cos a * 40
# sec
linewidth 1
color 700
a = sec * 6
move 50 50
line 50 + sin a * 40 50 + cos a * 40
.
on timer
if t$ <> sysfloor "time"systime
t$ = sysfloor "time"systime
h$ = sys "time:" &timestr t$
sec = number substr h$ 1718 2
min = number substr h$ 1415 2
hour = number substr h$ 1112 2
if hour > 12
hour -= 12
.
call draw hour min sec
timer 0.98
timer 0.1
else
timer 0.01
.
.
timer 0</lang>
</syntaxhighlight>
 
=={{header|Evaldraw}}==
 
A clock that shows hours, minutes and seconds all moving each millisecond.
 
[[File:Clock.png|Hour minute and second hands move on milli second ticks|right]]
 
<syntaxhighlight lang="C">
(){
cls(0);
drawclock(150);
}
drawclock(rad) {
hand_color = 0x6a6a6a;
seconds_color = 0xff0000;
radius_notches = rad*.95;
radius_numbers = rad*.85;
small_notch_size =rad*0.04;
big_notch_size = rad*0.08;
cx=rad+1;
cy=rad+1;
// Face background
setcol(0x5aaaaa); drawsph(cx,cy,rad);
 
// Highlight from stopwatch.kc
setcol(0xffffff); gldisable(GL_DEPTH_TEST);
glbegin(GL_COMPLEX); glsettex("whitepix.tga");
for(a=3.5;a<=4.5;a+=.25) { gltexcoord(0,0); glvertex(cos(a)*rad*.55+cx,sin(a)*rad*.55+cy); }
for(a=4.5;a>=3.5;a-=.25) { gltexcoord(0,0); glvertex(cos(a)*rad*.45+cx,sin(a)*rad*.45+cy); }
glend();
 
moveto(cx-4*6, cy-.5*rad);
setfont(6,8);
setcol(0); printf("Evaltime");
// Face
setcol(0x015151);
hr=0;
for(i=0; i<60; i++)
{
a = i/60*2*pi - pi/2;
ca=cos(a);
sa=sin(a);
if (i%5==0)
{
hour = hr; if (hour==0) hour=12;
draw_hour(cx,cy,ca,sa,radius_numbers,hour);
hr++;
r=radius_notches;
x=cx + ca*r; y=cy+sa*r;
drawcone(x,y,big_notch_size*.5,x+big_notch_size*ca,y+big_notch_size*sa,-big_notch_size*.5,0);
} else {
r=radius_notches;
x=cx + ca*r; y=cy+sa*r;
drawcone(x,y,small_notch_size*.5,x+small_notch_size*ca,y+small_notch_size*sa,-small_notch_size*.5,0);
}
}
int_hours = klock(6);
int_minutes = klock(7);
int_seconds = klock(8);
int_millis = klock(9);
// Hour and Minute hand
hours = (int_hours+int_minutes/60.0) / 24.0;
a = hours * 2*pi - pi/2;
drawhand(cx,cy,a, rad*.64, 6,4, hand_color);
a = ( (int_minutes+int_seconds/60+int_millis/1000/60) / 60) * 2*pi - pi/2;
drawhand(cx,cy,a, rad*.84, 4,2, hand_color);
a = ((int_seconds+int_millis/1000) / 60) * 2*pi - pi/2;
drawhand(cx,cy,a, rad*.9, 3,1, seconds_color);
}
 
draw_hour(cx,cy,ca,sa,r,hr) {
x=cx + ca*r; y=cy+sa*r;
ofs=0; if(hr>9 || hr==0) ofs=5;
setfont(9,16);
moveto(x-4.5-ofs,y-8);
printf("%g", hr);
}
drawhand(cx,cy,angle,forward,r0,r1,kolor) {
back = .19*forward;
sx=cx - cos(angle)*back;
sy=cy - sin(angle)*back;
ex=cx + cos(angle)*forward;
ey=cy + sin(angle)*forward;
setcol(0);
drawcone(sx,sy,r0+1,ex,ey,r1+1);
setcol(kolor);
drawsph(cx,cy,r0+3);
drawcone(sx,sy,-r0,ex,ey,r1);
}</syntaxhighlight>
 
=={{header|F_Sharp|F#}}==
<langsyntaxhighlight lang="fsharp">open System.Text.RegularExpressions
 
let numberTemplate = """
Line 1,176 ⟶ 2,137:
System.Console.ReadLine() |> ignore // Until return is hit
showTime ()
0</langsyntaxhighlight>
{{out}}
<pre> _ _ _ _ __
Line 1,189 ⟶ 2,150:
3. Assumes a 16 bit CPU.<BR>
4. Assumes big-endian memory organization.<BR>
<syntaxhighlight lang="forth">
<lang Forth>
HEX
8379 CONSTANT TICKER \ address of 1/60 second counter
Line 1,253 ⟶ 2,214:
?TERMINAL
UNTIL
2DROP ;</langsyntaxhighlight>
 
=={{header|Fortran}}==
Line 1,259 ⟶ 2,220:
Uses system commands to clear the screen, sleep and obtain time
 
<syntaxhighlight lang="fortran">
<lang Fortran>
!Digital Text implemented as in C version - Anant Dixit (Oct, 2014)
program clock
Line 1,376 ⟶ 2,337:
 
end subroutine
</syntaxhighlight>
</lang>
 
Preview:
Line 1,394 ⟶ 2,355:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">' version 05-04-2017
' compile with: fbc -s gui
 
Line 1,476 ⟶ 2,437:
ImageDestroy(clockdial)
 
End</langsyntaxhighlight>
 
=={{header|FunL}}==
 
<langsyntaxhighlight lang="funl">import concurrent.{scheduleAtFixedRate, scheduler}
 
val ROW = 10
Line 1,546 ⟶ 2,507:
 
if not $os.startsWith( 'Windows' )
print( '\u001B[?25h' )</langsyntaxhighlight>
 
{{out}}
Line 1,554 ⟶ 2,515:
/__ /__/ . /__ / . / /
</pre>
 
 
 
=={{header|FutureBasic}}==
This FB code produces a stand-alone executable application for a Macintosh.
<syntaxhighlight lang="futurebasic">
output file "Rosetta Code Clock"
 
_window = 1
begin enum 1
_clockView
_one
_two
_three
_four
_five
_six
_seven
_eight
_nine
_ten
_eleven
_twelve
end enum
 
local fn BuildWindow
CALayerRef layer, hoursLayer, minutesLayer, secondsLayer
CAShapeLayerRef shapeLayer, hubLayer
CATextLayerRef textLayer
BezierPathRef circle, hub
CGPoint pt
CGRect r, frame
CFDateRef dt
CFTimeInterval ti
CGFloat h, m, s, ha, ma, sa
NSUInteger i
CFStringRef num
CABasicAnimationRef secondsAnimation, minutesAnimation, hoursAnimation
// Window
r = fn CGRectMake( 0, 0, 500, 500 )
window _window, @"FutureBasic Rosetta Code Clock", r
WindowSetBackgroundColor( _window, fn ColorBlack )
// View to hold clock layers
view _clockView, r, _window
ViewSetWantsLayer( _clockView, YES )
layer = fn ViewLayer( _clockView )
frame = fn ViewFrame( _clockView )
// Blank clock face
shapeLayer = fn CAShapeLayerInit
circle = fn BezierPathWithOvalInRect( fn CGRectInset( r, 35, 35 ) )
CAShapeLayerSetPath( shapeLayer, circle )
CAShapeLayerSetLineWidth( shapeLayer, 6.5 )
CAShapeLayerSetLineCap( shapeLayer, kCALineCapRound )
CAShapeLayerSetFillColor( shapeLayer, fn ColorDarkGray )
CAShapeLayerSetStrokeColor( shapeLayer, fn ColorWithRGB( 0.711, 0.533, 0.258, 1.0 ) )
CALayerAddSublayer( layer, shapeLayer )
// Clock numerals
for i = _one to _twelve
if i = _one then pt = fn CGPointMake( frame.size.width / 2 + 95, frame.size.height / 2 + 115 ) : num = @"1"
if i = _two then pt = fn CGPointMake( frame.size.width / 2 + 160, frame.size.height / 2 + 45 ) : num = @"2"
if i = _three then pt = fn CGPointMake( frame.size.width / 2 + 180, frame.size.height / 2 - 40 ) : num = @"3"
if i = _four then pt = fn CGPointMake( frame.size.width / 2 + 155, frame.size.height / 2 - 125 ) : num = @"4"
if i = _five then pt = fn CGPointMake( frame.size.width / 2 + 90, frame.size.height / 2 - 190 ) : num = @"5"
if i = _six then pt = fn CGPointMake( frame.size.width / 2, frame.size.height / 2 - 215 ) : num = @"6"
if i = _seven then pt = fn CGPointMake( frame.size.width / 2 - 90, frame.size.height / 2 - 190 ) : num = @"7"
if i = _eight then pt = fn CGPointMake( frame.size.width / 2 - 155, frame.size.height / 2 - 125 ) : num = @"8"
if i = _nine then pt = fn CGPointMake( frame.size.width / 2 - 185, frame.size.height / 2 - 40 ) : num = @"9"
if i = _ten then pt = fn CGPointMake( frame.size.width / 2 - 155, frame.size.height / 2 + 45 ) : num = @"10"
if i = _eleven then pt = fn CGPointMake( frame.size.width / 2 - 90, frame.size.height / 2 + 115 ) : num = @"11"
if i = _twelve then pt = fn CGPointMake( frame.size.width / 2, frame.size.height / 2 + 145 ) : num = @"12"
textLayer = fn CATextLayerInit
CATextLayerSetString( textLayer, num )
CATextLayerSetFont( textLayer, @"Times" )
CATextLayerSetFontSize( textLayer, 50.0 )
CATextLayerSetForegroundColor( textLayer, fn ColorGreen )
CALayerSetAnchorPoint( textLayer, fn CGPointMake( 0.5, 0 ) )
CATextLayerSetAlignmentMode( textLayer, kCAAlignmentCenter )
CALayerSetPosition( textLayer, pt )
CALayerSetBounds( textLayer, fn CGRectMake( 0, 0, 70, 65 ) )
CALayerAddSublayer( layer, textLayer )
next
// Hours layer
hoursLayer = fn CALayerInit
CALayerSetBackgroundColor( hoursLayer, fn ColorWhite )
CALayerSetAnchorPoint( hoursLayer, fn CGPointMake( 0.5, 0 ) )
CALayerSetPosition( hoursLayer, fn CGPointMake( frame.size.width / 2, frame.size.height / 2 ) )
CALayerSetBounds( hoursLayer, fn CGRectMake( 0, 0, 10, frame.size.width / 2 -90 ) )
CALayerSetCornerRadius( hoursLayer, 4.0 )
CALayerAddSublayer( layer, hoursLayer )
// Minutes layer
minutesLayer = fn CALayerInit
CALayerSetBackgroundColor( minutesLayer, fn ColorWhite )
CALayerSetAnchorPoint( minutesLayer, fn CGPointMake( 0.5, 0 ) )
CALayerSetPosition( minutesLayer, fn CGPointMake( frame.size.width / 2, frame.size.height / 2 ) )
CALayerSetBounds( minutesLayer, fn CGRectMake( 0, 0, 6, frame.size.width / 2 -45 ) )
CALayerSetCornerRadius( minutesLayer, 3.0 )
CALayerAddSublayer( layer, minutesLayer )
// Seconds layer
secondsLayer = fn CALayerInit
CALayerSetBackgroundColor( secondsLayer, fn ColorWithRGB( 0.502, 0.000, 0.251, 1.0 ) )
CALayerSetAnchorPoint( secondsLayer, fn CGPointMake( 0.5, 0 ) )
CALayerSetPosition( secondsLayer, fn CGPointMake( frame.size.width / 2, frame.size.height / 2 ) )
CALayerSetBounds( secondsLayer, fn CGRectMake( 0, 0, 3, frame.size.width / 2 -35 ) )
CALayerAddSublayer( layer, secondsLayer )
// Timing functions and calculations
dt = fn CalendarStartOfDayForDate( fn CalendarCurrent, fn DateInit )
ti = fn DateTimeIntervalSinceDate( fn DateInit, dt )
h = ti / 3600.0
m = ( h - int(h) ) * 60.0
s = ( m - int(m) ) * 60.0
ha = h / 12.0 * 360.0
ma = m / 60.0 * 360.0
sa = s / 60.0 * 360.0
// Rotation calculation
CALayerSetTransform( secondsLayer, fn CATransform3DMakeRotation( sa / 180.0 * PI, 0, 0, 1 ) )
CALayerSetTransform( minutesLayer, fn CATransform3DMakeRotation( ma / 180.0 * PI, 0, 0, 1 ) )
CALayerSetTransform( hoursLayer, fn CATransform3DMakeRotation( ha / 180.0 * PI, 0, 0, 1 ) )
// Animations for each clock hand
secondsAnimation = fn CABasicAnimationWithKeyPath( @"transform.rotation.z" )
CAMediaTimingSetRepeatCount( secondsAnimation, INFINITY )
CAMediaTimingSetDuration( secondsAnimation, 60 )
CAAnimationSetRemovedOnCompletion( secondsAnimation, NO )
CABasicAnimationSetFromValue( secondsAnimation, @( -sa * PI / 180 ) )
CABasicAnimationSetByValue( secondsAnimation, @( -2 * PI ) )
CAAnimationSetTimingFunction( secondsAnimation, fn CAMediaTimingFunctionWithName( kCAMediaTimingFunctionLinear ) )
CALayerAddAnimation( secondsLayer, secondsAnimation, @"SecondAnimationKey" )
minutesAnimation = fn CABasicAnimationWithKeyPath( @"transform.rotation.z" )
CAMediaTimingSetRepeatCount( minutesAnimation, INFINITY )
CAMediaTimingSetDuration( minutesAnimation, 60 * 60 )
CAAnimationSetRemovedOnCompletion( minutesAnimation, NO )
CABasicAnimationSetFromValue( minutesAnimation, @( -ma * PI / 180 ) )
CABasicAnimationSetByValue( minutesAnimation, @( -2 * PI ) )
CAAnimationSetTimingFunction( minutesAnimation, fn CAMediaTimingFunctionWithName( kCAMediaTimingFunctionLinear ) )
CALayerAddAnimation( minutesLayer, minutesAnimation, @"MinutesAnimationKey" )
hoursAnimation = fn CABasicAnimationWithKeyPath( @"transform.rotation.z" )
CAMediaTimingSetRepeatCount( hoursAnimation, INFINITY )
CAMediaTimingSetDuration( hoursAnimation, 60 * 60 * 12 )
CAAnimationSetRemovedOnCompletion( hoursAnimation, NO )
CABasicAnimationSetFromValue( hoursAnimation, @( -ha * PI / 180 ) )
CABasicAnimationSetByValue( hoursAnimation, @( -2 * PI ) )
CAAnimationSetTimingFunction( hoursAnimation, fn CAMediaTimingFunctionWithName( kCAMediaTimingFunctionLinear ) )
CALayerAddAnimation( hoursLayer, hoursAnimation, @"HoursAnimationKey" )
// Center hub
hubLayer = fn CAShapeLayerInit
r = fn CGRectMake( 244, 242, 16, 16 )
hub = fn BezierPathWithOvalInRect( r )
CAShapeLayerSetPath( hubLayer, hub )
CAShapeLayerSetLineWidth( hubLayer, 1.5 )
CAShapeLayerSetFillColor( hubLayer, fn ColorBlack )
CALayerAddSublayer( layer, hubLayer )
end fn
 
 
local fn DoDialog( ev as long, tag as long )
select ( ev )
case _viewWantsUpdateLayer : DialogEventSetBool(YES)
case _windowWillClose : end
end select
end fn
 
on dialog fn DoDialog
 
fn BuildWindow
 
HandleEvents
</syntaxhighlight>
{{output}}
[[File:Clock in FutureBasic.png]]
 
 
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import (
Line 1,643 ⟶ 2,789:
y := float64(radius) * math.Sin(theta)
return int(x) + 256, int(y) + 256
}</langsyntaxhighlight>
The following html file, 'clock.html', should be in the same folder as the wsclock binary.
<langsyntaxhighlight lang="html"><!DOCTYPE html>
<meta charset="utf-8" />
<title>Clock</title>
Line 1,745 ⟶ 2,891:
</body>
</html></langsyntaxhighlight>
 
=={{header|GUISS}}==
 
<langsyntaxhighlight lang="guiss">Start,Programs,Accessories,Analogue Clock</langsyntaxhighlight> =={{header|GUISS}}==
 
<syntaxhighlight lang="guiss">Start,Programs,Accessories,Analogue Clock</syntaxhighlight>
 
=={{header|Haskell}}==
{{libheader|ansi-terminal}}
<langsyntaxhighlight Haskelllang="haskell">import Control.Concurrent
import Data.List
import System.Time
Line 1,866 ⟶ 3,014:
setCursorColumn 0
cursorUp 5
main</langsyntaxhighlight>
Output:<pre> ██ ██████ ██████ ██████ ██████ ██████
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
Line 1,872 ⟶ 3,020:
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██ ██████ ██████ ██████ ██████ ██████</pre>
 
=={{header|GUISS}}==
 
<lang guiss>Start,Programs,Accessories,Analogue Clock</lang>
 
=={{header|Icon}} and {{header|Unicon}}==
Line 1,884 ⟶ 3,028:
1. Clock using conventional Graphics
 
<langsyntaxhighlight lang="icon">
link graphics
 
Line 1,998 ⟶ 3,142:
end
 
</syntaxhighlight>
</lang>
 
2. Clock using Turtle Graphics
<langsyntaxhighlight lang="icon">
link graphics, turtle
 
Line 2,183 ⟶ 3,327:
draw("r", xsize/2 * 0.25, 8 * xsize / 800, ws - 180)
end
</syntaxhighlight>
</lang>
 
=={{header|J}}==
Graphical clock (tested on jqt -- j903):
<lang J>
 
<syntaxhighlight lang="j">{{
require'gl2'
coinsert 'jgl2'
clock_face_paint=: {{
try.
'H M S'=. _3{.6!:0''
glclear''
center=. 2-~<.-:glqwh''
glpen 2: glrgb 0 0 0 255
glellipse 1+,0 2*/center
center {{ gllines <.2+(m,m)+,0.97 1*/m*+.j.y}}"0^j.2r12p1*i.12
center {{ gllines <.2+(m,m)+,0.92 0.99*/m*+.j.y}}"0^j.2r4p1*i.4
hand=: center {{
glpen 2: glbrush glrgb<.4{.255*x,4#1
gllines<.2+m,m*1++.j.n*^j.1p1+y
EMPTY
}}
1 0 0 (0.8) hand 2r60p1*S
0 1 0 (0.7) hand 2r60p1*M+60%~S
0 0 1 (0.4) hand 2r12p1*H+60%~M+60%~S
catch.
echo 13!:12''
end.
EMPTY
}}
clock_timer=: glpaint
wd {{)n
pc clock closeok;
cc face isigraph;
set face wh 200 200;
ptimer 100;
pshow;
}}
}}1</syntaxhighlight>
 
Some alternatives:
 
<syntaxhighlight lang="j">
Note'rudimentary 4 second clock'
advances an arrow at roughly 1 second intervals,
Line 2,207 ⟶ 3,390:
 
tic=: (>. draw Pass_y <.) ([: seconds 0 $ delay@1:)
</syntaxhighlight>
</lang>
The result of 3.18... is the session time at which the example began.
<pre>
Line 2,222 ⟶ 3,405:
</pre>
 
Here's a graphical variant (caution: this update mechanism fails on newer J implementations, partially because of version drift in the underlying Qt mechanisms and how those shortcomings have resulted in interface changes):
Here's a graphical variant:
 
<langsyntaxhighlight Jlang="j">require'plot'
N=:0.01*i.629
O=: [: j./ 1 2 o./ ]
Line 2,230 ⟶ 3,413:
delay=:6!:3 NB. "sleep"
clock=: [: plot (O N),N*/~0.07 0.11 0.15(*O) 2r24p1 2r60p1 2r60p1*_3{.6!:0 bind ''
delay@1:@clock^:9e99''</langsyntaxhighlight>
 
=={{header|Java}}==
{{works with|Java|8}}
<langsyntaxhighlight lang="java">import java.awt.*;
import java.awt.event.*;
import static java.lang.Math.*;
Line 2,314 ⟶ 3,497:
});
}
}</langsyntaxhighlight>
 
=={{header|JavaScript}}==
Tested on Gecko. Put the following in a &lt;script> tag somewhere, and call <code>init_clock()</code> after body load.
<langsyntaxhighlight JavaScriptlang="javascript">var sec_old = 0;
function update_clock() {
var t = new Date();
Line 2,364 ⟶ 3,547:
 
window.setInterval(update_clock, 200);
}</langsyntaxhighlight>
 
=== digital ===
<langsyntaxhighlight lang="javascript"><!DOCTYPE html>
<html lang="en">
<head>
Line 2,499 ⟶ 3,682:
 
</body>
</html></langsyntaxhighlight>
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">
using Gtk, Colors, Graphics, Dates
 
Line 2,586 ⟶ 3,769:
sleep(1.0)
end
</syntaxhighlight>
</lang>
 
=={{header|Kotlin}}==
{{trans|Java}}
<langsyntaxhighlight lang="scala">// version 1.1
 
import java.awt.*
Line 2,660 ⟶ 3,843:
f.isVisible = true
}
}</langsyntaxhighlight>
 
=={{header|Lambdatalk}}==
The {watch} expression displays three thick arc of circles, red for hours, green for minutes and blue for seconds, growing from 0° to 360° according to the time, and the full date inside following this format yyy/mm/dd hh:mm:ss. The output can be seen in http://lambdaway.free.fr/lambdawalks/?view=watch
 
<syntaxhighlight lang="scheme">
1) lambdatalk code
{watch} // displays the watch
 
{def watch
{watch.init}
{div {@ id="watch"}}
}
 
{def watch.draw
{lambda {:r :g :b}
{svg {@ style="width:300px; height:300px;"}
{let { {:r :r} {:g :g} {:b :b} {:t {date}} }
{watch.path 150 150 100 20 :r 1 :t}
{watch.path 150 150 120 20 :g 2 :t}
{watch.path 150 150 140 20 :b 3 :t}
{watch.digit :t} }}}}
 
{def watch.path
{lambda {:x :y :r :e :c :i :t}
{path {@ d="{watch.arc :x :y :r {watch.time :i :t}}"
fill="none" stroke=":c" stroke-width=":e"}} }}
 
{def watch.arc
{lambda {:x :y :r :t}
{let { {:x :x} {:y :y} {:r :r}
{:start {watch.pol2car :x :y :r :t}}
{:end {watch.pol2car :x :y :r 0}}
{:flag {if {<= :t 180} then 0 else 1}} }
M {car :start} {cdr :start}
A :r :r 0 :flag 0 {car :end} {cdr :end} }}}
 
{def watch.time
{lambda {:i :t}
{if {= :i 1}
then {/ {* 360 {% {S.get {+ :i 2} :t} 12}} 12}
else {/ {* 360 {S.get {+ :i 2} :t}} 60} }}}
 
{def watch.pol2car
{lambda {:cx :cy :r :t}
{let { {:cx :cx} {:cy :cy} {:r :r}
{:T {* {- :t 90} {/ {PI} 180}}} }
{cons {+ :cx {* :r {cos :T}}}
{+ :cy {* :r {sin :T}}}} }}}
 
{def watch.digit
{lambda {:t}
{text {@ x="50%" y="48%"
base-line="middle"
text-anchor="middle"
font-size="2.0em"
stroke="#ccc"}
{S.get 0 :t}/{S.get 1 :t}/{S.get 2 :t} }
{text {@ x="50%" y="58%"
base-line="middle"
text-anchor="middle"
font-size="2.0em"
stroke="#ccc"}
{S.get 3 :t} : {S.get 4 :t} : {S.get 5 :t} } }}
 
2) javascript code (for timing)
 
{script
var update = function () {
document.getElementById("watch").innerHTML =
LAMBDATALK.eval_forms( "{watch.draw #f00 #0f0 #00f}" )
};
LAMBDATALK.DICT['watch.init'] = function () {
setTimeout( update, 10);
setInterval( update, 1000);
return ''
};
}
</syntaxhighlight>
 
=={{header|Liberty BASIC}}==
LB has a timer to call a routine at regular intervals. The example is a cut-down version of the full clock supplied with LB as an example.
<syntaxhighlight lang="lb">
<lang lb>
WindowWidth =120
WindowHeight =144
Line 2,704 ⟶ 3,965:
 
end
</syntaxhighlight>
</lang>
 
=={{header|Locomotive Basic}}==
[[File:Cpcbasic draw clock.png|thumb|Output]]
 
Because the Amstrad CPC does not have an RTC, we first have to ask the user for the current time. The seconds hand is drawn in XOR ink mode so that it can be removed without affecting the other hands.
 
<langsyntaxhighlight lang="locobasic">10 mode 1:defint a-y:deg
20 input "Current time (HH:MM)";t$
30 h=val(mid$(t$,1,2))
Line 2,755 ⟶ 4,016:
440 if a>0 then frame:move 0,0:draw .8*r*sin(a-6),.8*r*cos(a-6),3,1
450 frame:move 0,0:draw .8*r*sin(a),.8*r*cos(a),3,1
460 return</langsyntaxhighlight>
 
=={{header|Lua}}==
Line 2,761 ⟶ 4,022:
Several nice clocks in the [http://love2d.org/forums/viewtopic.php?f=5&t=77346 LÖVE-forum]
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<lang Mathematica>makeHand[fl_, bl_, fw_, bw_] := Polygon[{{-bw, -bl}, {bw, -bl}, {fw, fl}, {0, fl + 8 fw}, {-fw, fl}}/9];
 
=={{header|M2000 Interpreter}}==
hourHand = makeHand[5, 5/3, .1, .3];minuteHand = makeHand[7, 7/3, .1, .3];
secondHand = {Red, EdgeForm[Black], makeHand[7, 7/3, .1/2, .3/2]};
 
Low demand for CPU. A LED style clock. Using Space Bar we can tongle the backround from BLACK to Transparent. Esc for quit.
Graphics[{
[[File:DrawClockM2000.png|thumb|center]]
{Thickness[.03], Circle[]},(* Rim *)
 
{Thickness[.003], Table[Line[{.9 {Cos[a], Sin[a]}, .95 {Cos[a], Sin[a]}}], {a, 0, 2 \[Pi], 2 \[Pi]/60}]}, (* Thin ticks *)
 
{Thickness[.01], Table[Line[{.9 {Cos[a], Sin[a]}, .95 {Cos[a], Sin[a]}}], {a, 0, 2 \[Pi], 2 \[Pi]/12}]}, (* Thick ticks *)
<syntaxhighlight lang="m2000 interpreter">
Style[Table[Text[i, .77 {Cos[-i \[Pi]/6 + \[Pi]/2], Sin[-i \[Pi]/6 + \[Pi]/2]}], {i, 1, 12}], FontFamily -> "Helvetica", FontSize -> 36], (* Numbers *)
\\ if you have two monitors:
Rotate[hourHand, Dynamic[Refresh[-30 Mod[AbsoluteTime[]/3600, 60] \[Degree], UpdateInterval -> 60]], {0, 0}],
\\ Window mode, 1 \\ mode is a read only variable return the size of current font
Rotate[minuteHand, Dynamic[Refresh[-6 Mod[AbsoluteTime[]/60, 60] \[Degree], UpdateInterval -> 1]], {0, 0}],
// Window mode, 2 // selecet monitor 2
Rotate[secondHand, Dynamic[Refresh[-6 Mod[AbsoluteTime[], 60] \[Degree], UpdateInterval -> 1/20]], {0, 0}]
cls, 0
}]</lang>[[File:mma_clock.png]]
window 6, window
 
Module Led_Clock{
Escape Off
Smooth off
Dim D(-1 to 9)
D(-1)=(0,0,0,0,0,0,0)
D(0)=(1,1,1,0,1,1,1)
D(1)=(0,0,1,0,0,1,0)
D(2)=(1,0,1,1,1,0,1)
D(3)=(1,0,1,1,0,1,1)
D(4)=(0,1,1,1,0,1,0)
D(5)=(1,1,0,1,0,1,1)
D(6)=(1,1,0,1,1,1,1)
D(7)=(1,0,1,0,0,1,0)
D(8)=(1,1,1,1,1,1,1)
D(9)=(1,1,1,1,0,1,1)
N=240
XX=(scale.x-N*75) div 2
YY=scale.y-N*22
NN=N
BackColor=0
CLS BackColor, 0
Back {CLS BackColor,0}
desktop 255, BackColor
Forecolor=12
C=BackColor-Forecolor
pen BackColor
for i=0 to 9: cc=d(i): cc*=c:next
m=1
move XX+N*23.2, YY+N*5.2
polygon BackColor-C, N,-N, N,N, -N, N, -N, -N
move XX+N*23.2,YY+N*13.2
polygon BackColor-C, N,-N, N,N, -N, N, -N, -N
move XX+N*49.2,YY+N*5.2
polygon BackColor-C, N,-N, N,N, -N, N, -N, -N
move XX+N*49.2,YY+N*13.2
polygon BackColor-C, N,-N, N,N, -N, N, -N, -N
dsk=True
every 1000/2 {
k=now
k1=val(str$(k, "hh"))
k2=val(str$(k, "nn"))
k3=val(str$(k, "ss"))
LED(XX, D(k1 div 10))
LED(XX+N*12, D(k1 mod 10))
LED(XX+N*26, D(k2 div 10))
LED(XX+N*38, D(k2 mod 10))
LED(XX+N*52, D(k3 div 10))
LED(XX+N*64, D(k3 mod 10))
refresh 1000
if keypress(32) then
dsk~
if dsk then desktop 255 else desktop 255, BackColor
end if
if keypress(27) or mouse=2 then exit
}
desktop 255
pen 14
refresh 50
mode 16
wait 1000
Escape On
 
sub LED(XX, S())
move XX+N*1.2, YY+NN
\\ LED - UPPER
polygon BackColor-S(0), N,-N,N*6,0, N,N, -N, N,-N*6,0, -N, -N
\\ LED | LEFT UPPER
move XX+N*1.2-N*1.2, YY+N*1.2+NN
polygon BackColor-S(1), N,-N,N,N,0,N*6,-N, N, -N, -N, 0, -N*6
move XX+N*1.2+N*7.2, YY+N*1.2+NN
\\ LED | RIGHT UPPER
polygon BackColor-S(2), N,-N,N,N,0,N*6,-N, N, -N, -N, 0, -N*6
move XX+N*1.2, YY+N*8.4+NN
\\ LED - MIDDLE
polygon BackColor-S(3), N,-N,N*6,0, N,N, -N, N,-N*6,0, -N, -N
\\ LED | LEFT BOTTOM
move XX+N*1.2-N*1.2, YY+N*9.6+NN
polygon BackColor-S(4), N,-N,N,N,0,N*6,-N, N, -N, -N, 0, -N*6
\\ LED | RIGHT BOTTOM
move XX+N*1.2+N*7.2, YY+N*9.6+NN
polygon BackColor-S(5), N,-N,N,N,0,N*6,-N, N, -N, -N, 0, -N*6
\\ LED - BOTTOM
move XX+N*1.2, YY+N*16.8+NN
polygon BackColor-S(6), N,-N,N*6,0, N,N, -N, N,-N*6,0, -N, -N
end sub
}
Led_Clock
</syntaxhighlight>
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<syntaxhighlight lang="mathematica">Dynamic[ClockGauge[], UpdateInterval -> 1]</syntaxhighlight>
 
=={{header|MATLAB}} / {{header|Octave}}==
 
<langsyntaxhighlight Matlablang="matlab"> u = [0:360]*pi/180;
while(1)
s = mod(now*60*24,1)*2*pi;
plot([0,sin(s)],[0,cos(s)],'-',sin(u),cos(u),'k-');
pause(1);
end;</langsyntaxhighlight>
 
=={{header|MiniScript}}==
 
This solution works with [https://miniscript.org/MiniMicro Mini Micro], and uses its default SpriteDisplay.
 
<syntaxhighlight lang="miniscript">// draw a clock hand, then copy it to an image
gfx.clear color.clear
gfx.fillPoly [[60,5], [64,10], [128,5], [64,0]], color.yellow
handImg = gfx.getImage(0,0, 128,10)
 
clear // clear all displays
 
// prepare the face sprite
faceImg = file.loadImage("/sys/pics/shapes/CircleThinInv.png")
face = new Sprite
face.image = faceImg
face.scale = 2
face.x = 480; face.y = 320
display(4).sprites.push face
 
// prepare the hand sprite (from previously created image)
hand = new Sprite
hand.image = handImg
hand.x = face.x; hand.y = face.y
display(4).sprites.push hand
 
// main loop
while true
hand.rotation = 90 - floor(time) % 60 * 6
wait
end while</syntaxhighlight>
 
=={{header|NetRexx}}==
{{trans|Java}}
<langsyntaxhighlight NetRexxlang="netrexx">/* NetRexx */
options replace format comments java crossref symbols binary
 
Line 2,890 ⟶ 4,272:
repaint()
return
</syntaxhighlight>
</lang>
 
=={{header|Nim}}==
==={{transheader|Perl 6Text}}===
{{trans|Raku}}
<lang nim>import times, os
<syntaxhighlight lang="nim">import times, os
 
const
Line 2,907 ⟶ 4,290:
for c in x: stdout.write b[c.ord - '0'.ord]
echo ""
sleep 1000</langsyntaxhighlight>
 
==={{header|Using SDL}}===
{{libheader|SDL2}}
<syntaxhighlight lang="nim">## needs sdl2 ("nimble install sdl2")
 
import sdl2, times, math
 
let
size = [400, 400]
center = [size[0] div 2, size[1] div 2]
ra = 0.4 * float(size[0])
 
discard sdl2.init(INIT_EVERYTHING)
 
var
window: WindowPtr
render: RendererPtr
 
window = createWindow("studio", 100, 100, cint(size[0]), cint(size[1]), SDL_WINDOW_SHOWN)
render = createRenderer(window, -1, Renderer_Accelerated or
Renderer_PresentVsync or Renderer_TargetTexture)
 
var
evt = sdl2.defaultEvent
runGame = true
r: Rect
 
r.w = 6
r.h = 6
let rh = r.w div 2
 
while runGame:
let
n = now()
h = n.hour
m = n.minute
hm = float(h) + float(m) / 60
s = n.second
while pollEvent evt:
if evt.kind == QuitEvent:
runGame = false
break
render.setDrawColor(0, 0, 0)
render.clear
render.setDrawColor(255, 0, 0)
 
for i in 0..11:
r.x = cint(center[0] - rh + int(ra * sin(2.0 * PI * float(i) / 12.0)))
r.y = cint(center[1] - rh - int(ra * cos(2.0 * PI * float(i) / 12.0)))
render.fillRect(r)
for i in 0..s:
r.x = cint(center[0] - rh + int(0.9 * ra * sin(2.0 * PI * float(i) / 60.0)))
r.y = cint(center[1] - rh - int(0.9 * ra * cos(2.0 * PI * float(i) / 60.0)))
render.fillRect(r)
render.drawLine(cint(center[0]), cint(center[1]),
cint(center[0] + int(0.5 * ra * sin(2.0 * PI * float(hm) / 12.0))),
cint(center[1] - int(0.5 * ra * cos(2.0 * PI * float(hm) / 12.0))))
render.drawLine(cint(center[0]), cint(center[1]),
cint(center[0] + int(0.8 * ra * sin(2.0 * PI * float(m) / 60.0))),
cint(center[1] - int(0.8 * ra * cos(2.0 * PI * float(m) / 60.0))))
 
render.present()
delay(100)
 
destroy render
destroy window</syntaxhighlight>
 
=={{header|OCaml}}==
Line 2,913 ⟶ 4,362:
Using only the standard library of OCaml with its [http://caml.inria.fr/pub/docs/manual-ocaml/libref/Graphics.html Graphics] module:
 
<langsyntaxhighlight lang="ocaml">#!/usr/bin/env ocaml
#load "unix.cma"
#load "graphics.cma"
Line 2,977 ⟶ 4,426:
in
try loop ()
with _ -> close_graph ()</langsyntaxhighlight>
 
 
Line 2,993 ⟶ 4,442:
unix.cmxa lablgtk.cmxa cairo.cmxa cairo_lablgtk.cmxa gtkInit.cmx gtkclock.ml
 
<langsyntaxhighlight lang="ocaml">let pi = 4.0 *. atan 1.0
let angle v max = float v /. max *. 2.0 *. pi
 
Line 3,058 ⟶ 4,507:
animate area;
w#show ();
GMain.main ()</langsyntaxhighlight>
 
=={{header|ooRexx}}==
Line 3,065 ⟶ 4,514:
<br>https://www.dropbox.com/sh/h0dycdshv04c5lz/5oHFfI3t14?n=132389230
<br>It runs nicely on Windows 7 with ooRexx installed.
<langsyntaxhighlight ooRexxlang="oorexx">/* REXX ---------------------------------------------------------------
* 09.02.2014 Walter Pachl with a little, well considerable, help from
* a friend (Mark Miesfeld)
Line 3,343 ⟶ 4,792:
Parse Arg x,y
If y=0 Then Return '??'
Else Return x/y</langsyntaxhighlight>
 
===version 2 runs under Windows, Linux, and MacOSX===
Line 3,349 ⟶ 4,798:
A screenshot of this clock can be seen on my dropbox (clocka.jpg)
<br>https://www.dropbox.com/sh/h0dycdshv04c5lz/5oHFfI3t14?n=132389230
<langsyntaxhighlight lang="oorexx">/* REXX ---------------------------------------------------------------
Name: clock.rxj
Purpose: create a graphical clock that shows the current time
Line 3,491 ⟶ 4,940:
::method actionPerformed -- this event will be caused every second by the swing Timer
use arg eventObj, slotDir
slotDir~userData~repaint -- fetch the Java object and send it the repaint message</langsyntaxhighlight>
[[out}}
<pre>... [2017-01-26T17:17:51.527000] Rexx main program, now waiting until JFrame gets closed ...
Line 3,497 ⟶ 4,946:
 
=={{header|Perl}}==
{{trans|Raku}}
 
<syntaxhighlight lang="perl">use utf8; # interpret source code as UTF8
{{trans|Perl 6}}
<lang perl>use utf8; # interpret source code as UTF8
binmode STDOUT, ':utf8'; # allow printing wide chars without warning
$|++; # disable output buffering
Line 3,527 ⟶ 4,975:
 
sub clear { print "\e[H\e[J" }
sub position { printf "\e[%d;%dH", shift, shift }</langsyntaxhighlight>
 
{{out}}
Line 3,535 ⟶ 4,983:
╵ └─┘ └─╴ └─┘ └─┘ ╶─┘
</pre>
 
=={{header|Perl 6}}==
<lang perl6>my ($rows,$cols) = qx/stty size/.words;
my $v = floor $rows / 2;
my $h = floor $cols / 2 - 16;
 
my @t = < ⡎⢉⢵ ⠀⢺⠀ ⠊⠉⡱ ⠊⣉⡱ ⢀⠔⡇ ⣏⣉⡉ ⣎⣉⡁ ⠊⢉⠝ ⢎⣉⡱ ⡎⠉⢱ ⠀⠶⠀>;
my @b = < ⢗⣁⡸ ⢀⣸⣀ ⣔⣉⣀ ⢄⣀⡸ ⠉⠉⡏ ⢄⣀⡸ ⢇⣀⡸ ⢰⠁⠀ ⢇⣀⡸ ⢈⣉⡹ ⠀⠶⠀>;
 
loop {
my @x = DateTime.now.Str.substr(11,8).ords X- ord('0');
print "\e[H\e[J";
print "\e[$v;{$h}H";
print ~@t[@x];
print "\e[{$v+1};{$h}H";
print ~@b[@x];
print "\e[H";
sleep 1;
}</lang>
{{out}}
<pre>⠀⢺⠀ ⢀⠔⡇ ⠀⠶⠀ ⠊⠉⡱ ⠊⣉⡱ ⠀⠶⠀ ⣏⣉⡉ ⡎⢉⢵
⢀⣸⣀ ⠉⠉⡏ ⠀⠶⠀ ⣔⣉⣀ ⢄⣀⡸ ⠀⠶⠀ ⢄⣀⡸ ⢗⣁⡸</pre>
 
=={{header|Phix}}==
{{libheader|Phix/pGUI}}
Requires 0.7.6 or later. Resizeable, appearance similar to Mathematica.
{{libheader|pGUIPhix/online}}
Resizeable, appearance similar to Mathematica.
<lang Phix>--
You can run this online [http://phix.x10.mx/p2js/clock.htm here].
-- demo\rosetta\Clock.exw
<!--<syntaxhighlight lang="phix">(phixonline)-->
--
<span style="color: #000080;font-style:italic;">--
include pGUI.e
-- demo\rosetta\Clock.exw
 
-- ======================
constant USE_OPENGL = 01
--</span>
 
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
Ihandle dlg, canvas, hTimer
<span style="color: #008080;">include</span> <span style="color: #000000;">pGUI</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
cdCanvas cd_canvas
<span style="color: #004080;">Ihandle</span> <span style="color: #000000;">dlg</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">canvas</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">hTimer</span>
 
<span style="color: #004080;">cdCanvas</span> <span style="color: #000000;">cd_canvas</span>
procedure draw_hand(atom degrees, atom r, baseangle, baselen, cx, cy)
atom a = PI-(degrees+90)*PI/180
<span style="color: #008080;">procedure</span> <span style="color: #000000;">draw_hand</span><span style="color: #0000FF;">(</span><span style="color: #004080;">atom</span> <span style="color: #000000;">degrees</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">atom</span> <span style="color: #000000;">r</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">baseangle</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">baselen</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">cx</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">cy</span><span style="color: #0000FF;">)</span>
-- tip
<span style="color: #004080;">atom</span> <span style="color: #000000;">a</span> <span style="color: #0000FF;">=</span> <span style="color: #004600;">PI</span><span style="color: #0000FF;">-(</span><span style="color: #000000;">degrees</span><span style="color: #0000FF;">+</span><span style="color: #000000;">90</span><span style="color: #0000FF;">)*</span><span style="color: #004600;">PI</span><span style="color: #0000FF;">/</span><span style="color: #000000;">180</span><span style="color: #0000FF;">,</span>
atom x1 = cos(a)*(r)
<span style="color: #000080;font-style:italic;">-- tip</span>
atom y1 = sin(a)*(r)
<span style="color: #000000;">x1</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">cos</span><span style="color: #0000FF;">(</span><span style="color: #000000;">a</span><span style="color: #0000FF;">)*(</span><span style="color: #000000;">r</span><span style="color: #0000FF;">),</span>
-- base
<span style="color: #000000;">y1</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">sin</span><span style="color: #0000FF;">(</span><span style="color: #000000;">a</span><span style="color: #0000FF;">)*(</span><span style="color: #000000;">r</span><span style="color: #0000FF;">),</span>
atom x2 = cos(a+PI-baseangle)*baselen
<span style="color: #000080;font-style:italic;">-- base</span>
atom y2 = sin(a+PI-baseangle)*baselen
<span style="color: #000000;">x2</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">cos</span><span style="color: #0000FF;">(</span><span style="color: #000000;">a</span><span style="color: #0000FF;">+</span><span style="color: #004600;">PI</span><span style="color: #0000FF;">-</span><span style="color: #000000;">baseangle</span><span style="color: #0000FF;">)*</span><span style="color: #000000;">baselen</span><span style="color: #0000FF;">,</span>
atom x3 = cos(a+PI+baseangle)*baselen
<span style="color: #000000;">y2</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">sin</span><span style="color: #0000FF;">(</span><span style="color: #000000;">a</span><span style="color: #0000FF;">+</span><span style="color: #004600;">PI</span><span style="color: #0000FF;">-</span><span style="color: #000000;">baseangle</span><span style="color: #0000FF;">)*</span><span style="color: #000000;">baselen</span><span style="color: #0000FF;">,</span>
atom y3 = sin(a+PI+baseangle)*baselen
<span style="color: #000000;">x3</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">cos</span><span style="color: #0000FF;">(</span><span style="color: #000000;">a</span><span style="color: #0000FF;">+</span><span style="color: #004600;">PI</span><span style="color: #0000FF;">+</span><span style="color: #000000;">baseangle</span><span style="color: #0000FF;">)*</span><span style="color: #000000;">baselen</span><span style="color: #0000FF;">,</span>
cdCanvasLineWidth(cd_canvas,1)
<span style="color: #000000;">y3</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">sin</span><span style="color: #0000FF;">(</span><span style="color: #000000;">a</span><span style="color: #0000FF;">+</span><span style="color: #004600;">PI</span><span style="color: #0000FF;">+</span><span style="color: #000000;">baseangle</span><span style="color: #0000FF;">)*</span><span style="color: #000000;">baselen</span>
cdCanvasLine(cd_canvas,cx+x1,cy+y1,cx+x2,cy+y2)
<span style="color: #7060A8;">cdCanvasSetLineWidth</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cd_canvas</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)</span>
cdCanvasLine(cd_canvas,cx+x2,cy+y2,cx+x3,cy+y3)
<span style="color: #7060A8;">cdCanvasLine</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cd_canvas</span><span style="color: #0000FF;">,</span><span style="color: #000000;">cx</span><span style="color: #0000FF;">+</span><span style="color: #000000;">x1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">cy</span><span style="color: #0000FF;">+</span><span style="color: #000000;">y1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">cx</span><span style="color: #0000FF;">+</span><span style="color: #000000;">x2</span><span style="color: #0000FF;">,</span><span style="color: #000000;">cy</span><span style="color: #0000FF;">+</span><span style="color: #000000;">y2</span><span style="color: #0000FF;">)</span>
cdCanvasLine(cd_canvas,cx+x3,cy+y3,cx+x1,cy+y1)
<span style="color: #7060A8;">cdCanvasLine</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cd_canvas</span><span style="color: #0000FF;">,</span><span style="color: #000000;">cx</span><span style="color: #0000FF;">+</span><span style="color: #000000;">x2</span><span style="color: #0000FF;">,</span><span style="color: #000000;">cy</span><span style="color: #0000FF;">+</span><span style="color: #000000;">y2</span><span style="color: #0000FF;">,</span><span style="color: #000000;">cx</span><span style="color: #0000FF;">+</span><span style="color: #000000;">x3</span><span style="color: #0000FF;">,</span><span style="color: #000000;">cy</span><span style="color: #0000FF;">+</span><span style="color: #000000;">y3</span><span style="color: #0000FF;">)</span>
cdCanvasBegin(cd_canvas,CD_FILL)
<span style="color: #7060A8;">cdCanvasLine</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cd_canvas</span><span style="color: #0000FF;">,</span><span style="color: #000000;">cx</span><span style="color: #0000FF;">+</span><span style="color: #000000;">x3</span><span style="color: #0000FF;">,</span><span style="color: #000000;">cy</span><span style="color: #0000FF;">+</span><span style="color: #000000;">y3</span><span style="color: #0000FF;">,</span><span style="color: #000000;">cx</span><span style="color: #0000FF;">+</span><span style="color: #000000;">x1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">cy</span><span style="color: #0000FF;">+</span><span style="color: #000000;">y1</span><span style="color: #0000FF;">)</span>
cdCanvasVertex(cd_canvas,cx+x1,cy+y1)
<span style="color: #7060A8;">cdCanvasBegin</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cd_canvas</span><span style="color: #0000FF;">,</span><span style="color: #004600;">CD_FILL</span><span style="color: #0000FF;">)</span>
cdCanvasVertex(cd_canvas,cx+x2,cy+y2)
<span style="color: #7060A8;">cdCanvasVertex</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cd_canvas</span><span style="color: #0000FF;">,</span><span style="color: #000000;">cx</span><span style="color: #0000FF;">+</span><span style="color: #000000;">x1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">cy</span><span style="color: #0000FF;">+</span><span style="color: #000000;">y1</span><span style="color: #0000FF;">)</span>
cdCanvasVertex(cd_canvas,cx+x3,cy+y3)
<span style="color: #7060A8;">cdCanvasVertex</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cd_canvas</span><span style="color: #0000FF;">,</span><span style="color: #000000;">cx</span><span style="color: #0000FF;">+</span><span style="color: #000000;">x2</span><span style="color: #0000FF;">,</span><span style="color: #000000;">cy</span><span style="color: #0000FF;">+</span><span style="color: #000000;">y2</span><span style="color: #0000FF;">)</span>
cdCanvasEnd(cd_canvas)
<span style="color: #7060A8;">cdCanvasVertex</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cd_canvas</span><span style="color: #0000FF;">,</span><span style="color: #000000;">cx</span><span style="color: #0000FF;">+</span><span style="color: #000000;">x3</span><span style="color: #0000FF;">,</span><span style="color: #000000;">cy</span><span style="color: #0000FF;">+</span><span style="color: #000000;">y3</span><span style="color: #0000FF;">)</span>
end procedure
<span style="color: #7060A8;">cdCanvasEnd</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cd_canvas</span><span style="color: #0000FF;">)</span>
 
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
procedure draw_clock(atom cx, cy, d)
atom w = 2+floor(d/25)
<span style="color: #008080;">procedure</span> <span style="color: #000000;">draw_clock</span><span style="color: #0000FF;">(</span><span style="color: #004080;">atom</span> <span style="color: #000000;">cx</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">cy</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">d</span><span style="color: #0000FF;">)</span>
cdCanvasFont(cd_canvas, "Helvetica", CD_PLAIN, floor(d/15))
<span style="color: #004080;">atom</span> <span style="color: #000000;">w</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">2</span><span style="color: #0000FF;">+</span><span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">d</span><span style="color: #0000FF;">/</span><span style="color: #000000;">25</span><span style="color: #0000FF;">)</span>
cdCanvasLineWidth(cd_canvas, w)
<span style="color: #7060A8;">cdCanvasFont</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cd_canvas</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"Helvetica"</span><span style="color: #0000FF;">,</span> <span style="color: #004600;">CD_PLAIN</span><span style="color: #0000FF;">,</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">d</span><span style="color: #0000FF;">/</span><span style="color: #000000;">15</span><span style="color: #0000FF;">))</span>
cdCanvasArc(cd_canvas, cx, cy, d, d, 0, 360)
<span style="color: #7060A8;">cdCanvasSetLineWidth</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cd_canvas</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">w</span><span style="color: #0000FF;">)</span>
d -= w+8
<span style="color: #7060A8;">cdCanvasArc</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cd_canvas</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">cx</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">cy</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">d</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">d</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">360</span><span style="color: #0000FF;">)</span>
w = 1+floor(d/50)
<span style="color: #000000;">d</span> <span style="color: #0000FF;">-=</span> <span style="color: #000000;">w</span><span style="color: #0000FF;">+</span><span style="color: #000000;">8</span>
for i=6 to 360 by 6 do
<span style="color: #000000;">w</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">1</span><span style="color: #0000FF;">+</span><span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">d</span><span style="color: #0000FF;">/</span><span style="color: #000000;">50</span><span style="color: #0000FF;">)</span>
integer h = remainder(i,30)=0
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">6</span> <span style="color: #008080;">to</span> <span style="color: #000000;">360</span> <span style="color: #008080;">by</span> <span style="color: #000000;">6</span> <span style="color: #008080;">do</span>
cdCanvasLineWidth(cd_canvas, floor(w*(1+h)/3))
<span style="color: #004080;">integer</span> <span style="color: #000000;">h</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">i</span><span style="color: #0000FF;">,</span><span style="color: #000000;">30</span><span style="color: #0000FF;">)=</span><span style="color: #000000;">0</span>
atom a = PI-(i+90)*PI/180
<span style="color: #7060A8;">cdCanvasSetLineWidth</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cd_canvas</span><span style="color: #0000FF;">,</span> <span style="color: #7060A8;">max</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">w</span><span style="color: #0000FF;">*(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">+</span><span style="color: #000000;">h</span><span style="color: #0000FF;">)/</span><span style="color: #000000;">3</span><span style="color: #0000FF;">),</span><span style="color: #000000;">1</span><span style="color: #0000FF;">))</span>
atom x1 = cos(a)*d/2, x2 = cos(a)*(d/2-w*(2+h)*.66)
<span style="color: #004080;">atom</span> <span style="color: #000000;">a</span> <span style="color: #0000FF;">=</span> <span style="color: #004600;">PI</span><span style="color: #0000FF;">-(</span><span style="color: #000000;">i</span><span style="color: #0000FF;">+</span><span style="color: #000000;">90</span><span style="color: #0000FF;">)*</span><span style="color: #004600;">PI</span><span style="color: #0000FF;">/</span><span style="color: #000000;">180</span><span style="color: #0000FF;">,</span>
atom y1 = sin(a)*d/2, y2 = sin(a)*(d/2-w*(2+h)*.66)
<span style="color: #000000;">x1</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">cos</span><span style="color: #0000FF;">(</span><span style="color: #000000;">a</span><span style="color: #0000FF;">)*</span><span style="color: #000000;">d</span><span style="color: #0000FF;">/</span><span style="color: #000000;">2</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">x2</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">cos</span><span style="color: #0000FF;">(</span><span style="color: #000000;">a</span><span style="color: #0000FF;">)*(</span><span style="color: #000000;">d</span><span style="color: #0000FF;">/</span><span style="color: #000000;">2</span><span style="color: #0000FF;">-</span><span style="color: #000000;">w</span><span style="color: #0000FF;">*(</span><span style="color: #000000;">2</span><span style="color: #0000FF;">+</span><span style="color: #000000;">h</span><span style="color: #0000FF;">)*.</span><span style="color: #000000;">66</span><span style="color: #0000FF;">),</span>
cdCanvasLine(cd_canvas, cx+x1, cy+y1, cx+x2, cy+y2)
<span style="color: #000000;">y1</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">sin</span><span style="color: #0000FF;">(</span><span style="color: #000000;">a</span><span style="color: #0000FF;">)*</span><span style="color: #000000;">d</span><span style="color: #0000FF;">/</span><span style="color: #000000;">2</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">y2</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">sin</span><span style="color: #0000FF;">(</span><span style="color: #000000;">a</span><span style="color: #0000FF;">)*(</span><span style="color: #000000;">d</span><span style="color: #0000FF;">/</span><span style="color: #000000;">2</span><span style="color: #0000FF;">-</span><span style="color: #000000;">w</span><span style="color: #0000FF;">*(</span><span style="color: #000000;">2</span><span style="color: #0000FF;">+</span><span style="color: #000000;">h</span><span style="color: #0000FF;">)*.</span><span style="color: #000000;">66</span><span style="color: #0000FF;">)</span>
if h then
<span style="color: #7060A8;">cdCanvasLine</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cd_canvas</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">cx</span><span style="color: #0000FF;">+</span><span style="color: #000000;">x1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">cy</span><span style="color: #0000FF;">+</span><span style="color: #000000;">y1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">cx</span><span style="color: #0000FF;">+</span><span style="color: #000000;">x2</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">cy</span><span style="color: #0000FF;">+</span><span style="color: #000000;">y2</span><span style="color: #0000FF;">)</span>
x1 = cos(a)*(d/2-w*4.5)
<span style="color: #008080;">if</span> <span style="color: #000000;">h</span> <span style="color: #008080;">then</span>
y1 = sin(a)*(d/2-w*4.5)
<span style="color: #000000;">x1</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">cos</span><span style="color: #0000FF;">(</span><span style="color: #000000;">a</span><span style="color: #0000FF;">)*(</span><span style="color: #000000;">d</span><span style="color: #0000FF;">/</span><span style="color: #000000;">2</span><span style="color: #0000FF;">-</span><span style="color: #000000;">w</span><span style="color: #0000FF;">*</span><span style="color: #000000;">4.5</span><span style="color: #0000FF;">)</span>
cdCanvasText(cd_canvas,cx+x1,cy+y1,sprintf("%d",{i/30}))
<span style="color: #000000;">y1</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">sin</span><span style="color: #0000FF;">(</span><span style="color: #000000;">a</span><span style="color: #0000FF;">)*(</span><span style="color: #000000;">d</span><span style="color: #0000FF;">/</span><span style="color: #000000;">2</span><span style="color: #0000FF;">-</span><span style="color: #000000;">w</span><span style="color: #0000FF;">*</span><span style="color: #000000;">4.5</span><span style="color: #0000FF;">)</span>
end if
<span style="color: #7060A8;">cdCanvasText</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cd_canvas</span><span style="color: #0000FF;">,</span><span style="color: #000000;">cx</span><span style="color: #0000FF;">+</span><span style="color: #000000;">x1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">cy</span><span style="color: #0000FF;">+</span><span style="color: #000000;">y1</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"%d"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">i</span><span style="color: #0000FF;">/</span><span style="color: #000000;">30</span><span style="color: #0000FF;">}))</span>
end for
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
atom {hour,mins,secs,msecs} = date(true)[DT_HOUR..DT_MSEC]
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
if IupGetInt(hTimer,"TIME")<1000 then
<span style="color: #004080;">atom</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">hour</span><span style="color: #0000FF;">,</span><span style="color: #000000;">mins</span><span style="color: #0000FF;">,</span><span style="color: #000000;">secs</span><span style="color: #0000FF;">,</span><span style="color: #000000;">msecs</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">date</span><span style="color: #0000FF;">(</span><span style="color: #004600;">true</span><span style="color: #0000FF;">)[</span><span style="color: #004600;">DT_HOUR</span><span style="color: #0000FF;">..</span><span style="color: #004600;">DT_MSEC</span><span style="color: #0000FF;">]</span>
-- (if showing once a second, always land on exact
<span style="color: #008080;">if</span> <span style="color: #7060A8;">IupGetInt</span><span style="color: #0000FF;">(</span><span style="color: #000000;">hTimer</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"TIME"</span><span style="color: #0000FF;">)<</span><span style="color: #000000;">1000</span> <span style="color: #008080;">then</span>
-- seconds, ie completely ignore msecs, otherwise
<span style="color: #000080;font-style:italic;">-- (if showing once a second, always land on exact
-- show smooth running (fractional) second hand.)
secs +=-- seconds, ie completely ignore msecs/1000, otherwise
-- show smooth running (fractional) second hand.)</span>
end if
<span style="color: #000000;">secs</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">msecs</span><span style="color: #0000FF;">/</span><span style="color: #000000;">1000</span>
mins += secs/60
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
hour += mins/60
<span style="color: #000000;">mins</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">secs</span><span style="color: #0000FF;">/</span><span style="color: #000000;">60</span>
atom r = d/2
<span style="color: #000000;">hour</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">mins</span><span style="color: #0000FF;">/</span><span style="color: #000000;">60</span>
draw_hand(hour*360/12,r-w*9,0.3,d/20,cx,cy)
<span style="color: #004080;">atom</span> <span style="color: #000000;">r</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">d</span><span style="color: #0000FF;">/</span><span style="color: #000000;">2</span>
draw_hand(mins*360/60,r-w*2,0.2,d/16,cx,cy)
<span style="color: #000000;">draw_hand</span><span style="color: #0000FF;">(</span><span style="color: #000000;">hour</span><span style="color: #0000FF;">*</span><span style="color: #000000;">360</span><span style="color: #0000FF;">/</span><span style="color: #000000;">12</span><span style="color: #0000FF;">,</span><span style="color: #000000;">r</span><span style="color: #0000FF;">-</span><span style="color: #000000;">w</span><span style="color: #0000FF;">*</span><span style="color: #000000;">9</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0.3</span><span style="color: #0000FF;">,</span><span style="color: #000000;">d</span><span style="color: #0000FF;">/</span><span style="color: #000000;">20</span><span style="color: #0000FF;">,</span><span style="color: #000000;">cx</span><span style="color: #0000FF;">,</span><span style="color: #000000;">cy</span><span style="color: #0000FF;">)</span>
cdCanvasSetForeground(cd_canvas, CD_RED)
<span style="color: #000000;">draw_hand</span><span style="color: #0000FF;">(</span><span style="color: #000000;">mins</span><span style="color: #0000FF;">*</span><span style="color: #000000;">360</span><span style="color: #0000FF;">/</span><span style="color: #000000;">60</span><span style="color: #0000FF;">,</span><span style="color: #000000;">r</span><span style="color: #0000FF;">-</span><span style="color: #000000;">w</span><span style="color: #0000FF;">*</span><span style="color: #000000;">2</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0.2</span><span style="color: #0000FF;">,</span><span style="color: #000000;">d</span><span style="color: #0000FF;">/</span><span style="color: #000000;">16</span><span style="color: #0000FF;">,</span><span style="color: #000000;">cx</span><span style="color: #0000FF;">,</span><span style="color: #000000;">cy</span><span style="color: #0000FF;">)</span>
draw_hand(secs*360/60,r-w*2,0.05,d/16,cx,cy)
<span style="color: #7060A8;">cdCanvasSetForeground</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cd_canvas</span><span style="color: #0000FF;">,</span> <span style="color: #004600;">CD_RED</span><span style="color: #0000FF;">)</span>
cdCanvasSetForeground(cd_canvas, CD_BLACK)
<span style="color: #000000;">draw_hand</span><span style="color: #0000FF;">(</span><span style="color: #000000;">secs</span><span style="color: #0000FF;">*</span><span style="color: #000000;">360</span><span style="color: #0000FF;">/</span><span style="color: #000000;">60</span><span style="color: #0000FF;">,</span><span style="color: #000000;">r</span><span style="color: #0000FF;">-</span><span style="color: #000000;">w</span><span style="color: #0000FF;">*</span><span style="color: #000000;">2</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0.05</span><span style="color: #0000FF;">,</span><span style="color: #000000;">d</span><span style="color: #0000FF;">/</span><span style="color: #000000;">16</span><span style="color: #0000FF;">,</span><span style="color: #000000;">cx</span><span style="color: #0000FF;">,</span><span style="color: #000000;">cy</span><span style="color: #0000FF;">)</span>
end procedure
<span style="color: #7060A8;">cdCanvasSetForeground</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cd_canvas</span><span style="color: #0000FF;">,</span> <span style="color: #004600;">CD_BLACK</span><span style="color: #0000FF;">)</span>
 
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
function redraw_cb(Ihandle /*ih*/, integer /*posx*/, integer /*posy*/)
integer {width, height} = IupGetIntInt(canvas, "DRAWSIZE")
<span style="color: #008080;">function</span> <span style="color: #000000;">redraw_cb</span><span style="color: #0000FF;">(</span><span style="color: #004080;">Ihandle</span> <span style="color: #000080;font-style:italic;">/*ih*/</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">integer</span> <span style="color: #000080;font-style:italic;">/*posx*/</span><span style="color: #0000FF;">,</span> <span style="color: #000080;font-style:italic;">/*posy*/</span><span style="color: #0000FF;">)</span>
integer r = floor(min(width,height)*0.9)
<span style="color: #004080;">integer</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">width</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">height</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupGetIntInt</span><span style="color: #0000FF;">(</span><span style="color: #000000;">canvas</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"DRAWSIZE"</span><span style="color: #0000FF;">),</span>
integer cx = floor(width/2)
<span style="color: #000000;">r</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">min</span><span style="color: #0000FF;">(</span><span style="color: #000000;">width</span><span style="color: #0000FF;">,</span><span style="color: #000000;">height</span><span style="color: #0000FF;">)*</span><span style="color: #000000;">0.9</span><span style="color: #0000FF;">),</span>
integer cy = floor(height/2)
<span style="color: #000000;">cx</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">width</span><span style="color: #0000FF;">/</span><span style="color: #000000;">2</span><span style="color: #0000FF;">),</span>
cdCanvasActivate(cd_canvas)
<span style="color: #000000;">cy</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">height</span><span style="color: #0000FF;">/</span><span style="color: #000000;">2</span><span style="color: #0000FF;">)</span>
cdCanvasClear(cd_canvas)
<span style="color: #7060A8;">cdCanvasActivate</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cd_canvas</span><span style="color: #0000FF;">)</span>
draw_clock(cx,cy,r)
<span style="color: #7060A8;">cdCanvasClear</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cd_canvas</span><span style="color: #0000FF;">)</span>
cdCanvasFlush(cd_canvas)
<span style="color: #000000;">draw_clock</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cx</span><span style="color: #0000FF;">,</span><span style="color: #000000;">cy</span><span style="color: #0000FF;">,</span><span style="color: #000000;">r</span><span style="color: #0000FF;">)</span>
return IUP_DEFAULT
<span style="color: #7060A8;">cdCanvasFlush</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cd_canvas</span><span style="color: #0000FF;">)</span>
end function
<span style="color: #008080;">return</span> <span style="color: #004600;">IUP_DEFAULT</span>
 
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
function timer_cb(Ihandle /*ih*/)
IupUpdate(canvas)
<span style="color: #008080;">function</span> <span style="color: #000000;">timer_cb</span><span style="color: #0000FF;">(</span><span style="color: #004080;">Ihandle</span> <span style="color: #000080;font-style:italic;">/*ih*/</span><span style="color: #0000FF;">)</span>
return IUP_IGNORE
<span style="color: #7060A8;">IupUpdate</span><span style="color: #0000FF;">(</span><span style="color: #000000;">canvas</span><span style="color: #0000FF;">)</span>
end function
<span style="color: #008080;">return</span> <span style="color: #004600;">IUP_IGNORE</span>
 
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
function map_cb(Ihandle ih)
if USE_OPENGL then
<span style="color: #008080;">function</span> <span style="color: #000000;">map_cb</span><span style="color: #0000FF;">(</span><span style="color: #004080;">Ihandle</span> <span style="color: #000000;">ih</span><span style="color: #0000FF;">)</span>
atom res = IupGetDouble(NULL, "SCREENDPI")/25.4
<span style="color: #7060A8;">IupGLMakeCurrent</span><span style="color: #0000FF;">(</span><span style="color: #000000;">canvas</span><span style="color: #0000FF;">)</span>
IupGLMakeCurrent(canvas)
<span style="color: #008080;">if</span> <span style="color: #7060A8;">platform</span><span style="color: #0000FF;">()=</span><span style="color: #004600;">JS</span> <span style="color: #008080;">then</span>
cd_canvas = cdCreateCanvas(CD_GL, "10x10 %g", {res})
<span style="color: #000000;">cd_canvas</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">cdCreateCanvas</span><span style="color: #0000FF;">(</span><span style="color: #004600;">CD_IUP</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">canvas</span><span style="color: #0000FF;">)</span>
else
<span style="color: #008080;">else</span>
cd_canvas = cdCreateCanvas(CD_IUPDBUFFER, canvas)
<span style="color: #004080;">atom</span> <span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupGetDouble</span><span style="color: #0000FF;">(</span><span style="color: #004600;">NULL</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"SCREENDPI"</span><span style="color: #0000FF;">)/</span><span style="color: #000000;">25.4</span>
end if
<span style="color: #000000;">cd_canvas</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">cdCreateCanvas</span><span style="color: #0000FF;">(</span><span style="color: #004600;">CD_GL</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"10x10 %g"</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">res</span><span style="color: #0000FF;">})</span>
cdCanvasSetBackground(cd_canvas, CD_WHITE)
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
cdCanvasSetForeground(cd_canvas, CD_BLACK)
<span style="color: #7060A8;">cdCanvasSetBackground</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cd_canvas</span><span style="color: #0000FF;">,</span> <span style="color: #004600;">CD_WHITE</span><span style="color: #0000FF;">)</span>
{} = cdCanvasTextAlignment(cd_canvas, CD_CENTER)
<span style="color: #7060A8;">cdCanvasSetForeground</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cd_canvas</span><span style="color: #0000FF;">,</span> <span style="color: #004600;">CD_BLACK</span><span style="color: #0000FF;">)</span>
return IUP_DEFAULT
<span style="color: #7060A8;">cdCanvasSetTextAlignment</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cd_canvas</span><span style="color: #0000FF;">,</span> <span style="color: #004600;">CD_CENTER</span><span style="color: #0000FF;">)</span>
end function
<span style="color: #008080;">return</span> <span style="color: #004600;">IUP_DEFAULT</span>
 
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
function canvas_resize_cb(Ihandle /*canvas*/)
if USE_OPENGL then
<span style="color: #008080;">function</span> <span style="color: #000000;">canvas_resize_cb</span><span style="color: #0000FF;">(</span><span style="color: #004080;">Ihandle</span> <span style="color: #000080;font-style:italic;">/*canvas*/</span><span style="color: #0000FF;">)</span>
integer {canvas_width, canvas_height} = IupGetIntInt(canvas, "DRAWSIZE")
<span style="color: #004080;">integer</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">canvas_width</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">canvas_height</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupGetIntInt</span><span style="color: #0000FF;">(</span><span style="color: #000000;">canvas</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"DRAWSIZE"</span><span style="color: #0000FF;">)</span>
atom res = IupGetDouble(NULL, "SCREENDPI")/25.4
<span style="color: #004080;">atom</span> <span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupGetDouble</span><span style="color: #0000FF;">(</span><span style="color: #004600;">NULL</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"SCREENDPI"</span><span style="color: #0000FF;">)/</span><span style="color: #000000;">25.4</span>
cdCanvasSetAttribute(cd_canvas, "SIZE", "%dx%d %g", {canvas_width, canvas_height, res})
<span style="color: #7060A8;">cdCanvasSetAttribute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cd_canvas</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"SIZE"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"%dx%d %g"</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">canvas_width</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">canvas_height</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">res</span><span style="color: #0000FF;">})</span>
end if
<span style="color: #008080;">return</span> <span style="color: #004600;">IUP_DEFAULT</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
end function
 
<span style="color: #008080;">procedure</span> <span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
function esc_close(Ihandle /*ih*/, atom c)
<span style="color: #7060A8;">IupOpen</span><span style="color: #0000FF;">()</span>
if c=K_ESC then return IUP_CLOSE end if
return IUP_CONTINUE
<span style="color: #000000;">canvas</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupGLCanvas</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"RASTERSIZE=350x350"</span><span style="color: #0000FF;">)</span>
end function
<span style="color: #7060A8;">IupSetCallbacks</span><span style="color: #0000FF;">(</span><span style="color: #000000;">canvas</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #008000;">"MAP_CB"</span><span style="color: #0000FF;">,</span> <span style="color: #7060A8;">Icallback</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"map_cb"</span><span style="color: #0000FF;">),</span>
 
<span style="color: #008000;">"ACTION"</span><span style="color: #0000FF;">,</span> <span style="color: #7060A8;">Icallback</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"redraw_cb"</span><span style="color: #0000FF;">),</span>
procedure main()
<span style="color: #008000;">"RESIZE_CB"</span><span style="color: #0000FF;">,</span> <span style="color: #7060A8;">Icallback</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"canvas_resize_cb"</span><span style="color: #0000FF;">)})</span>
IupOpen()
 
<span style="color: #000000;">hTimer</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupTimer</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">Icallback</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"timer_cb"</span><span style="color: #0000FF;">),</span> <span style="color: #000000;">40</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- smooth secs
if USE_OPENGL then
-- hTimer = IupTimer(Icallback("timer_cb"), 1000) -- tick seconds</span>
canvas = IupGLCanvas()
else
<span style="color: #000000;">dlg</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupDialog</span><span style="color: #0000FF;">(</span><span style="color: #000000;">canvas</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"TITLE=Clock"</span><span style="color: #0000FF;">)</span>
canvas = IupCanvas()
<span style="color: #7060A8;">IupShow</span><span style="color: #0000FF;">(</span><span style="color: #000000;">dlg</span><span style="color: #0000FF;">)</span>
end if
<span style="color: #7060A8;">IupSetAttribute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">canvas</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"RASTERSIZE"</span><span style="color: #0000FF;">,</span> <span style="color: #004600;">NULL</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- release the minimum limitation</span>
IupSetAttribute(canvas, "RASTERSIZE", "350x350") -- initial size
<span style="color: #008080;">if</span> <span style="color: #7060A8;">platform</span><span style="color: #0000FF;">()!=</span><span style="color: #004600;">JS</span> <span style="color: #008080;">then</span>
IupSetCallback(canvas, "MAP_CB", Icallback("map_cb"))
<span style="color: #7060A8;">IupMainLoop</span><span style="color: #0000FF;">()</span>
IupSetCallback(canvas, "ACTION", Icallback("redraw_cb"))
<span style="color: #7060A8;">IupClose</span><span style="color: #0000FF;">()</span>
IupSetCallback(canvas, "RESIZE_CB", Icallback("canvas_resize_cb"))
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
 
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
hTimer = IupTimer(Icallback("timer_cb"), 40) -- smooth secs
-- hTimer = IupTimer(Icallback("timer_cb"), 1000) -- tick seconds
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
 
<!--</syntaxhighlight>-->
dlg = IupDialog(canvas)
IupSetAttribute(dlg, "TITLE", "Clock")
IupSetCallback(dlg, "K_ANY", Icallback("esc_close"))
 
IupShowXY(dlg,IUP_CENTER,IUP_CENTER)
IupSetAttribute(canvas, "RASTERSIZE", NULL) -- release the minimum limitation
IupMainLoop()
IupClose()
end procedure
 
main()</lang>
The distribution also contains demo\tinEWGdemo\tindemo\clock.exw, which is a win32-only digital affair (whereas the above should be fine on 32/64 and win/lnx).
 
=={{header|PicoLisp}}==
This is an animated ASCII drawing of the "Berlin-Uhr", a clock built to display the time according to the principles of set theory, which is installed in Berlin since 1975. See [http://www.surveyor.in-berlin.de/berlin/uhr/indexe.html www.surveyor.in-berlin.de/berlin/uhr/indexe.html].<langsyntaxhighlight PicoLisplang="picolisp">(de draw Lst
(for L Lst
(for X L
Line 3,751 ⟶ 5,167:
(bigBox (% (cadr Time) 5))
(draw (+ (10 . -) + (10 . -) + (10 . -) + (10 . -) +)) )
(wait 1000) )</langsyntaxhighlight>The six '#' characters in the "circle" on top toggle on/off every second. This is the display at 17:46
<pre> _____
/ \
Line 3,770 ⟶ 5,186:
| ======== | | | |
+----------+----------+----------+----------+</pre>
 
=={{header|Processing}}==
This simple example of an analog wall clock uses the Processing built-in time functions second(), minute(), and hour(). For each hand it rotates the sketch canvas and then draws a straight line.
 
<syntaxhighlight lang="java">void draw() {
drawClock();
}
void drawClock() {
background(192);
translate(width/2, height/2);
float s = second() * TWO_PI / 60.0;
float m = minute() * TWO_PI / 60.0;
float h = hour() * TWO_PI / 12.0;
rotate(s);
strokeWeight(1);
line(0, 0, 0, -width*0.5);
rotate(-s+m);
strokeWeight(2);
line(0, 0, 0, -width*0.4);
rotate(-m+h);
strokeWeight(4);
line(0, 0, 0, -width*0.2);
}</syntaxhighlight>
 
The sketch redraws at Processing's default 60fps. To redraw the screen only when the second hand changes, add a global variable and change draw() as follows:
 
<syntaxhighlight lang="java">int lastSec = second();
void draw() {
if (lastSec!=second()) {
drawClock();
lastSec=second();
}
}</syntaxhighlight>
 
One of the official Processing language examples is a more graphically detailed [https://processing.org/examples/clock.html Clock example].
 
==={{header|Processing Python mode}}===
<syntaxhighlight lang="python">
last_sec = second()
 
def draw():
global last_sec
if last_sec != second():
draw_clock()
last_sec = second()
 
def draw_clock():
background(192)
translate(width / 2, height / 2)
s = second() * TWO_PI / 60.0
m = minute() * TWO_PI / 60.0
h = hour() * TWO_PI / 12.0
rotate(s)
strokeWeight(1)
line(0, 0, 0, -width * 0.5)
rotate(-s + m)
strokeWeight(2)
line(0, 0, 0, -width * 0.4)
rotate(-m + h)
strokeWeight(4)
line(0, 0, 0, -width * 0.2)</syntaxhighlight>
 
=={{header|PureBasic}}==
[[File:PureBasic_Clock.png|thumb|Sample display of PureBasic solution]]
<langsyntaxhighlight lang="purebasic">#MiddleX = 90 + 1 ;x,y must be odd numbers, minimum width is 67
#MiddleY = #MiddleX
#len_sh = (#MiddleX - 8) * 0.97 ;length of second-hand
Line 3,823 ⟶ 5,300:
SetGadgetState(#clock_gad, ImageID(#clockFace_img))
EndIf
Until event = #PB_Event_CloseWindow</langsyntaxhighlight>
 
=={{header|Python}}==
[http://www.thinkgeek.com/gadgets/watches/6a17/ Think Geek Binary Clock]
Line 3,829 ⟶ 5,307:
===Textmode===
 
<langsyntaxhighlight lang="python">import time
 
def chunks(l, n=5):
Line 3,859 ⟶ 5,337:
print bin_bit(y[1])
print
print secs(s)</langsyntaxhighlight>
 
==={{libheader|VPython}}===
There is a 3D analog clock in the
[http://www.vpython.org/contents/contributed/cxvp_clock.py VPython contributed section]
 
=={{header|Quackery}}==
 
<syntaxhighlight lang="Quackery"> [ $ "turtleduck.qky" loadfile
$ "bigrat.qky" loadfile ] now!
 
[ $ \
import datetime
sec = datetime.timedelta(seconds=1)
time_will_be = datetime.datetime.now()+sec
hours = time_will_be.hour
minutes = time_will_be.minute
seconds = time_will_be.second
to_stack([hours, minutes, seconds])
\ python ] is time+1 ( --> [ )
 
 
[ $ \
import time
current_time = time.time()
time_to_sleep = 1.0 - (current_time % 1.0)
time.sleep(time_to_sleep)
\ python ] is wait ( --> )
 
[ 3 wide
60 times
[ 240 1 fly
10 1 walk
-250 1 fly
1 60 turn ]
7 wide
12 times
[ 235 1 fly
12 1 walk
-247 1 fly
1 12 turn ]
9 wide
4 times
[ 233 1 fly
14 1 walk
-247 1 fly
1 4 turn ]
1 wide
' [ 0 0 0 ] fill
[ 10 1 circle ] ] is face ( --> )
 
[ 12 wide
unpack rot dip
[ 43200 rot
720 v+ ]
12 v+
2dup turn
175 1 walk
-175 1 fly
-v turn ] is hour ( [ --> )
 
[ 8 wide
unpack rot drop
3600 rot
60 v+
2dup turn
200 1 walk
-200 1 fly
-v turn ] is minute ( [ --> )
 
[ 4 wide
2 peek
dup 60 turn
225 1 walk
-225 1 fly
negate 60 turn ] is second ( [ --> )
 
[ turtle
0 frames
[ clear -1 4 turn
face
time+1 dup dup
second minute hour
wait
frame 1 4 turn again ] ] is clock ( --> )</syntaxhighlight>
 
{{out}}
 
https://youtu.be/Z0XS9EnADGE
 
The audio, On the Teeth of Wheels by Beat Frequency, is a sonification of the [[Stern-Brocot sequence#Quackery]]. It was discovered independently by Moritz Stern (1858) and Achille Brocot (1861), along with its visualisation, the Stern-Brocot tree. Brocot was a watchmaker, and used the sequence to find best approximations for gear ratios.
 
The book "A Treatise On The Teeth of Wheels, Demonstrating The Best Form Which Can Be Given To Them For The Purposes Of Machinery; Such As Clockwork And Millwork, And The Art Of Finding Their Numbers" predates the sequence, being written by Charles Étienne Louis Camus in 1749-1752, (and translated from French to English by John Isaac Hawkins in 1873), but shows a method relying in part on guesswork to achieve the same end.
 
=={{header|Racket}}==
Line 3,869 ⟶ 5,435:
Draws an analog clock in a new GUI window:
 
<langsyntaxhighlight lang="racket">
#lang racket/gui
 
Line 3,925 ⟶ 5,491:
 
(send f show #t)
</syntaxhighlight>
</lang>
 
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku" line>my ($rows,$cols) = qx/stty size/.words;
my $v = floor $rows / 2;
my $h = floor $cols / 2 - 16;
 
my @t = < ⡎⢉⢵ ⠀⢺⠀ ⠊⠉⡱ ⠊⣉⡱ ⢀⠔⡇ ⣏⣉⡉ ⣎⣉⡁ ⠊⢉⠝ ⢎⣉⡱ ⡎⠉⢱ ⠀⠶⠀>;
my @b = < ⢗⣁⡸ ⢀⣸⣀ ⣔⣉⣀ ⢄⣀⡸ ⠉⠉⡏ ⢄⣀⡸ ⢇⣀⡸ ⢰⠁⠀ ⢇⣀⡸ ⢈⣉⡹ ⠀⠶⠀>;
 
loop {
my @x = DateTime.now.Str.substr(11,8).ords X- ord('0');
print "\e[H\e[J";
print "\e[$v;{$h}H";
print ~@t[@x];
print "\e[{$v+1};{$h}H";
print ~@b[@x];
print "\e[H";
sleep 1;
}</syntaxhighlight>
{{out}}
<pre>⠀⢺⠀ ⢀⠔⡇ ⠀⠶⠀ ⠊⠉⡱ ⠊⣉⡱ ⠀⠶⠀ ⣏⣉⡉ ⡎⢉⢵
⢀⣸⣀ ⠉⠉⡏ ⠀⠶⠀ ⣔⣉⣀ ⢄⣀⡸ ⠀⠶⠀ ⢄⣀⡸ ⢗⣁⡸</pre>
 
A simpler version that does not clear the screen:
 
<syntaxhighlight lang=raku>constant @t = < ⡎⢉⢵ ⠀⢺⠀ ⠊⠉⡱ ⠊⣉⡱ ⢀⠔⡇ ⣏⣉⡉ ⣎⣉⡁ ⠊⢉⠝ ⢎⣉⡱ ⡎⠉⢱ ⠀⠶⠀>;
constant @b = < ⢗⣁⡸ ⢀⣸⣀ ⣔⣉⣀ ⢄⣀⡸ ⠉⠉⡏ ⢄⣀⡸ ⢇⣀⡸ ⢰⠁⠀ ⢇⣀⡸ ⢈⣉⡹ ⠀⠶⠀>;
 
signal(SIGINT).tap: { print "\e[?25h\n"; exit }
print "\e7\e[?25l"; # saves cursor position, make it invisible
loop {
my @x = DateTime.now.Str.substr(11,8).ords X- ord('0');
put ~.[@x] for @t, @b;
sleep 1;
print "\e8"; # restores cursor position
}</syntaxhighlight>
 
Finally a more minimalist version that shows three progress bars (hours, minutes, seconds):
<syntaxhighlight lang=raku>print "\e7";
loop {
my $time = DateTime.now;
put '#' x $_ ~ '.' x (24 - $_) given $time.hour.round;
put '#' x $_ ~ '.' x (60 - $_) given $time.minute.round;
put '#' x $_ ~ '.' x (60 - $_) given $time.second.round;
sleep 1;
print "\e8";
}
END put "\n";</syntaxhighlight>
 
=={{header|Red}}==
===Minimalistic===
<syntaxhighlight lang="red">Red [Needs: 'View]
view [t: h4 rate 1 on-time [t/data: now/time]]
</syntaxhighlight>
{{out}}
[https://raw.githubusercontent.com/Palaing/redlib/master/games/images/miniclock.png mini clock image]
 
===Analog===
<syntaxhighlight lang="red">Red [
Needs: 'View
Purpose: {simple analog clock based on Nenad Rakocevic's eve-clock.red,
see http://www.red-lang.org/2016/07/eve-style-clock-demo-in-red-livecoded.html}
]
 
view [ base 100x100 transparent rate 1 now draw [
circle 50x50 45
hour: rotate 0 50x50 [pen #023963 line 50x50 50x20]
min: rotate 0 50x50 [pen #023963 line 50x50 50x10]
sec: rotate 0 50x50 [pen #CE0B46 line 50x50 50x10]
] on-time [
time: now/time
hour/2: 30 * time/hour
min/2: 6 * time/minute
sec/2: 6 * time/second
]]
</syntaxhighlight>
{{out}}
[https://raw.githubusercontent.com/Palaing/redlib/master/games/images/analogclock.png analog clock image]
 
=={{header|REXX}}==
This REXX program draws a digital clock; &nbsp; it shows the seconds if the terminal screen is wide enough.
<br>The clock displayed is displayed in a &nbsp; '''24''' &nbsp; hour format..
 
The &nbsp; '''$T.REX''' &nbsp; program does the heavy lifting of actually creating the blocked characters.
 
This REXX program was written when CRTs were used for terminal displays and therefore &nbsp; ''creeping'' &nbsp; was utilized to avoid phosphor burn-in.
If using
 
:::* '''PC/REXX'''
 
:::* '''Personal REXX'''
If using:
:::* '''R4'''
:::* &nbsp; '''ROOPC/REXX'''
:::* &nbsp; '''Personal REXX'''
:::* &nbsp; '''R4'''
:::* &nbsp; '''ROO'''
the color of the display can be specified.
<syntaxhighlight lang="rexx">/*REXX program displays the current (local) time as a digital clock on the terminal.*/
trace off /*turn off tracing/possible host errors*/
parse arg ! /*obtain optional arguments from the CL*/
if !all(arg()) then exit /*was there a request for some help? */
if !cms then address '' /*If CMS, then initialize ADDRESS name*/
 
signal on halt /*initialize target label when HALTed. */
signal on noValue /* " " " " noValue.*/
signal on syntax /* " " " " syntax. */
 
parse var ! ops /*obtain optional arguments from the CL*/
ops = space(ops) /*elide superfluous blanks from options*/
blinkSecs = 1 /*amount of time between displays. */
creep = 1 /*moves the output "around" the screen.*/
tops = '.C=blue .BC=░ .BS=1 .BLOCK=12' /*options to be specified for $T.REXX */
 
do while ops\=='' /*process all the specified options. */
parse var ops _1 2 1 _ . 1 y ops /*extract various information from opt.*/
upper _ /*uppercase the _ REXX variavle. */
select
when _==',' then nop /*ignore any comma used.*/
when _1==. & pos("=",_)\==0 then tops= tops y /*add this value to TOPS*/
when abbn('BLINKSECs') then blinksecs= no() /*use/not use BLINKSECs.*/
when abbn('CREEPs') then creep= no() /* " " " CREEPs. */
otherwise call er 55,y /*whoops! Invalid option*/
end /*select*/
end /*while ops¬==''*/
 
if \!pcrexx then blinkSecs= 0 /*Not PC/REXX? Then turn off BLINKSECS*/
tops= space(tops) /*elide superfluous blanks in TOPS. */
parse value scrsize() with sd sw . /*obtain the terminal screen dimensions*/
oldTime= /*blank out the OLDTIME for comparison.*/
do until queued()\==0 /*if user entered some text, then QUIT.*/
ct= time() /*obtain the current (system) time. */
mn= substr(ct, 4, 2) /*extract the minutes part of the time.*/
ss= right(ct, 2) /* " " seconds " " " " */
i_= 0 /*REXX variable used for display creep.*/
p_= 0 /* " " " " " " */
call blinksec
if ct==oldTime then if !cms then 'CP SLEEP' /*sleep for one second. */
else call delay 1 /* " " " " */
 
if creep then do; p_ = 3 + right(mn, 1) /*perform display creep.*/
if sd>26 then p_ = p_ + left(mn, 1)
if sd>33 then p_ = p_ + left(mn, 1)
if sd>44 then p_ = p_ + left(mn, 1) + right(mn, 1)
end
_p= - p_ /*change the sign of the P_ number. */
i_= 2 + left(ct, 1) /*obtain indentation size base on HH. */
if sw>108 then ctt= ct /*maybe use wider format for the clock*/
else ctt= left(ct, 5) /*maybe use narrow " " " " */
r= $t('.P='_p ".I="i_ tops ctt) /*where the rubber meets the road. */
if r\==0 then leave /*Had an error in $T ? Then quit. */
oldTime= time() /*save the new time, it may be the same*/
end /*forever*/
exit 0 /*stick a fork in it, we're all done. */
 
/*═════════════════════════════general 1-line subs══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════*/
!all: !!=!;!=space(!);upper !;call !fid;!nt=right(!var('OS'),2)=='NT';!cls=word('CLS VMFCLEAR CLRSCREEN',1+!cms+!tso*2);if arg(1)\==1 then return 0;if wordpos(!,'? ?SAMPLES ?AUTHOR ?FLOW')==0 then return 0;!call=']$H';call '$H' !fn !;!call=;return 1
!cal: if symbol('!CALL')\=="VAR" then !call=; return !call
!env: !env= 'ENVIRONMENT'; if !sys=="MSDOS" | !brexx | !r4 | !roo then !env= 'SYSTEM'; if !os2 then !env= "OS2"!env; !ebcdic= 3=='f3'x; if !crx then !env= "DOS"; return
!fid: parse upper source !sys !fun !fid . 1 . . !fn !ft !fm .; call !sys; if !dos then do; _= lastpos('\', !fn); !fm= left(!fn, _); !fn= substr(!fn, _+1); parse var !fn !fn '.' !ft; end; return word(0 !fn !ft !fm, 1 +('0'arg(1)))
!rex: parse upper version !ver !vernum !verdate .; !brexx= 'BY'==!vernum; !kexx= "KEXX"==!ver; !pcrexx= 'REXX/PERSONAL'==!ver | "REXX/PC"==!ver; !r4= 'REXX-R4'==!ver; !regina="REXX-REGINA"==left(!ver, 11); !roo='REXX-ROO'==!ver; call !env; return
!sys: !cms= !sys=='CMS'; !os2= !sys=="OS2"; !tso= !sys=='TSO' | !sys=="MVS"; !vse= !sys=='VSE'; !dos= pos("DOS", !sys)\==0 | pos('WIN', !sys)\==0 | !sys=="CMD"; !crx= left(!sys, 6)=='DOSCRX'; call !rex; return
!var: call !fid; if !kexx then return space( dosenv( arg(1) ) ); return space( value( arg(1), , !env))
$t: !call= ']$T'; call "$T" arg(1); !call=; return result
abb: parse upper arg abbu; parse arg abb; return abbrev(abbu, _, abbl(abb) )
abbl: @abc = 'abcdefghijklmnopqrstuvwxyz'; return verify(arg(1)'a', @abc, 'M') - 1
abbn: parse arg abbn; return abb(abbn) | abb('NO'abbn)
blinksec: if \blinksecs then return; bsec= ' '; ss2= right(ss, 2); if sw<=80 then bsec= copies(" ", 2 + ss2) ss2; call scrwrite 1 + right(mn, 1), 1, bsec, , , 1; call cursor sd - right(mn, 1), sw - length(bsec); return
er: parse arg _1,_2; call '$ERR' "14"p(_1) p(word(_1, 2) !fid(1)) _2; if _1<0 then return _1; exit result
err: call er '-'arg(1),arg(2); return ''
erx: call er '-'arg(1),arg(2); exit 0
halt: call er .1
no: if arg(1)\=='' then call er 01,arg(2); return left(_, 2) \== 'NO'
noValue: !sigl= sigl; call er 17,!fid(2) !fid(3) !sigl condition('D') sourceline(!sigl)
p: return word( arg(1), 1)
syntax: !sigl= sigl; call er 13,!fid(2) !fid(3) !sigl !cal() condition('D') sourceline(!sigl)</syntaxhighlight>
;Programming notes:
The &nbsp; '''$CLOCK.REX''' &nbsp; REXX program makes use of &nbsp; '''$T.REX''' &nbsp; REXX program which is used to display text and/or create big blocked characters.
<br>The &nbsp; '''$T.REX''' &nbsp; REXX program is included here &nbsp; ──► &nbsp; [[$T.REX]].
Line 3,953 ⟶ 5,680:
 
REXX programs not included are &nbsp; '''$H.REX''' &nbsp; which shows '''help''' and other documentation.
<lang rexx>/**/trace o;parse arg !;if !all(arg()) then exit;if !cms then address ''
signal on halt; signal on novalue; signal on syntax
parse var ! ops; ops = space(ops) /*obtain command line options. */
@abc = 'abcdefghijklmnopqrstuvwxyz' /*alphabet str used by ABB/ABBN. */
blinkSecs = 1
creep = 1
tops = '.C=blue .BC=░ .BS=1 .BLOCK=12'
 
do while ops\==''; parse var ops _1 2 1 _ . 1 y ops; upper _
select
when _==',' then nop
when _1=='.' & pos("=",_)\==0 then tops=tops y
when abbn('BLINKSECs') then blinksecs=no()
when abbn('CREEPs') then creep=no()
otherwise call er 55,y
end /*select*/
end /*while ops¬==''*/
 
if \!pcrexx then blinkSecs=0 /*if ¬PC/REXX, turn off BLINKSECS*/
tops=space(tops) /*elide extraneous TOPS blanks.*/
parse value scrsize() with sd sw . /*get the term screens dimensions*/
oldTime=
do until queued()\==0
ct=time(); mn=substr(ct,4,2); ss=right(ct,2); i_=0; p_=0
call blinksec
if ct==oldTime then if !cms then 'CP SLEEP'; else call delay 1
 
{{out|output|text=&nbsp; when using the default inputs:}}
if creep then do; p_ = 3 + right(mn,1)
if sd>26 then p_ = p_ + left(mn,1)
if sd>33 then p_ = p_ + left(mn,1)
if sd>44 then p_ = p_ + left(mn,1) +right(mn,1)
end
_p=-p_
i_=2+left(ct,1); ctt=left(ct,5); if sw>108 then ctt=ct
r=$t('.P='_p ".I="i_ tops ctt); if r\==0 then leave
oldTime=time()
end /*forever*/
exit /*stick a fork in it, we're done.*/
/*═════════════════════════════general 1-line subs════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════*/
!all:!!=!;!=space(!);upper !;call !fid;!nt=right(!var('OS'),2)=='NT';!cls=word('CLS VMFCLEAR CLRSCREEN',1+!cms+!tso*2);if arg(1)\==1 then return 0;if wordpos(!,'? ?SAMPLES ?AUTHOR ?FLOW')==0 then return 0;!call=']$H';call '$H' !fn !;!call=;return 1
!cal: if symbol('!CALL')\=="VAR" then !call=;return !call
!env: !env='ENVIRONMENT';if !sys=='MSDOS'|!brexx|!r4|!roo then !env='SYSTEM';if !os2 then !env='OS2'!env;!ebcdic=1=='f0'x;return
!fid: parse upper source !sys !fun !fid . 1 . . !fn !ft !fm .;call !sys;if !dos then do;_=lastpos('\',!fn);!fm=left(!fn,_);!fn=substr(!fn,_+1);parse var !fn !fn '.' !ft;end;return word(0 !fn !ft !fm,1+('0'arg(1)))
!rex: parse upper version !ver !vernum !verdate .;!brexx='BY'==!vernum;!kexx='KEXX'==!ver;!pcrexx='REXX/PERSONAL'==!ver|'REXX/PC'==!ver;!r4='REXX-R4'==!ver;!regina='REXX-REGINA'==left(!ver,11);!roo='REXX-ROO'==!ver;call !env;return
!sys: !cms=!sys=='CMS';!os2=!sys=='OS2';!tso=!sys=='TSO'|!sys=='MVS';!vse=!sys=='VSE';!dos=pos('DOS',!sys)\==0|pos('WIN',!sys)\==0|!sys=='CMD';call !rex;return
!var: call !fid;if !kexx then return space(dosenv(arg(1)));return space(value(arg(1),,!env))
$t: !call=']$T';call "$T" arg(1);!call=;return result
abb: arg abbu;parse arg abb;return abbrev(abbu,_,abbl(abb))
abbl: return verify(arg(1)'a',@abc,'M')-1
abbn: parse arg abbn;return abb(abbn)|abb('NO'abbn)
blinksec: if \blinksecs then return;bsec=' ';ss2=right(ss,2);if sw<=80 then bsec=copies(' ',2+ss2) ss2;call scrwrite 1+right(mn,1),1,bsec,,,1;call cursor sd-right(mn,1),sw-length(bsec);return
er: parse arg _1,_2;call '$ERR' "14"p(_1) p(word(_1,2) !fid(1)) _2;if _1<0 then return _1;exit result
err: call er '-'arg(1),arg(2);return ''
erx: call er '-'arg(1),arg(2);exit ''
halt: call er .1
no: if arg(1)\=='' then call er 01,arg(2);return left(_,2)\=='NO'
novalue:!sigl=sigl;call er 17,!fid(2) !fid(3) !sigl condition('D') sourceline(!sigl)
p: return word(arg(1),1)
syntax:!sigl=sigl;call er 13,!fid(2) !fid(3) !sigl !cal() condition('D') sourceline(!sigl)</lang>
'''output'''
<pre>
░░░░░░░░ ░░░░░░░░ ░░ ░░░░░░░░░░ ░░░ ░░░░░░░░░░
Line 4,027 ⟶ 5,698:
░░░░░░░░░░ ░░░░░░░░ ░░░░░░ ░░░░░░░░ ░░░░ ░░░░░░░░
</pre>
 
'''output''' &nbsp; (when the terminal screen is less then 109 bytes)
{{out|output|text=&nbsp; (when the terminal screen is less than 109 bytes)}}
<pre>
░░░░░░░░ ░░░░░░░░ ░░░░░░░░ ░░░░░░░░░░
Line 4,046 ⟶ 5,718:
{{libheader|Shoes}}
[[File:shoes_clock.png|thumb|Sample display of Ruby solution]]
<langsyntaxhighlight lang="ruby">Shoes.app(:width=>205, :height => 228, :title => "A Clock") do
def draw_ray(width, start, stop, ratio)
angle = Math::PI * 2 * ratio - Math::PI/2
Line 4,086 ⟶ 5,758:
 
animate(5) {update}
end</langsyntaxhighlight>
 
Inspired by the PicoLisp solution, here's an implementation of the Berlin-Uhr clock.
[[File:berlin_uhr.rb.png|thumb|Berlin-Uhr clock]]
<langsyntaxhighlight lang="ruby">Shoes.app(:title => "Berlin-Uhr Clock", :width => 209, :height => 300) do
background lightgrey
 
Line 4,134 ⟶ 5,806:
end
end
end</langsyntaxhighlight>
 
{{libheader|RubyGems}}
{{libheader|JRubyArt}}
JRubyArt is port of processing to ruby
<syntaxhighlight lang="ruby">
def setup
sketch_title 'Clock'
stroke 255
font = create_font 'NimbusRoman-Regular', 20
text_font font
end
 
def draw
background 0
fill 80
no_stroke
clock_x = lambda do |val, adj, length|
DegLut.cos((val * adj).to_i - 90) * length + width / 2
end
clock_y = lambda do |val, adj, length|
DegLut.sin((val * adj).to_i - 90) * length + height / 2
end
ellipse 100, 100, 160, 160
stroke 220
stroke_weight 6
t = Time.now
line(100, 100, clock_x.call(t.hour % 12 + (t.min / 60.0), 30, 50),
clock_y.call(t.hour % 12 + (t.min / 60.0), 30, 50))
stroke_weight 3
line(100, 100, clock_x.call(t.min + (t.sec / 60.0), 6, 60),
clock_y.call(t.min + (t.sec / 60.0), 6, 60))
stroke 255, 0, 0
stroke_weight 1
line(100, 100, clock_x.call(t.sec, 6, 72), clock_y.call(t.sec, 6, 72))
# Draw the minute ticks
stroke_weight 2
stroke 255
(0..360).step(6) do |a|
x = 100 + DegLut.cos(a) * 72
y = 100 + DegLut.sin(a) * 72
point x, y
end
fill 200
text t.strftime('%H:%M:%S'), 50, 200
end
 
def settings
size 200, 220
smooth 8
end
 
</syntaxhighlight>
 
=={{header|Run BASIC}}==
[[File:Rb_clock.png|thumb|Sample display of RB solution]]
<langsyntaxhighlight lang="runbasic">' --------------------------------------------
' clock. I got nothing but time
' ---------------------------------------------
Line 4,232 ⟶ 5,956:
#g2 circle(2)
#g2 line(100,100,px,py)
RETURN</langsyntaxhighlight>
 
=={{header|Rust}}==
<langsyntaxhighlight lang="rust">// cargo-deps: time="0.1"
extern crate time;
 
Line 4,263 ⟶ 5,987:
fn clear_screen() {
println!("{}[H{}[J", 27 as char, 27 as char);
}</langsyntaxhighlight>
 
=={{header|Scala}}==
===Circular ASCII clock===
Generates and prints a simple ASCII clock every second
<langsyntaxhighlight lang="scala">import java.util.{ Timer, TimerTask }
import java.time.LocalTime
import scala.math._
 
object Clock extends App {
private val (width, heigthheight) = (80, 35)
 
def getGrid(localTime: LocalTime): Array[Array[Char]] = {
val (minute, second) = (localTime.getMinute, localTime.getSecond())
val grid = Array.fill[Char](heigthheight, width)(' ')
 
def toGridCoord(x: Double, y: Double): (Int, Int) =
(floor((y + 1.0) / 2.0 * heigthheight).toInt, floor((x + 1.0) / 2.0 * width).toInt)
 
def makeText(grid: Array[Array[Char]], r: Double, theta: Double, str: String) {
val (row, col) = toGridCoord(r * cos(theta), r * sin(theta))
(0 until str.length).foreach(i =>
if (row >= 0 && row < heigthheight && col + i >= 0 && col + i < width) grid(row)(col + i) = str(i))
}
 
Line 4,292 ⟶ 6,016:
while (theta < 2 * Pi) {
val (row, col) = toGridCoord(r * cos(theta), r * sin(theta))
if (row >= 0 && row < heigthheight && col >= 0 && col < width) grid(row)(col) = c
theta = theta + 0.01
}
Line 4,301 ⟶ 6,025:
while (r < maxR) {
val (row, col) = toGridCoord(r * cos(theta), r * sin(theta))
if (row >= 0 && row < heigthheight && col >= 0 && col < width) grid(row)(col) = c
r = r + 0.01
}
Line 4,320 ⟶ 6,044:
}
(new Timer).schedule(timerTask, 0, 1000)
}</langsyntaxhighlight>
===Berliner Uhr===
See [[http://en.wikipedia.org/wiki/Mengenlehreuhr The Berlin set theory clock]]
<langsyntaxhighlight lang="scala">import java.time.LocalTime
import java.awt.{ Color, Graphics }
 
Line 4,372 ⟶ 6,096:
}
}
}</langsyntaxhighlight>
 
=={{header|Scheme}}==
Line 4,380 ⟶ 6,104:
The program displays an analogue clock with three hands, updating once a second.
 
<syntaxhighlight lang="scheme">
<lang Scheme>
(import (scheme base)
(scheme inexact)
Line 4,440 ⟶ 6,164:
(hands canvas))
(tk-event-loop tk))
</syntaxhighlight>
</lang>
 
=={{header|Scratch}}==
Line 4,449 ⟶ 6,173:
=={{header|Seed7}}==
The example program clock3.sd7 from the Seed7 package can be used for this task.
<langsyntaxhighlight lang="seed7">$ include "seed7_05.s7i";
include "float.s7i";
include "math.s7i";
Line 4,473 ⟶ 6,197:
clear(curr_win, BACKGROUND);
KEYBOARD := GRAPH_KEYBOARD;
command := busy_getcgetc(KEYBOARD, NO_WAIT);
while command <> 'q' do
start_time := truncToSecond(time(NOW));
Line 4,515 ⟶ 6,239:
fcircle(100, 100, 7, CLOCKCOLOR);
circle(100, 100, 7, FOREGROUND);
DRAW_FLUSHflushGraphic;
await(start_time + 1 . SECONDS);
command := busy_getcgetc(KEYBOARD, NO_WAIT);
end while;
end func;</langsyntaxhighlight>
 
=={{header|Sidef}}==
{{trans|Perl}}
<langsyntaxhighlight lang="ruby">STDOUT.autoflush(true)
 
var (rows, cols) = `stty size`.nums...
Line 4,553 ⟶ 6,277:
print position(1, 1)
Sys.sleep(0.1)
}</langsyntaxhighlight>
{{out}}
<pre>
Line 4,562 ⟶ 6,286:
 
=={{header|SVG}}==
<langsyntaxhighlight lang="svg"><svg viewBox="0 0 100 100" width="480px" height="480px" xmlns="http://www.w3.org/2000/svg">
<circle cx="50" cy="50" r="48" style="fill:peru; stroke:black; stroke-width:2" />
<g transform="translate(50,50) rotate(0)" style="fill:none; stroke-linecap:round">
Line 4,596 ⟶ 6,320:
<circle cx="50" cy="50" r="4" style="fill:gold; stroke:black; stroke-width:1" />
</svg>
</syntaxhighlight>
</lang>
 
=={{header|Tcl}}==
[[File:Clock tcltk.png|thumb|Sample display of Tcl solution]]
{{libheader|Tk}}
<langsyntaxhighlight lang="tcl">package require Tcl 8.5
package require Tk
 
Line 4,632 ⟶ 6,357:
}
}
ticker</langsyntaxhighlight>
Note that though this code does poll the system timer approximately four times a second, this is a cheap operation; the GUI update (the relatively expensive part) only happens once a second. The amount of system processing power consumed by this code isn't noticeable on my system; it vanishes with respect to the other processing normally happening.
 
=={{header|VBScript}}==
The only way to do animation in VBScript is to use ANSI codes in the console. The program will work only in Windows 10 or up. Should be invoked from cscript
<syntaxhighlight lang="vb">
'ANSI Clock
 
'ansi escape functions
ans0=chr(27)&"["
sub cls() wscript.StdOut.Write ans0 &"2J"&ans0 &"?25l":end sub
sub torc(r,c,s) wscript.StdOut.Write ans0 & r & ";" & c & "f" & s :end sub
 
'bresenham
Sub draw_line(r1,c1, r2,c2,c)
Dim x,y,xf,yf,dx,dy,sx,sy,err,err2
x =r1 : y =c1
xf=r2 : yf=c2
dx=Abs(xf-x) : dy=Abs(yf-y)
If x<xf Then sx=+1: Else sx=-1
If y<yf Then sy=+1: Else sy=-1
err=dx-dy
Do
torc x,y,c
If x=xf And y=yf Then Exit Do
err2=err+err
If err2>-dy Then err=err-dy: x=x+sx
If err2< dx Then err=err+dx: y=y+sy
Loop
End Sub
 
const pi180=0.017453292519943
'center of the clock
const r0=13
const c0=26
 
'angles
nangi=-30*pi180
aangi=-6*pi180
ang0=90*pi180
 
'lengths of hands
lh=7
lm=9
ls=9
ln=12
 
 
while 1
cls
 
'dial
angn=ang0+nangi
for i=1 to 12
torc r0-cint(ln*sin(angn)),cint(c0+2*ln*cos(angn)),i
angn=angn+nangi
next
 
'get time and display it in numbers
t=now()
torc 1,1, hour(t) &":"& minute(t) &":"& second(t)
'angle for each hand
angh=ang0+hour(t) *nangi
angm=ang0+minute(t) *aangi
angS=ang0+second(t) *aangi
 
'draw them
draw_line r0,c0,cint(r0-ls*sin(angs)),cint(c0+2*ls*cos(angs)),"."
draw_line r0,c0,cint(r0-lm*sin(angm)),cint(c0+2*lm*cos(angm)),"*"
draw_line r0,c0,cint(r0-lh*sin(angh)),cint(c0+2*lh*cos(angh)),"W"
torc r0,c0,"O"
'wait one second
wscript.sleep(1000)
wend
</syntaxhighlight>
{{out}}
<pre>
15:8:37 12
 
11 1
 
 
 
10 ** 2
**
**
**
**
**
9 OWWWWWWWWWWWWWW 3
..
..
..
.
..
8 .. 4
.
 
 
7 5
 
6
 
</pre>
 
=={{header|V (Vlang)}}==
<syntaxhighlight lang="Go">
// Written by Stefan Schroeder in 2021 for the v project examples.
// github.com/vlang/v/blob/master/examples/clock/clock.v
import os
import gg
import gx
import math
import time
 
const (
// All coordinates are designed for a clock size of this many pixel.
// You cannot change the size of the clock by adjusting this value.
design_size = 700
center = 350
 
// Half the width of a tic-mark.
tw = 9
// Height of a minute tic-mark. (hour is twice, 3-hour is thrice)
th = 25
// Padding of tic-mark to window border
tp = 10
 
tic_color = gx.Color{
r: 50
g: 50
b: 50
}
hand_color = gx.black
second_hand_color = gx.red
)
 
struct App {
minutes_tic []f32 = [f32(center - tw), tp, center + tw, tp, center + tw, tp, center + tw,
tp + 1 * th, center - tw, tp + 1 * th]
hours_tic []f32 = [f32(center - tw), tp, center + tw, tp, center + tw, tp, center + tw, tp + 2 * th,
center - tw, tp + 2 * th]
hours3_tic []f32 = [f32(center - tw), tp, center + tw, tp, center + tw, tp, center + tw, tp + 3 * th,
center - tw, tp + 3 * th]
 
hour_hand []f32 = [f32(329), 161, 350, 140, 371, 161, 371, 413, 329, 413]
minute_hand []f32 = [f32(334.25), 40.25, 350, 24.5, 365.75, 40.25, 365.75, 427, 334.25, 427]
second_hand []f32 = [f32(345.8), 38.5, 350, 34.3, 354.2000, 38.5, 358.75, 427, 341.25, 427]
mut:
gg &gg.Context = unsafe { nil }
draw_flag bool = true
dpi_scale f32 = 1.0
}
 
fn on_frame(mut app App) {
if !app.draw_flag {
return
}
app.gg.begin()
 
for i in 0 .. 60 { // draw minute tics
draw_convex_poly_rotate(mut app.gg, app.dpi_scale, app.minutes_tic, tic_color,
i * 6)
}
for i in 0 .. 12 { // hours
draw_convex_poly_rotate(mut app.gg, app.dpi_scale, app.hours_tic, tic_color, i * 30)
}
for i in 0 .. 4 { // 3 hours
draw_convex_poly_rotate(mut app.gg, app.dpi_scale, app.hours3_tic, tic_color,
i * 90)
}
 
n := time.now()
 
// draw hour hand
i := f32(n.hour) + f32(n.minute) / 60.0
draw_convex_poly_rotate(mut app.gg, app.dpi_scale, app.hour_hand, hand_color, i * 30)
 
// draw minute hand
mut j := f32(n.minute)
if n.second == 59 { // make minute hand move smoothly
j += f32(math.sin(f32(n.microsecond) / 1e6 * math.pi / 2.0))
}
draw_convex_poly_rotate(mut app.gg, app.dpi_scale, app.minute_hand, hand_color, j * 6)
 
// draw second hand with smooth transition
k := f32(n.second) + f32(math.sin(f32(n.microsecond) / 1e6 * math.pi / 2.0))
draw_convex_poly_rotate(mut app.gg, app.dpi_scale, app.second_hand, second_hand_color,
0 + k * 6)
 
app.gg.end()
}
 
// Rotate a polygon round the centerpoint
[manualfree]
fn draw_convex_poly_rotate(mut ctx gg.Context, dpi_scale f32, points []f32, c gx.Color, angle f32) {
sa := math.sin(math.pi * angle / 180.0)
ca := math.cos(math.pi * angle / 180.0)
 
mut rotated_points := []f32{cap: points.len}
for i := 0; i < points.len / 2; i++ {
x := points[2 * i]
y := points[2 * i + 1]
xn := f32((x - center) * ca - (y - center) * sa)
yn := f32((x - center) * sa + (y - center) * ca)
rotated_points << (xn + center) * dpi_scale
rotated_points << (yn + center) * dpi_scale
}
ctx.draw_convex_poly(rotated_points, c)
unsafe { rotated_points.free() }
}
 
fn (mut app App) resize() {
size := gg.window_size()
// avoid calls when minimized
if size.width < 2 && size.height < 2 {
return
}
w := f32(size.width) / design_size
h := f32(size.height) / design_size
app.dpi_scale = if w < h { w } else { h }
}
 
fn on_event(e &gg.Event, mut app App) {
match e.typ {
.resized, .resumed {
app.resize()
}
.iconified {
app.draw_flag = false
}
.restored {
app.draw_flag = true
app.resize()
}
else {
if e.typ == .key_down {
match e.key_code {
.q {
println('Good bye.')
// do we need to free anything here?
app.gg.quit()
}
else {}
}
}
}
}
}
 
fn on_init(mut app App) {
app.resize()
}
 
fn main() {
println("Press 'q' to quit.")
mut font_path := os.resource_abs_path(os.join_path('..', 'assets', 'fonts', 'RobotoMono-Regular.ttf'))
$if android {
font_path = 'fonts/RobotoMono-Regular.ttf'
}
 
mut app := &App{}
 
app.gg = gg.new_context(
width: design_size
height: design_size
window_title: 'Clock!'
bg_color: gx.white
user_data: app
frame_fn: on_frame
event_fn: on_event
init_fn: on_init
font_path: font_path
)
 
app.gg.run()
}
</syntaxhighlight>
 
=={{header|Wren}}==
{{trans|Kotlin}}
{{libheader|DOME}}
<syntaxhighlight lang="wren">import "graphics" for Canvas, Color
import "dome" for Window
import "math" for Math
 
var Degrees06 = Num.pi / 30
var Degrees30 = Degrees06 * 5
var Degrees90 = Degrees30 * 3
 
class Clock {
construct new(hour, minute, second) {
Window.title = "Clock"
_size = 590
Window.resize(_size, _size)
Canvas.resize(_size, _size)
_spacing = 40
_diameter = _size - 2 * _spacing
_cx = (_diameter / 2).floor + _spacing
_cy = _cx
_hour = hour
_minute = minute
_second = second
}
 
drawFace() {
var radius = (_diameter / 2).floor
Canvas.circlefill(_cx, _cy, radius, Color.yellow)
Canvas.circle(_cx, _cy, radius, Color.black)
}
 
drawHand(angle, radius, color) {
var x = _cx + (radius * Math.cos(angle)).truncate
var y = _cy - (radius * Math.sin(angle)).truncate
Canvas.line(_cx, _cy, x, y, color, 2)
}
 
drawClock() {
Canvas.cls(Color.white)
drawFace()
var angle = Degrees90 - Degrees06 * _second
drawHand(angle, (_diameter/2).floor - 30, Color.red)
var minsecs = _minute + _second/60
angle = Degrees90 - Degrees06 * minsecs
drawHand(angle, (_diameter / 3).floor + 10, Color.black)
var hourmins = _hour + minsecs / 60
angle = Degrees90 - Degrees30 * hourmins
drawHand(angle, (_diameter / 4).floor + 10, Color.black)
}
 
init() {
_frame = 0
drawClock()
}
 
update() {
_frame = _frame + 1
if (_frame == 60) {
_frame = 0
_second = _second + 1
if (_second == 60) {
_minute = _minute + 1
_second = 0
if (_minute == 60) {
_hour = _hour + 1
_minute = 0
if (_hour == 24) _hour = 0
}
}
}
}
 
draw(alpha) {
drawClock()
}
}
 
var Game = Clock.new(0, 0, 0) // start at midnight</syntaxhighlight>
 
=={{header|XPL0}}==
[[File:XPL0_Clock.gif|thumb]]
<syntaxhighlight lang "XPL0">
include xpllib; \for DrawCircle, DrawLine, LineWidth, MovePen, Deg2Rad
def X0=400, Y0=300; \center coordinate
int Hour, Minute, Second;
 
proc DrawHand(Angle, Length, Width, Color);
real Angle, Length;
int Width, Color;
int X, Y;
[X:= fix(Length*Sin(Angle));
Y:= fix(Length*Cos(Angle));
LineWidth:= Width;
MovePen(X0, Y0);
DrawLine(X0+X, Y0-Y, Color);
];
 
proc DrawClock; \Show analog clock with current time
real Angle;
int N, X, Y;
[DrawCircle(X0, Y0, 299, LCyan, true);
Angle:= 0.;
for N:= 0 to 59 do \draw tick marks
[X:= fix(260.*Cos(Angle));
Y:= fix(260.*Sin(Angle));
DrawCircle(X+X0, Y+Y0, if rem(N/5) then 4 else 8, Black, true);
Angle:= Angle + 6.*Deg2Rad;
];
Angle:= float((Hour*60+Minute)/2) * Deg2Rad;
DrawHand(Angle, 210., 8, Black);
Angle:= float((Minute*60+Second)/10) * Deg2Rad;
DrawHand(Angle, 240., 5, Black);
Angle:= float(Second*6) * Deg2Rad;
DrawHand(Angle, 260., 3, LRed);
DrawCircle(X0, Y0, 8, Black, true);
];
 
int Second0;
char Time;
[SetVid($103); \800x600x8
InitDraw;
repeat Time:= GetDateTime;
Hour:= Time(3);
if Hour>=12 then Hour:= Hour-12;
Minute:= Time(4);
Second:= Time(5);
if Second # Second0 then
[Second0:= Second; DrawClock];
until KeyHit;
]</syntaxhighlight>
 
=={{header|Yabasic}}==
===digital clock===
<lang Yabasic>clear screen
<syntaxhighlight lang="yabasic">clear screen
open window 300,100
backcolor 0, 0, 0
Line 4,669 ⟶ 6,806:
until(upper$(inkey$(.01))="ESC")
exit
end if</langsyntaxhighlight>
 
===graphical analog clock===
<syntaxhighlight lang="yabasic">
#!/usr/bin/yabasic
REM yaclock
DEG_PER_RAD = 57.257751
 
winx = 480
winy = 480
 
radius = min(winx,winy) / 2 - 1
hx = (winx/2) - 1
hy = (winy/2) - 1
 
REM length of the hands (90% of the radius of the clock face)
shand = int(radius * .9)
mhand = int(radius * .9)
hhand = int(radius * .5)
 
REM drop coords by one since graphics are 0 based
 
winx = winx - 1
winy = winy - 1
 
clear screen
 
open window winx,winy
 
clockface()
 
do
 
hour = val(mid$(time$,1,2))
mins = val(mid$(time$,4,2))
sec = val(mid$(time$,7,2))
updatehand("sec")
updatehand("mins")
updatehand("hour")
 
pause .25
 
loop
 
sub updatehand(hand$)
switch(hand$)
case "sec"
h_len = shand
angle = sec * 6
width = 6
color 255,0,0
ox = osx
oy = osy
oxm1 = osxm1
oxm2 = osxm2
oym1 = osym1
oym2 = osym2
break
case "mins"
h_len = mhand
angle = mins * 6 + int(sec/10)
width = 12
color 0,255,0
ox = omx
oy = omy
oxm1 = omxm1
oxm2 = omxm2
oym1 = omym1
oym2 = omym2
break
case "hour"
h_len = hhand
angle = ((hour * 30) + (minutes / 12) * 6) + int(mins/2)
width = 15
color 0,0,255
ox = ohx
oy = ohy
oxm1 = ohxm1
oxm2 = ohxm2
oym1 = ohym1
oym2 = ohym2
break
end switch
 
h_angle1 = angle - width
if h_angle1 < 0 then
h_angle1 = h_angle1 + 360
endif
h_angle1 = h_angle1 / DEG_PER_RAD
h_angle2 = angle + width
if h_angle2 > 360 then
h_angle2 = h_angle2 - 360
endif
h_angle2 = h_angle2 / DEG_PER_RAD
angle = angle / DEG_PER_RAD
x = (hx + (sin(angle) * h_len))
xm1 = (hx + (sin(h_angle1) * int(h_len * .2)))
xm2 = (hx + (sin(h_angle2) * int(h_len * .2)))
 
y = (hy - (cos(angle) * h_len))
ym1 = (hy - (cos(h_angle1) * int(h_len * .2)))
ym2 = (hy - (cos(h_angle2) * int(h_len * .2)))
 
clear line hx,hy,oxm1,oym1
clear line hx,hy,oxm2,oym2
clear line oxm1,oym1,ox,oy
clear line oxm2,oym2,ox,oy
line hx,hy,xm1,ym1
line hx,hy,xm2,ym2
line xm1,ym1,x,y
line xm2,ym2,x,y
REM save off the old vals
switch(hand$)
case "sec"
osx = x
osy = y
osxm1 = xm1
osxm2 = xm2
osym1 = ym1
osym2 = ym2
break
case "mins"
omx = x
omy = y
omxm1 = xm1
omxm2 = xm2
omym1 = ym1
omym2 = ym2
break
case "hour"
ohx = x
ohy = y
ohxm1 = xm1
ohxm2 = xm2
ohym1 = ym1
ohym2 = ym2
break
end switch
end sub
 
sub clockface()
circle hx,hy,radius
htick = radius / 10
mtick = htick / 2
for z=0 to 360 step 6
REM Begin at zero deg and stop before 360 deg
 
REM draw the hour markers
angle = z
angle = angle / DEG_PER_RAD
x2 = (hx + (sin(angle) * radius))
y2 = (hy - (cos(angle) * radius))
if mod(z,30) = 0 then
tick = htick
else
tick = mtick
endif
x3 = (hx + (sin(angle) * (radius - tick)))
y3 = (hy - (cos(angle) * (radius - tick)))
color 255,0,0
line x2,y2,x3,y3
color 0,0,0
next z
end sub
 
</syntaxhighlight>
 
=={{header|zkl}}==
{{trans|Nim}}
<langsyntaxhighlight lang="zkl">var
t=T("⡎⢉⢵","⠀⢺⠀","⠊⠉⡱","⠊⣉⡱","⢀⠔⡇","⣏⣉⡉","⣎⣉⡁","⠊⢉⠝","⢎⣉⡱","⡎⠉⢱","⠀⠶⠀"),
b=T("⢗⣁⡸","⢀⣸⣀","⣔⣉⣀","⢄⣀⡸","⠉⠉⡏","⢄⣀⡸","⢇⣀⡸","⢰⠁⠀","⢇⣀⡸","⢈⣉⡹","⠀⠶ ");
Line 4,682 ⟶ 6,992:
println(x.pump(String,t.get),"\n",x.pump(String,b.get));
Atomic.sleep(1);
}</langsyntaxhighlight>
{{out}}
<pre>
Line 4,688 ⟶ 6,998:
⣔⣉⣀⢄⣀⡸⠀⠶ ⠉⠉⡏⢄⣀⡸⠀⠶ ⢄⣀⡸⣔⣉⣀
</pre>
 
=={{header|ZX Spectrum Basic}}==
Chapter 18 of the BASIC manual supplied with the ZX Spectrum includes two programs to implement a clock - each uses different timing methods. The first - using a PAUSE command to hold for a second - is far less accurate, while the second - reading the three-byte system frames counter - is more CPU hungry (since ZX Spectrum Basic can't multitask, this doesn't really matter). With a tweak, the second is shown below.
<langsyntaxhighlight lang="zxbasic">10 REM First we draw the clock face
20 FOR n=1 TO 12
30 PRINT AT 10-10*COS (n/6*PI),16+10*SIN (n/6*PI);n
Line 4,703 ⟶ 7,014:
210 IF INT t<=INT t1 THEN GO TO 200: REM wait for time for next hand; the INTs were not in the original but force it to wait for the next second
220 PLOT 131,91: DRAW OVER 1;sx,sy: REM rub out old hand
230 LET t1=t: GO TO 120</langsyntaxhighlight>
 
{{omit from|ACL2|No access to system time}}