Draw a clock: Difference between revisions

Content added Content deleted
m (syntax highlighting fixup automation)
Line 21: Line 21:


=={{header|ActionScript}}==
=={{header|ActionScript}}==
<syntaxhighlight lang="actionscript">
<lang ActionScript>
package {
package {
Line 160: Line 160:


}
}
</syntaxhighlight>
</lang>


=={{header|Ada}}==
=={{header|Ada}}==
{{libheader|SDLAda}}
{{libheader|SDLAda}}
<lang Ada>with Ada.Numerics.Elementary_Functions;
<syntaxhighlight lang="ada">with Ada.Numerics.Elementary_Functions;
with Ada.Calendar.Formatting;
with Ada.Calendar.Formatting;
with Ada.Calendar.Time_Zones;
with Ada.Calendar.Time_Zones;
Line 262: Line 262:
Window.Finalize;
Window.Finalize;
SDL.Finalise;
SDL.Finalise;
end Draw_A_Clock;</lang>
end Draw_A_Clock;</syntaxhighlight>


=={{header|AutoHotkey}}==
=={{header|AutoHotkey}}==
Line 268: Line 268:
this code from http://www.autohotkey.com/forum/viewtopic.php?p=231836#231836
this code from http://www.autohotkey.com/forum/viewtopic.php?p=231836#231836
draws a very nice clock with GDI+
draws a very nice clock with GDI+
<lang AHK>; gdi+ ahk analogue clock example written by derRaphael
<syntaxhighlight lang="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
; Parts based on examples from Tic's GDI+ Tutorials and of course on his GDIP.ahk


Line 412: Line 412:
Gdip_Shutdown(pToken)
Gdip_Shutdown(pToken)
ExitApp
ExitApp
Return</lang>
Return</syntaxhighlight>


=={{header|AWK}}==
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f DRAW_A_CLOCK.AWK [-v xc="*"]
# syntax: GAWK -f DRAW_A_CLOCK.AWK [-v xc="*"]
BEGIN {
BEGIN {
Line 466: Line 466:
}
}
}
}
</syntaxhighlight>
</lang>
{{out|Sample run and output}}
{{out|Sample run and output}}
<pre>
<pre>
Line 485: Line 485:
==={{header|AmigaBASIC}}===
==={{header|AmigaBASIC}}===


<lang amigabasic>xp=320:yp=95:size=150
<syntaxhighlight lang="amigabasic">xp=320:yp=95:size=150
CIRCLE (xp,yp),size,,,,.5
CIRCLE (xp,yp),size,,,,.5
lasth=0:lastm=0:lasts=0
lasth=0:lastm=0:lasts=0
Line 516: Line 516:
LINE (xp,yp)-(xp+2*ms*SIN(lastm),yp-ms*COS(lastm)),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
LINE (xp,yp)-(xp+2*ss*SIN(lasts),yp-ss*COS(lasts)),2
RETURN</lang>
RETURN</syntaxhighlight>


==={{header|BaCon}}===
==={{header|BaCon}}===
Using GTK3 as a graphical toolkit.
Using GTK3 as a graphical toolkit.
<lang bacon>OPTION GUI TRUE
<syntaxhighlight lang="bacon">OPTION GUI TRUE
PRAGMA GUI gtk3
PRAGMA GUI gtk3


Line 594: Line 594:


ENDSUB
ENDSUB
</syntaxhighlight>
</lang>


==={{header|BBC BASIC}}===
==={{header|BBC BASIC}}===
<lang bbcbasic>
<syntaxhighlight lang="bbcbasic">
CLS
CLS
xp=320:yp=160:size=150
xp=320:yp=160:size=150
Line 634: Line 634:
LINE xp, yp, xp+2*ss*SIN(lasts), yp+ss*COS(lasts)
LINE xp, yp, xp+2*ss*SIN(lasts), yp+ss*COS(lasts)
ENDPROC
ENDPROC
</syntaxhighlight>
</lang>




==={{header|Commodore BASIC}}===
==={{header|Commodore BASIC}}===
To be entered in upper/lowercase mode but run in uppercase + graphics mode.
To be entered in upper/lowercase mode but run in uppercase + graphics mode.
<lang commodorebasic>10 gosub 1500: rem setup clock digit strings
<syntaxhighlight lang="commodorebasic">10 gosub 1500: rem setup clock digit strings
20 ti$ = "123456"
20 ti$ = "123456"
25 rem do some other stuff after this line
25 rem do some other stuff after this line
Line 670: Line 670:
1540 z$(4) = "B B B B B B BB BB B B"
1540 z$(4) = "B B B B B B BB BB B B"
1550 z$(5) = "JCKCCCJCCCCK BCCKJCKJCK CK"
1550 z$(5) = "JCKCCCJCCCCK BCCKJCKJCK CK"
1560 return</lang>
1560 return</syntaxhighlight>


==={{header|IS-BASIC}}===
==={{header|IS-BASIC}}===
<lang IS-BASIC>100 PROGRAM "Clock.bas"
<syntaxhighlight lang="is-basic">100 PROGRAM "Clock.bas"
110 OPTION ANGLE DEGREES
110 OPTION ANGLE DEGREES
120 LET CH=1:LET CH2=2
120 LET CH=1:LET CH2=2
Line 693: Line 693:
290 CLOSE #2
290 CLOSE #2
300 CLOSE #1
300 CLOSE #1
310 TEXT</lang>
310 TEXT</syntaxhighlight>


=={{header|Batch File}}==
=={{header|Batch File}}==
<lang dos>::Draw a Clock Task from Rosetta Code Wiki
<syntaxhighlight lang="dos">::Draw a Clock Task from Rosetta Code Wiki
::Batch File Implementation
::Batch File Implementation
::
::
Line 802: Line 802:
echo.
echo.
timeout /t 1 /nobreak >nul
timeout /t 1 /nobreak >nul
goto :clock_loop</lang>
goto :clock_loop</syntaxhighlight>
{{Out}}
{{Out}}
<pre>
<pre>
Line 814: Line 814:
=={{header|C}}==
=={{header|C}}==
Draws a crude clock in terminal. C99, compiled with <code>gcc -std=c99</code>.
Draws a crude clock in terminal. C99, compiled with <code>gcc -std=c99</code>.
<lang C>#include <stdio.h>
<syntaxhighlight lang="c">#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <math.h>
#include <math.h>
Line 906: Line 906:
draw(s);
draw(s);
return 0;
return 0;
}</lang>
}</syntaxhighlight>
===Clock in xlib (for X windows)===
===Clock in xlib (for X windows)===
<lang C>// clockrosetta.c - https://rosettacode.org/wiki/Draw_a_clock
<syntaxhighlight lang="c">// clockrosetta.c - https://rosettacode.org/wiki/Draw_a_clock


// # Makefile
// # Makefile
Line 1,121: Line 1,121:
}
}


// END</lang>
// END</syntaxhighlight>


=={{header|C sharp|C#}}==
=={{header|C sharp|C#}}==
<lang csharp>using System;
<syntaxhighlight lang="csharp">using System;
using System.Drawing;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Drawing2D;
Line 1,210: Line 1,210:
Application.Run(new Clock());
Application.Run(new Clock());
}
}
}</lang>
}</syntaxhighlight>


=={{header|C++}}==
=={{header|C++}}==
[[File:clock_cpp.png]]
[[File:clock_cpp.png]]
<lang cpp>
<syntaxhighlight lang="cpp">
#include <windows.h>
#include <windows.h>
#include <string>
#include <string>
Line 1,545: Line 1,545:
}
}
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
</syntaxhighlight>
</lang>


=={{header|ContextFree}}==
=={{header|ContextFree}}==
<lang>
<syntaxhighlight lang="text">
startshape START
startshape START


Line 1,564: Line 1,564:
}
}


</syntaxhighlight>
</lang>


=={{header|Delphi}}==
=={{header|Delphi}}==
Line 1,576: Line 1,576:
Form application
Form application


<syntaxhighlight lang="delphi">
<lang Delphi>
unit main;
unit main;


Line 1,767: Line 1,767:
end.
end.


</syntaxhighlight>
</lang>


Resources:
Resources:
<syntaxhighlight lang="delphi">
<lang Delphi>
object Clock: TClock
object Clock: TClock
Left = 0
Left = 0
Line 1,795: Line 1,795:
end
end
end
end
</syntaxhighlight>
</lang>




Line 1,805: Line 1,805:
[https://easylang.online/apps/clock.html Run it]
[https://easylang.online/apps/clock.html Run it]


<lang># Clock
<syntaxhighlight lang="text"># Clock
#
#
func draw hour min sec . .
func draw hour min sec . .
Line 1,857: Line 1,857:
timer 0.1
timer 0.1
.
.
timer 0</lang>
timer 0</syntaxhighlight>


=={{header|F_Sharp|F#}}==
=={{header|F_Sharp|F#}}==
<lang fsharp>open System.Text.RegularExpressions
<syntaxhighlight lang="fsharp">open System.Text.RegularExpressions


let numberTemplate = """
let numberTemplate = """
Line 1,902: Line 1,902:
System.Console.ReadLine() |> ignore // Until return is hit
System.Console.ReadLine() |> ignore // Until return is hit
showTime ()
showTime ()
0</lang>
0</syntaxhighlight>
{{out}}
{{out}}
<pre> _ _ _ _ __
<pre> _ _ _ _ __
Line 1,915: Line 1,915:
3. Assumes a 16 bit CPU.<BR>
3. Assumes a 16 bit CPU.<BR>
4. Assumes big-endian memory organization.<BR>
4. Assumes big-endian memory organization.<BR>
<syntaxhighlight lang="forth">
<lang Forth>
HEX
HEX
8379 CONSTANT TICKER \ address of 1/60 second counter
8379 CONSTANT TICKER \ address of 1/60 second counter
Line 1,979: Line 1,979:
?TERMINAL
?TERMINAL
UNTIL
UNTIL
2DROP ;</lang>
2DROP ;</syntaxhighlight>


=={{header|Fortran}}==
=={{header|Fortran}}==
Line 1,985: Line 1,985:
Uses system commands to clear the screen, sleep and obtain time
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)
!Digital Text implemented as in C version - Anant Dixit (Oct, 2014)
program clock
program clock
Line 2,102: Line 2,102:


end subroutine
end subroutine
</syntaxhighlight>
</lang>


Preview:
Preview:
Line 2,120: Line 2,120:


=={{header|FreeBASIC}}==
=={{header|FreeBASIC}}==
<lang freebasic>' version 05-04-2017
<syntaxhighlight lang="freebasic">' version 05-04-2017
' compile with: fbc -s gui
' compile with: fbc -s gui


Line 2,202: Line 2,202:
ImageDestroy(clockdial)
ImageDestroy(clockdial)


End</lang>
End</syntaxhighlight>


=={{header|FunL}}==
=={{header|FunL}}==


<lang funl>import concurrent.{scheduleAtFixedRate, scheduler}
<syntaxhighlight lang="funl">import concurrent.{scheduleAtFixedRate, scheduler}


val ROW = 10
val ROW = 10
Line 2,272: Line 2,272:


if not $os.startsWith( 'Windows' )
if not $os.startsWith( 'Windows' )
print( '\u001B[?25h' )</lang>
print( '\u001B[?25h' )</syntaxhighlight>


{{out}}
{{out}}
Line 2,282: Line 2,282:


=={{header|Go}}==
=={{header|Go}}==
<lang go>package main
<syntaxhighlight lang="go">package main


import (
import (
Line 2,369: Line 2,369:
y := float64(radius) * math.Sin(theta)
y := float64(radius) * math.Sin(theta)
return int(x) + 256, int(y) + 256
return int(x) + 256, int(y) + 256
}</lang>
}</syntaxhighlight>
The following html file, 'clock.html', should be in the same folder as the wsclock binary.
The following html file, 'clock.html', should be in the same folder as the wsclock binary.
<lang html><!DOCTYPE html>
<syntaxhighlight lang="html"><!DOCTYPE html>
<meta charset="utf-8" />
<meta charset="utf-8" />
<title>Clock</title>
<title>Clock</title>
Line 2,471: Line 2,471:
</body>
</body>
</html></lang>
</html></syntaxhighlight>


=={{header|GUISS}}==
=={{header|GUISS}}==


<lang guiss>Start,Programs,Accessories,Analogue Clock</lang> =={{header|GUISS}}==
<syntaxhighlight lang="guiss">Start,Programs,Accessories,Analogue Clock</syntaxhighlight> =={{header|GUISS}}==


<lang guiss>Start,Programs,Accessories,Analogue Clock</lang>
<syntaxhighlight lang="guiss">Start,Programs,Accessories,Analogue Clock</syntaxhighlight>


=={{header|Haskell}}==
=={{header|Haskell}}==
{{libheader|ansi-terminal}}
{{libheader|ansi-terminal}}
<lang Haskell>import Control.Concurrent
<syntaxhighlight lang="haskell">import Control.Concurrent
import Data.List
import Data.List
import System.Time
import System.Time
Line 2,594: Line 2,594:
setCursorColumn 0
setCursorColumn 0
cursorUp 5
cursorUp 5
main</lang>
main</syntaxhighlight>
Output:<pre> ██ ██████ ██████ ██████ ██████ ██████
Output:<pre> ██ ██████ ██████ ██████ ██████ ██████
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
Line 2,608: Line 2,608:
1. Clock using conventional Graphics
1. Clock using conventional Graphics


<lang icon>
<syntaxhighlight lang="icon">
link graphics
link graphics


Line 2,722: Line 2,722:
end
end


</syntaxhighlight>
</lang>


2. Clock using Turtle Graphics
2. Clock using Turtle Graphics
<lang icon>
<syntaxhighlight lang="icon">
link graphics, turtle
link graphics, turtle


Line 2,907: Line 2,907:
draw("r", xsize/2 * 0.25, 8 * xsize / 800, ws - 180)
draw("r", xsize/2 * 0.25, 8 * xsize / 800, ws - 180)
end
end
</syntaxhighlight>
</lang>


=={{header|J}}==
=={{header|J}}==
Graphical clock (tested on jqt -- j903):
Graphical clock (tested on jqt -- j903):


<syntaxhighlight lang="j">{{
<lang J>{{
require'gl2'
require'gl2'
coinsert 'jgl2'
coinsert 'jgl2'
Line 2,945: Line 2,945:
pshow;
pshow;
}}
}}
}}1</lang>
}}1</syntaxhighlight>


Some alternatives:
Some alternatives:


<syntaxhighlight lang="j">
<lang J>
Note'rudimentary 4 second clock'
Note'rudimentary 4 second clock'
advances an arrow at roughly 1 second intervals,
advances an arrow at roughly 1 second intervals,
Line 2,970: Line 2,970:


tic=: (>. draw Pass_y <.) ([: seconds 0 $ delay@1:)
tic=: (>. draw Pass_y <.) ([: seconds 0 $ delay@1:)
</syntaxhighlight>
</lang>
The result of 3.18... is the session time at which the example began.
The result of 3.18... is the session time at which the example began.
<pre>
<pre>
Line 2,987: Line 2,987:
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 (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):


<lang J>require'plot'
<syntaxhighlight lang="j">require'plot'
N=:0.01*i.629
N=:0.01*i.629
O=: [: j./ 1 2 o./ ]
O=: [: j./ 1 2 o./ ]
Line 2,993: Line 2,993:
delay=:6!:3 NB. "sleep"
delay=:6!:3 NB. "sleep"
clock=: [: plot (O N),N*/~0.07 0.11 0.15(*O) 2r24p1 2r60p1 2r60p1*_3{.6!:0 bind ''
clock=: [: plot (O N),N*/~0.07 0.11 0.15(*O) 2r24p1 2r60p1 2r60p1*_3{.6!:0 bind ''
delay@1:@clock^:9e99''</lang>
delay@1:@clock^:9e99''</syntaxhighlight>


=={{header|Java}}==
=={{header|Java}}==
{{works with|Java|8}}
{{works with|Java|8}}
<lang java>import java.awt.*;
<syntaxhighlight lang="java">import java.awt.*;
import java.awt.event.*;
import java.awt.event.*;
import static java.lang.Math.*;
import static java.lang.Math.*;
Line 3,077: Line 3,077:
});
});
}
}
}</lang>
}</syntaxhighlight>


=={{header|JavaScript}}==
=={{header|JavaScript}}==
Tested on Gecko. Put the following in a &lt;script> tag somewhere, and call <code>init_clock()</code> after body load.
Tested on Gecko. Put the following in a &lt;script> tag somewhere, and call <code>init_clock()</code> after body load.
<lang JavaScript>var sec_old = 0;
<syntaxhighlight lang="javascript">var sec_old = 0;
function update_clock() {
function update_clock() {
var t = new Date();
var t = new Date();
Line 3,127: Line 3,127:


window.setInterval(update_clock, 200);
window.setInterval(update_clock, 200);
}</lang>
}</syntaxhighlight>


=== digital ===
=== digital ===
<lang javascript><!DOCTYPE html>
<syntaxhighlight lang="javascript"><!DOCTYPE html>
<html lang="en">
<html lang="en">
<head>
<head>
Line 3,262: Line 3,262:


</body>
</body>
</html></lang>
</html></syntaxhighlight>


=={{header|Julia}}==
=={{header|Julia}}==
<lang julia>
<syntaxhighlight lang="julia">
using Gtk, Colors, Graphics, Dates
using Gtk, Colors, Graphics, Dates


Line 3,349: Line 3,349:
sleep(1.0)
sleep(1.0)
end
end
</syntaxhighlight>
</lang>


=={{header|Kotlin}}==
=={{header|Kotlin}}==
{{trans|Java}}
{{trans|Java}}
<lang scala>// version 1.1
<syntaxhighlight lang="scala">// version 1.1


import java.awt.*
import java.awt.*
Line 3,423: Line 3,423:
f.isVisible = true
f.isVisible = true
}
}
}</lang>
}</syntaxhighlight>


=={{header|Lambdatalk}}==
=={{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
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


<lang scheme>
<syntaxhighlight lang="scheme">
1) lambdatalk code
1) lambdatalk code
{watch} // displays the watch
{watch} // displays the watch
Line 3,501: Line 3,501:
};
};
}
}
</syntaxhighlight>
</lang>


=={{header|Liberty BASIC}}==
=={{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.
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
WindowWidth =120
WindowHeight =144
WindowHeight =144
Line 3,545: Line 3,545:


end
end
</syntaxhighlight>
</lang>


=={{header|Locomotive Basic}}==
=={{header|Locomotive Basic}}==
Line 3,551: Line 3,551:
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.
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.


<lang locobasic>10 mode 1:defint a-y:deg
<syntaxhighlight lang="locobasic">10 mode 1:defint a-y:deg
20 input "Current time (HH:MM)";t$
20 input "Current time (HH:MM)";t$
30 h=val(mid$(t$,1,2))
30 h=val(mid$(t$,1,2))
Line 3,596: Line 3,596:
440 if a>0 then frame:move 0,0:draw .8*r*sin(a-6),.8*r*cos(a-6),3,1
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
450 frame:move 0,0:draw .8*r*sin(a),.8*r*cos(a),3,1
460 return</lang>
460 return</syntaxhighlight>


=={{header|Lua}}==
=={{header|Lua}}==
Line 3,603: Line 3,603:


=={{header|Mathematica}} / {{header|Wolfram Language}}==
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<lang Mathematica>Dynamic[ClockGauge[], UpdateInterval -> 1]</lang>
<syntaxhighlight lang="mathematica">Dynamic[ClockGauge[], UpdateInterval -> 1]</syntaxhighlight>


=={{header|MATLAB}} / {{header|Octave}}==
=={{header|MATLAB}} / {{header|Octave}}==


<lang Matlab> u = [0:360]*pi/180;
<syntaxhighlight lang="matlab"> u = [0:360]*pi/180;
while(1)
while(1)
s = mod(now*60*24,1)*2*pi;
s = mod(now*60*24,1)*2*pi;
plot([0,sin(s)],[0,cos(s)],'-',sin(u),cos(u),'k-');
plot([0,sin(s)],[0,cos(s)],'-',sin(u),cos(u),'k-');
pause(1);
pause(1);
end;</lang>
end;</syntaxhighlight>


=={{header|MiniScript}}==
=={{header|MiniScript}}==
Line 3,618: Line 3,618:
This solution works with [https://miniscript.org/MiniMicro Mini Micro], and uses its default SpriteDisplay.
This solution works with [https://miniscript.org/MiniMicro Mini Micro], and uses its default SpriteDisplay.


<lang MiniScript>// draw a clock hand, then copy it to an image
<syntaxhighlight lang="miniscript">// draw a clock hand, then copy it to an image
gfx.clear color.clear
gfx.clear color.clear
gfx.fillPoly [[60,5], [64,10], [128,5], [64,0]], color.yellow
gfx.fillPoly [[60,5], [64,10], [128,5], [64,0]], color.yellow
Line 3,643: Line 3,643:
hand.rotation = 90 - floor(time) % 60 * 6
hand.rotation = 90 - floor(time) % 60 * 6
wait
wait
end while</lang>
end while</syntaxhighlight>


=={{header|NetRexx}}==
=={{header|NetRexx}}==
{{trans|Java}}
{{trans|Java}}
<lang NetRexx>/* NetRexx */
<syntaxhighlight lang="netrexx">/* NetRexx */
options replace format comments java crossref symbols binary
options replace format comments java crossref symbols binary


Line 3,749: Line 3,749:
repaint()
repaint()
return
return
</syntaxhighlight>
</lang>


=={{header|Nim}}==
=={{header|Nim}}==
==={{header|Text}}===
==={{header|Text}}===
{{trans|Raku}}
{{trans|Raku}}
<lang nim>import times, os
<syntaxhighlight lang="nim">import times, os


const
const
Line 3,767: Line 3,767:
for c in x: stdout.write b[c.ord - '0'.ord]
for c in x: stdout.write b[c.ord - '0'.ord]
echo ""
echo ""
sleep 1000</lang>
sleep 1000</syntaxhighlight>


==={{header|Using SDL}}===
==={{header|Using SDL}}===
{{libheader|SDL2}}
{{libheader|SDL2}}
<lang nim>## needs sdl2 ("nimble install sdl2")
<syntaxhighlight lang="nim">## needs sdl2 ("nimble install sdl2")


import sdl2, times, math
import sdl2, times, math
Line 3,833: Line 3,833:


destroy render
destroy render
destroy window</lang>
destroy window</syntaxhighlight>


=={{header|OCaml}}==
=={{header|OCaml}}==
Line 3,839: Line 3,839:
Using only the standard library of OCaml with its [http://caml.inria.fr/pub/docs/manual-ocaml/libref/Graphics.html Graphics] module:
Using only the standard library of OCaml with its [http://caml.inria.fr/pub/docs/manual-ocaml/libref/Graphics.html Graphics] module:


<lang ocaml>#!/usr/bin/env ocaml
<syntaxhighlight lang="ocaml">#!/usr/bin/env ocaml
#load "unix.cma"
#load "unix.cma"
#load "graphics.cma"
#load "graphics.cma"
Line 3,903: Line 3,903:
in
in
try loop ()
try loop ()
with _ -> close_graph ()</lang>
with _ -> close_graph ()</syntaxhighlight>




Line 3,919: Line 3,919:
unix.cmxa lablgtk.cmxa cairo.cmxa cairo_lablgtk.cmxa gtkInit.cmx gtkclock.ml
unix.cmxa lablgtk.cmxa cairo.cmxa cairo_lablgtk.cmxa gtkInit.cmx gtkclock.ml


<lang ocaml>let pi = 4.0 *. atan 1.0
<syntaxhighlight lang="ocaml">let pi = 4.0 *. atan 1.0
let angle v max = float v /. max *. 2.0 *. pi
let angle v max = float v /. max *. 2.0 *. pi


Line 3,984: Line 3,984:
animate area;
animate area;
w#show ();
w#show ();
GMain.main ()</lang>
GMain.main ()</syntaxhighlight>


=={{header|ooRexx}}==
=={{header|ooRexx}}==
Line 3,991: Line 3,991:
<br>https://www.dropbox.com/sh/h0dycdshv04c5lz/5oHFfI3t14?n=132389230
<br>https://www.dropbox.com/sh/h0dycdshv04c5lz/5oHFfI3t14?n=132389230
<br>It runs nicely on Windows 7 with ooRexx installed.
<br>It runs nicely on Windows 7 with ooRexx installed.
<lang ooRexx>/* REXX ---------------------------------------------------------------
<syntaxhighlight lang="oorexx">/* REXX ---------------------------------------------------------------
* 09.02.2014 Walter Pachl with a little, well considerable, help from
* 09.02.2014 Walter Pachl with a little, well considerable, help from
* a friend (Mark Miesfeld)
* a friend (Mark Miesfeld)
Line 4,269: Line 4,269:
Parse Arg x,y
Parse Arg x,y
If y=0 Then Return '??'
If y=0 Then Return '??'
Else Return x/y</lang>
Else Return x/y</syntaxhighlight>


===version 2 runs under Windows, Linux, and MacOSX===
===version 2 runs under Windows, Linux, and MacOSX===
Line 4,275: Line 4,275:
A screenshot of this clock can be seen on my dropbox (clocka.jpg)
A screenshot of this clock can be seen on my dropbox (clocka.jpg)
<br>https://www.dropbox.com/sh/h0dycdshv04c5lz/5oHFfI3t14?n=132389230
<br>https://www.dropbox.com/sh/h0dycdshv04c5lz/5oHFfI3t14?n=132389230
<lang oorexx>/* REXX ---------------------------------------------------------------
<syntaxhighlight lang="oorexx">/* REXX ---------------------------------------------------------------
Name: clock.rxj
Name: clock.rxj
Purpose: create a graphical clock that shows the current time
Purpose: create a graphical clock that shows the current time
Line 4,417: Line 4,417:
::method actionPerformed -- this event will be caused every second by the swing Timer
::method actionPerformed -- this event will be caused every second by the swing Timer
use arg eventObj, slotDir
use arg eventObj, slotDir
slotDir~userData~repaint -- fetch the Java object and send it the repaint message</lang>
slotDir~userData~repaint -- fetch the Java object and send it the repaint message</syntaxhighlight>
[[out}}
[[out}}
<pre>... [2017-01-26T17:17:51.527000] Rexx main program, now waiting until JFrame gets closed ...
<pre>... [2017-01-26T17:17:51.527000] Rexx main program, now waiting until JFrame gets closed ...
Line 4,424: Line 4,424:
=={{header|Perl}}==
=={{header|Perl}}==
{{trans|Raku}}
{{trans|Raku}}
<lang perl>use utf8; # interpret source code as UTF8
<syntaxhighlight lang="perl">use utf8; # interpret source code as UTF8
binmode STDOUT, ':utf8'; # allow printing wide chars without warning
binmode STDOUT, ':utf8'; # allow printing wide chars without warning
$|++; # disable output buffering
$|++; # disable output buffering
Line 4,452: Line 4,452:


sub clear { print "\e[H\e[J" }
sub clear { print "\e[H\e[J" }
sub position { printf "\e[%d;%dH", shift, shift }</lang>
sub position { printf "\e[%d;%dH", shift, shift }</syntaxhighlight>


{{out}}
{{out}}
Line 4,466: Line 4,466:
Resizeable, appearance similar to Mathematica.
Resizeable, appearance similar to Mathematica.
You can run this online [http://phix.x10.mx/p2js/clock.htm here].
You can run this online [http://phix.x10.mx/p2js/clock.htm here].
<!--<lang Phix>(phixonline)-->
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #000080;font-style:italic;">--
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\Clock.exw
-- demo\rosetta\Clock.exw
Line 4,593: Line 4,593:
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
<!--</lang>-->
<!--</syntaxhighlight>-->
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).
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}}==
=={{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].<lang PicoLisp>(de draw Lst
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].<syntaxhighlight lang="picolisp">(de draw Lst
(for L Lst
(for L Lst
(for X L
(for X L
Line 4,644: Line 4,644:
(bigBox (% (cadr Time) 5))
(bigBox (% (cadr Time) 5))
(draw (+ (10 . -) + (10 . -) + (10 . -) + (10 . -) +)) )
(draw (+ (10 . -) + (10 . -) + (10 . -) + (10 . -) +)) )
(wait 1000) )</lang>The six '#' characters in the "circle" on top toggle on/off every second. This is the display at 17:46
(wait 1000) )</syntaxhighlight>The six '#' characters in the "circle" on top toggle on/off every second. This is the display at 17:46
<pre> _____
<pre> _____
/ \
/ \
Line 4,667: Line 4,667:
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.
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.


<lang java>void draw() {
<syntaxhighlight lang="java">void draw() {
drawClock();
drawClock();
}
}
Line 4,685: Line 4,685:
strokeWeight(4);
strokeWeight(4);
line(0, 0, 0, -width*0.2);
line(0, 0, 0, -width*0.2);
}</lang>
}</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:
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:


<lang java>int lastSec = second();
<syntaxhighlight lang="java">int lastSec = second();
void draw() {
void draw() {
if (lastSec!=second()) {
if (lastSec!=second()) {
Line 4,695: Line 4,695:
lastSec=second();
lastSec=second();
}
}
}</lang>
}</syntaxhighlight>


One of the official Processing language examples is a more graphically detailed [https://processing.org/examples/clock.html Clock example].
One of the official Processing language examples is a more graphically detailed [https://processing.org/examples/clock.html Clock example].


==={{header|Processing Python mode}}===
==={{header|Processing Python mode}}===
<lang python>
<syntaxhighlight lang="python">
last_sec = second()
last_sec = second()


Line 4,723: Line 4,723:
rotate(-m + h)
rotate(-m + h)
strokeWeight(4)
strokeWeight(4)
line(0, 0, 0, -width * 0.2)</lang>
line(0, 0, 0, -width * 0.2)</syntaxhighlight>


=={{header|PureBasic}}==
=={{header|PureBasic}}==
[[File:PureBasic_Clock.png|thumb|Sample display of PureBasic solution]]
[[File:PureBasic_Clock.png|thumb|Sample display of PureBasic solution]]
<lang purebasic>#MiddleX = 90 + 1 ;x,y must be odd numbers, minimum width is 67
<syntaxhighlight lang="purebasic">#MiddleX = 90 + 1 ;x,y must be odd numbers, minimum width is 67
#MiddleY = #MiddleX
#MiddleY = #MiddleX
#len_sh = (#MiddleX - 8) * 0.97 ;length of second-hand
#len_sh = (#MiddleX - 8) * 0.97 ;length of second-hand
Line 4,777: Line 4,777:
SetGadgetState(#clock_gad, ImageID(#clockFace_img))
SetGadgetState(#clock_gad, ImageID(#clockFace_img))
EndIf
EndIf
Until event = #PB_Event_CloseWindow</lang>
Until event = #PB_Event_CloseWindow</syntaxhighlight>


=={{header|Python}}==
=={{header|Python}}==
Line 4,784: Line 4,784:
===Textmode===
===Textmode===


<lang python>import time
<syntaxhighlight lang="python">import time


def chunks(l, n=5):
def chunks(l, n=5):
Line 4,814: Line 4,814:
print bin_bit(y[1])
print bin_bit(y[1])
print
print
print secs(s)</lang>
print secs(s)</syntaxhighlight>


==={{libheader|VPython}}===
==={{libheader|VPython}}===
Line 4,824: Line 4,824:
Draws an analog clock in a new GUI window:
Draws an analog clock in a new GUI window:


<lang racket>
<syntaxhighlight lang="racket">
#lang racket/gui
#lang racket/gui


Line 4,880: Line 4,880:


(send f show #t)
(send f show #t)
</syntaxhighlight>
</lang>


=={{header|Raku}}==
=={{header|Raku}}==
(formerly Perl 6)
(formerly Perl 6)
<lang perl6>my ($rows,$cols) = qx/stty size/.words;
<syntaxhighlight lang="raku" line>my ($rows,$cols) = qx/stty size/.words;
my $v = floor $rows / 2;
my $v = floor $rows / 2;
my $h = floor $cols / 2 - 16;
my $h = floor $cols / 2 - 16;
Line 4,900: Line 4,900:
print "\e[H";
print "\e[H";
sleep 1;
sleep 1;
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>⠀⢺⠀ ⢀⠔⡇ ⠀⠶⠀ ⠊⠉⡱ ⠊⣉⡱ ⠀⠶⠀ ⣏⣉⡉ ⡎⢉⢵
<pre>⠀⢺⠀ ⢀⠔⡇ ⠀⠶⠀ ⠊⠉⡱ ⠊⣉⡱ ⠀⠶⠀ ⣏⣉⡉ ⡎⢉⢵
Line 4,907: Line 4,907:
=={{header|Red}}==
=={{header|Red}}==
===Minimalistic===
===Minimalistic===
<lang Red>Red [Needs: 'View]
<syntaxhighlight lang="red">Red [Needs: 'View]
view [t: h4 rate 1 on-time [t/data: now/time]]
view [t: h4 rate 1 on-time [t/data: now/time]]
</syntaxhighlight>
</lang>
{{out}}
{{out}}
[https://raw.githubusercontent.com/Palaing/redlib/master/games/images/miniclock.png mini clock image]
[https://raw.githubusercontent.com/Palaing/redlib/master/games/images/miniclock.png mini clock image]


===Analog===
===Analog===
<lang Red>Red [
<syntaxhighlight lang="red">Red [
Needs: 'View
Needs: 'View
Purpose: {simple analog clock based on Nenad Rakocevic's eve-clock.red,
Purpose: {simple analog clock based on Nenad Rakocevic's eve-clock.red,
Line 4,931: Line 4,931:
sec/2: 6 * time/second
sec/2: 6 * time/second
]]
]]
</syntaxhighlight>
</lang>
{{out}}
{{out}}
[https://raw.githubusercontent.com/Palaing/redlib/master/games/images/analogclock.png analog clock image]
[https://raw.githubusercontent.com/Palaing/redlib/master/games/images/analogclock.png analog clock image]
Line 4,950: Line 4,950:
:::* &nbsp; '''ROO'''
:::* &nbsp; '''ROO'''
the color of the display can be specified.
the color of the display can be specified.
<lang rexx>/*REXX program displays the current (local) time as a digital clock on the terminal.*/
<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*/
trace off /*turn off tracing/possible host errors*/
parse arg ! /*obtain optional arguments from the CL*/
parse arg ! /*obtain optional arguments from the CL*/
Line 5,027: Line 5,027:
noValue: !sigl= sigl; call er 17,!fid(2) !fid(3) !sigl condition('D') sourceline(!sigl)
noValue: !sigl= sigl; call er 17,!fid(2) !fid(3) !sigl condition('D') sourceline(!sigl)
p: return word( arg(1), 1)
p: return word( arg(1), 1)
syntax: !sigl= sigl; call er 13,!fid(2) !fid(3) !sigl !cal() condition('D') sourceline(!sigl)</lang>
syntax: !sigl= sigl; call er 13,!fid(2) !fid(3) !sigl !cal() condition('D') sourceline(!sigl)</syntaxhighlight>
;Programming notes:
;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.
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.
Line 5,081: Line 5,081:
{{libheader|Shoes}}
{{libheader|Shoes}}
[[File:shoes_clock.png|thumb|Sample display of Ruby solution]]
[[File:shoes_clock.png|thumb|Sample display of Ruby solution]]
<lang ruby>Shoes.app(:width=>205, :height => 228, :title => "A Clock") do
<syntaxhighlight lang="ruby">Shoes.app(:width=>205, :height => 228, :title => "A Clock") do
def draw_ray(width, start, stop, ratio)
def draw_ray(width, start, stop, ratio)
angle = Math::PI * 2 * ratio - Math::PI/2
angle = Math::PI * 2 * ratio - Math::PI/2
Line 5,121: Line 5,121:


animate(5) {update}
animate(5) {update}
end</lang>
end</syntaxhighlight>


Inspired by the PicoLisp solution, here's an implementation of the Berlin-Uhr clock.
Inspired by the PicoLisp solution, here's an implementation of the Berlin-Uhr clock.
[[File:berlin_uhr.rb.png|thumb|Berlin-Uhr clock]]
[[File:berlin_uhr.rb.png|thumb|Berlin-Uhr clock]]
<lang ruby>Shoes.app(:title => "Berlin-Uhr Clock", :width => 209, :height => 300) do
<syntaxhighlight lang="ruby">Shoes.app(:title => "Berlin-Uhr Clock", :width => 209, :height => 300) do
background lightgrey
background lightgrey


Line 5,169: Line 5,169:
end
end
end
end
end</lang>
end</syntaxhighlight>


{{libheader|RubyGems}}
{{libheader|RubyGems}}
{{libheader|JRubyArt}}
{{libheader|JRubyArt}}
JRubyArt is port of processing to ruby
JRubyArt is port of processing to ruby
<lang ruby>
<syntaxhighlight lang="ruby">
def setup
def setup
sketch_title 'Clock'
sketch_title 'Clock'
Line 5,221: Line 5,221:
end
end


</syntaxhighlight>
</lang>


=={{header|Run BASIC}}==
=={{header|Run BASIC}}==
[[File:Rb_clock.png|thumb|Sample display of RB solution]]
[[File:Rb_clock.png|thumb|Sample display of RB solution]]
<lang runbasic>' --------------------------------------------
<syntaxhighlight lang="runbasic">' --------------------------------------------
' clock. I got nothing but time
' clock. I got nothing but time
' ---------------------------------------------
' ---------------------------------------------
Line 5,319: Line 5,319:
#g2 circle(2)
#g2 circle(2)
#g2 line(100,100,px,py)
#g2 line(100,100,px,py)
RETURN</lang>
RETURN</syntaxhighlight>


=={{header|Rust}}==
=={{header|Rust}}==
<lang rust>// cargo-deps: time="0.1"
<syntaxhighlight lang="rust">// cargo-deps: time="0.1"
extern crate time;
extern crate time;


Line 5,350: Line 5,350:
fn clear_screen() {
fn clear_screen() {
println!("{}[H{}[J", 27 as char, 27 as char);
println!("{}[H{}[J", 27 as char, 27 as char);
}</lang>
}</syntaxhighlight>


=={{header|Scala}}==
=={{header|Scala}}==
===Circular ASCII clock===
===Circular ASCII clock===
Generates and prints a simple ASCII clock every second
Generates and prints a simple ASCII clock every second
<lang scala>import java.util.{ Timer, TimerTask }
<syntaxhighlight lang="scala">import java.util.{ Timer, TimerTask }
import java.time.LocalTime
import java.time.LocalTime
import scala.math._
import scala.math._
Line 5,407: Line 5,407:
}
}
(new Timer).schedule(timerTask, 0, 1000)
(new Timer).schedule(timerTask, 0, 1000)
}</lang>
}</syntaxhighlight>
===Berliner Uhr===
===Berliner Uhr===
See [[http://en.wikipedia.org/wiki/Mengenlehreuhr The Berlin set theory clock]]
See [[http://en.wikipedia.org/wiki/Mengenlehreuhr The Berlin set theory clock]]
<lang scala>import java.time.LocalTime
<syntaxhighlight lang="scala">import java.time.LocalTime
import java.awt.{ Color, Graphics }
import java.awt.{ Color, Graphics }


Line 5,459: Line 5,459:
}
}
}
}
}</lang>
}</syntaxhighlight>


=={{header|Scheme}}==
=={{header|Scheme}}==
Line 5,467: Line 5,467:
The program displays an analogue clock with three hands, updating once a second.
The program displays an analogue clock with three hands, updating once a second.


<syntaxhighlight lang="scheme">
<lang Scheme>
(import (scheme base)
(import (scheme base)
(scheme inexact)
(scheme inexact)
Line 5,527: Line 5,527:
(hands canvas))
(hands canvas))
(tk-event-loop tk))
(tk-event-loop tk))
</syntaxhighlight>
</lang>


=={{header|Scratch}}==
=={{header|Scratch}}==
Line 5,536: Line 5,536:
=={{header|Seed7}}==
=={{header|Seed7}}==
The example program clock3.sd7 from the Seed7 package can be used for this task.
The example program clock3.sd7 from the Seed7 package can be used for this task.
<lang seed7>$ include "seed7_05.s7i";
<syntaxhighlight lang="seed7">$ include "seed7_05.s7i";
include "float.s7i";
include "float.s7i";
include "math.s7i";
include "math.s7i";
Line 5,606: Line 5,606:
command := busy_getc(KEYBOARD);
command := busy_getc(KEYBOARD);
end while;
end while;
end func;</lang>
end func;</syntaxhighlight>


=={{header|Sidef}}==
=={{header|Sidef}}==
{{trans|Perl}}
{{trans|Perl}}
<lang ruby>STDOUT.autoflush(true)
<syntaxhighlight lang="ruby">STDOUT.autoflush(true)


var (rows, cols) = `stty size`.nums...
var (rows, cols) = `stty size`.nums...
Line 5,640: Line 5,640:
print position(1, 1)
print position(1, 1)
Sys.sleep(0.1)
Sys.sleep(0.1)
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 5,649: Line 5,649:


=={{header|SVG}}==
=={{header|SVG}}==
<lang svg><svg viewBox="0 0 100 100" width="480px" height="480px" xmlns="http://www.w3.org/2000/svg">
<syntaxhighlight 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" />
<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">
<g transform="translate(50,50) rotate(0)" style="fill:none; stroke-linecap:round">
Line 5,683: Line 5,683:
<circle cx="50" cy="50" r="4" style="fill:gold; stroke:black; stroke-width:1" />
<circle cx="50" cy="50" r="4" style="fill:gold; stroke:black; stroke-width:1" />
</svg>
</svg>
</syntaxhighlight>
</lang>


=={{header|Tcl}}==
=={{header|Tcl}}==
[[File:Clock tcltk.png|thumb|Sample display of Tcl solution]]
[[File:Clock tcltk.png|thumb|Sample display of Tcl solution]]
{{libheader|Tk}}
{{libheader|Tk}}
<lang tcl>package require Tcl 8.5
<syntaxhighlight lang="tcl">package require Tcl 8.5
package require Tk
package require Tk


Line 5,720: Line 5,720:
}
}
}
}
ticker</lang>
ticker</syntaxhighlight>
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.
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}}==
=={{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
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">
<lang vb>
'ANSI Clock
'ANSI Clock


Line 5,797: Line 5,797:
wend
wend
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 5,831: Line 5,831:
{{trans|Kotlin}}
{{trans|Kotlin}}
{{libheader|DOME}}
{{libheader|DOME}}
<lang ecmascript>import "graphics" for Canvas, Color
<syntaxhighlight lang="ecmascript">import "graphics" for Canvas, Color
import "dome" for Window
import "dome" for Window
import "math" for Math
import "math" for Math
Line 5,906: Line 5,906:
}
}


var Game = Clock.new(0, 0, 0) // start at midnight</lang>
var Game = Clock.new(0, 0, 0) // start at midnight</syntaxhighlight>


=={{header|Yabasic}}==
=={{header|Yabasic}}==
<lang Yabasic>clear screen
<syntaxhighlight lang="yabasic">clear screen
open window 300,100
open window 300,100
backcolor 0, 0, 0
backcolor 0, 0, 0
Line 5,942: Line 5,942:
until(upper$(inkey$(.01))="ESC")
until(upper$(inkey$(.01))="ESC")
exit
exit
end if</lang>
end if</syntaxhighlight>


=={{header|zkl}}==
=={{header|zkl}}==
{{trans|Nim}}
{{trans|Nim}}
<lang zkl>var
<syntaxhighlight lang="zkl">var
t=T("⡎⢉⢵","⠀⢺⠀","⠊⠉⡱","⠊⣉⡱","⢀⠔⡇","⣏⣉⡉","⣎⣉⡁","⠊⢉⠝","⢎⣉⡱","⡎⠉⢱","⠀⠶⠀"),
t=T("⡎⢉⢵","⠀⢺⠀","⠊⠉⡱","⠊⣉⡱","⢀⠔⡇","⣏⣉⡉","⣎⣉⡁","⠊⢉⠝","⢎⣉⡱","⡎⠉⢱","⠀⠶⠀"),
b=T("⢗⣁⡸","⢀⣸⣀","⣔⣉⣀","⢄⣀⡸","⠉⠉⡏","⢄⣀⡸","⢇⣀⡸","⢰⠁⠀","⢇⣀⡸","⢈⣉⡹","⠀⠶ ");
b=T("⢗⣁⡸","⢀⣸⣀","⣔⣉⣀","⢄⣀⡸","⠉⠉⡏","⢄⣀⡸","⢇⣀⡸","⢰⠁⠀","⢇⣀⡸","⢈⣉⡹","⠀⠶ ");
Line 5,955: Line 5,955:
println(x.pump(String,t.get),"\n",x.pump(String,b.get));
println(x.pump(String,t.get),"\n",x.pump(String,b.get));
Atomic.sleep(1);
Atomic.sleep(1);
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 5,964: Line 5,964:
=={{header|ZX Spectrum Basic}}==
=={{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.
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.
<lang zxbasic>10 REM First we draw the clock face
<syntaxhighlight lang="zxbasic">10 REM First we draw the clock face
20 FOR n=1 TO 12
20 FOR n=1 TO 12
30 PRINT AT 10-10*COS (n/6*PI),16+10*SIN (n/6*PI);n
30 PRINT AT 10-10*COS (n/6*PI),16+10*SIN (n/6*PI);n
Line 5,977: Line 5,977:
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
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
220 PLOT 131,91: DRAW OVER 1;sx,sy: REM rub out old hand
230 LET t1=t: GO TO 120</lang>
230 LET t1=t: GO TO 120</syntaxhighlight>


{{omit from|ACL2|No access to system time}}
{{omit from|ACL2|No access to system time}}