Draw a clock: Difference between revisions

m
syntax highlighting fixup automation
m (syntax highlighting fixup automation)
Line 21:
 
=={{header|ActionScript}}==
<syntaxhighlight lang="actionscript">
<lang ActionScript>
package {
Line 160:
 
}
</syntaxhighlight>
</lang>
 
=={{header|Ada}}==
{{libheader|SDLAda}}
<langsyntaxhighlight Adalang="ada">with Ada.Numerics.Elementary_Functions;
with Ada.Calendar.Formatting;
with Ada.Calendar.Time_Zones;
Line 262:
Window.Finalize;
SDL.Finalise;
end Draw_A_Clock;</langsyntaxhighlight>
 
=={{header|AutoHotkey}}==
Line 268:
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 412:
Gdip_Shutdown(pToken)
ExitApp
Return</langsyntaxhighlight>
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f DRAW_A_CLOCK.AWK [-v xc="*"]
BEGIN {
Line 466:
}
}
</syntaxhighlight>
</lang>
{{out|Sample run and output}}
<pre>
Line 485:
==={{header|AmigaBASIC}}===
 
<langsyntaxhighlight lang="amigabasic">xp=320:yp=95:size=150
CIRCLE (xp,yp),size,,,,.5
lasth=0:lastm=0:lasts=0
Line 516:
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</langsyntaxhighlight>
 
==={{header|BaCon}}===
Using GTK3 as a graphical toolkit.
<langsyntaxhighlight lang="bacon">OPTION GUI TRUE
PRAGMA GUI gtk3
 
Line 594:
 
ENDSUB
</syntaxhighlight>
</lang>
 
==={{header|BBC BASIC}}===
<langsyntaxhighlight lang="bbcbasic">
CLS
xp=320:yp=160:size=150
Line 634:
LINE xp, yp, xp+2*ss*SIN(lasts), yp+ss*COS(lasts)
ENDPROC
</syntaxhighlight>
</lang>
 
 
==={{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 670:
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 693:
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 802:
echo.
timeout /t 1 /nobreak >nul
goto :clock_loop</langsyntaxhighlight>
{{Out}}
<pre>
Line 814:
=={{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 906:
draw(s);
return 0;
}</langsyntaxhighlight>
===Clock in xlib (for X windows)===
<langsyntaxhighlight Clang="c">// clockrosetta.c - https://rosettacode.org/wiki/Draw_a_clock
 
// # Makefile
Line 1,121:
}
 
// END</langsyntaxhighlight>
 
=={{header|C sharp|C#}}==
<langsyntaxhighlight lang="csharp">using System;
using System.Drawing;
using System.Drawing.Drawing2D;
Line 1,210:
Application.Run(new Clock());
}
}</langsyntaxhighlight>
 
=={{header|C++}}==
[[File:clock_cpp.png]]
<langsyntaxhighlight lang="cpp">
#include <windows.h>
#include <string>
Line 1,545:
}
//--------------------------------------------------------------------------------------------------
</syntaxhighlight>
</lang>
 
=={{header|ContextFree}}==
<syntaxhighlight lang="text">
startshape START
 
Line 1,564:
}
 
</syntaxhighlight>
</lang>
 
=={{header|Delphi}}==
Line 1,576:
Form application
 
<syntaxhighlight lang="delphi">
<lang Delphi>
unit main;
 
Line 1,767:
end.
 
</syntaxhighlight>
</lang>
 
Resources:
<syntaxhighlight lang="delphi">
<lang Delphi>
object Clock: TClock
Left = 0
Line 1,795:
end
end
</syntaxhighlight>
</lang>
 
 
Line 1,805:
[https://easylang.online/apps/clock.html Run it]
 
<syntaxhighlight lang="text"># Clock
#
func draw hour min sec . .
Line 1,857:
timer 0.1
.
timer 0</langsyntaxhighlight>
 
=={{header|F_Sharp|F#}}==
<langsyntaxhighlight lang="fsharp">open System.Text.RegularExpressions
 
let numberTemplate = """
Line 1,902:
System.Console.ReadLine() |> ignore // Until return is hit
showTime ()
0</langsyntaxhighlight>
{{out}}
<pre> _ _ _ _ __
Line 1,915:
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,979:
?TERMINAL
UNTIL
2DROP ;</langsyntaxhighlight>
 
=={{header|Fortran}}==
Line 1,985:
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 2,102:
 
end subroutine
</syntaxhighlight>
</lang>
 
Preview:
Line 2,120:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">' version 05-04-2017
' compile with: fbc -s gui
 
Line 2,202:
ImageDestroy(clockdial)
 
End</langsyntaxhighlight>
 
=={{header|FunL}}==
 
<langsyntaxhighlight lang="funl">import concurrent.{scheduleAtFixedRate, scheduler}
 
val ROW = 10
Line 2,272:
 
if not $os.startsWith( 'Windows' )
print( '\u001B[?25h' )</langsyntaxhighlight>
 
{{out}}
Line 2,282:
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import (
Line 2,369:
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 2,471:
</body>
</html></langsyntaxhighlight>
 
=={{header|GUISS}}==
 
<syntaxhighlight lang ="guiss">Start,Programs,Accessories,Analogue Clock</langsyntaxhighlight> =={{header|GUISS}}==
 
<syntaxhighlight lang ="guiss">Start,Programs,Accessories,Analogue Clock</langsyntaxhighlight>
 
=={{header|Haskell}}==
{{libheader|ansi-terminal}}
<langsyntaxhighlight Haskelllang="haskell">import Control.Concurrent
import Data.List
import System.Time
Line 2,594:
setCursorColumn 0
cursorUp 5
main</langsyntaxhighlight>
Output:<pre> ██ ██████ ██████ ██████ ██████ ██████
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
Line 2,608:
1. Clock using conventional Graphics
 
<langsyntaxhighlight lang="icon">
link graphics
 
Line 2,722:
end
 
</syntaxhighlight>
</lang>
 
2. Clock using Turtle Graphics
<langsyntaxhighlight lang="icon">
link graphics, turtle
 
Line 2,907:
draw("r", xsize/2 * 0.25, 8 * xsize / 800, ws - 180)
end
</syntaxhighlight>
</lang>
 
=={{header|J}}==
Graphical clock (tested on jqt -- j903):
 
<syntaxhighlight lang="j">{{
<lang J>{{
require'gl2'
coinsert 'jgl2'
Line 2,945:
pshow;
}}
}}1</langsyntaxhighlight>
 
Some alternatives:
 
<syntaxhighlight lang="j">
<lang J>
Note'rudimentary 4 second clock'
advances an arrow at roughly 1 second intervals,
Line 2,970:
 
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,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):
 
<langsyntaxhighlight Jlang="j">require'plot'
N=:0.01*i.629
O=: [: j./ 1 2 o./ ]
Line 2,993:
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 3,077:
});
}
}</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 3,127:
 
window.setInterval(update_clock, 200);
}</langsyntaxhighlight>
 
=== digital ===
<langsyntaxhighlight lang="javascript"><!DOCTYPE html>
<html lang="en">
<head>
Line 3,262:
 
</body>
</html></langsyntaxhighlight>
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">
using Gtk, Colors, Graphics, Dates
 
Line 3,349:
sleep(1.0)
end
</syntaxhighlight>
</lang>
 
=={{header|Kotlin}}==
{{trans|Java}}
<langsyntaxhighlight lang="scala">// version 1.1
 
import java.awt.*
Line 3,423:
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
 
<langsyntaxhighlight lang="scheme">
1) lambdatalk code
{watch} // displays the watch
Line 3,501:
};
}
</syntaxhighlight>
</lang>
 
=={{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 3,545:
 
end
</syntaxhighlight>
</lang>
 
=={{header|Locomotive Basic}}==
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.
 
<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 3,596:
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 3,603:
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">Dynamic[ClockGauge[], UpdateInterval -> 1]</langsyntaxhighlight>
 
=={{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}}==
Line 3,618:
This solution works with [https://miniscript.org/MiniMicro Mini Micro], and uses its default SpriteDisplay.
 
<langsyntaxhighlight MiniScriptlang="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
Line 3,643:
hand.rotation = 90 - floor(time) % 60 * 6
wait
end while</langsyntaxhighlight>
 
=={{header|NetRexx}}==
{{trans|Java}}
<langsyntaxhighlight NetRexxlang="netrexx">/* NetRexx */
options replace format comments java crossref symbols binary
 
Line 3,749:
repaint()
return
</syntaxhighlight>
</lang>
 
=={{header|Nim}}==
==={{header|Text}}===
{{trans|Raku}}
<langsyntaxhighlight lang="nim">import times, os
 
const
Line 3,767:
for c in x: stdout.write b[c.ord - '0'.ord]
echo ""
sleep 1000</langsyntaxhighlight>
 
==={{header|Using SDL}}===
{{libheader|SDL2}}
<langsyntaxhighlight lang="nim">## needs sdl2 ("nimble install sdl2")
 
import sdl2, times, math
Line 3,833:
 
destroy render
destroy window</langsyntaxhighlight>
 
=={{header|OCaml}}==
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:
 
<langsyntaxhighlight lang="ocaml">#!/usr/bin/env ocaml
#load "unix.cma"
#load "graphics.cma"
Line 3,903:
in
try loop ()
with _ -> close_graph ()</langsyntaxhighlight>
 
 
Line 3,919:
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,984:
animate area;
w#show ();
GMain.main ()</langsyntaxhighlight>
 
=={{header|ooRexx}}==
Line 3,991:
<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 4,269:
Parse Arg x,y
If y=0 Then Return '??'
Else Return x/y</langsyntaxhighlight>
 
===version 2 runs under Windows, Linux, and MacOSX===
Line 4,275:
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 4,417:
::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 4,424:
=={{header|Perl}}==
{{trans|Raku}}
<langsyntaxhighlight lang="perl">use utf8; # interpret source code as UTF8
binmode STDOUT, ':utf8'; # allow printing wide chars without warning
$|++; # disable output buffering
Line 4,452:
 
sub clear { print "\e[H\e[J" }
sub position { printf "\e[%d;%dH", shift, shift }</langsyntaxhighlight>
 
{{out}}
Line 4,466:
Resizeable, appearance similar to Mathematica.
You can run this online [http://phix.x10.mx/p2js/clock.htm here].
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\Clock.exw
Line 4,593:
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
<!--</langsyntaxhighlight>-->
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 4,644:
(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 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.
 
<langsyntaxhighlight lang="java">void draw() {
drawClock();
}
Line 4,685:
strokeWeight(4);
line(0, 0, 0, -width*0.2);
}</langsyntaxhighlight>
 
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:
 
<langsyntaxhighlight lang="java">int lastSec = second();
void draw() {
if (lastSec!=second()) {
Line 4,695:
lastSec=second();
}
}</langsyntaxhighlight>
 
One of the official Processing language examples is a more graphically detailed [https://processing.org/examples/clock.html Clock example].
 
==={{header|Processing Python mode}}===
<langsyntaxhighlight lang="python">
last_sec = second()
 
Line 4,723:
rotate(-m + h)
strokeWeight(4)
line(0, 0, 0, -width * 0.2)</langsyntaxhighlight>
 
=={{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 4,777:
SetGadgetState(#clock_gad, ImageID(#clockFace_img))
EndIf
Until event = #PB_Event_CloseWindow</langsyntaxhighlight>
 
=={{header|Python}}==
Line 4,784:
===Textmode===
 
<langsyntaxhighlight lang="python">import time
 
def chunks(l, n=5):
Line 4,814:
print bin_bit(y[1])
print
print secs(s)</langsyntaxhighlight>
 
==={{libheader|VPython}}===
Line 4,824:
Draws an analog clock in a new GUI window:
 
<langsyntaxhighlight lang="racket">
#lang racket/gui
 
Line 4,880:
 
(send f show #t)
</syntaxhighlight>
</lang>
 
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku" perl6line>my ($rows,$cols) = qx/stty size/.words;
my $v = floor $rows / 2;
my $h = floor $cols / 2 - 16;
Line 4,900:
print "\e[H";
sleep 1;
}</langsyntaxhighlight>
{{out}}
<pre>⠀⢺⠀ ⢀⠔⡇ ⠀⠶⠀ ⠊⠉⡱ ⠊⣉⡱ ⠀⠶⠀ ⣏⣉⡉ ⡎⢉⢵
Line 4,907:
=={{header|Red}}==
===Minimalistic===
<langsyntaxhighlight Redlang="red">Red [Needs: 'View]
view [t: h4 rate 1 on-time [t/data: now/time]]
</syntaxhighlight>
</lang>
{{out}}
[https://raw.githubusercontent.com/Palaing/redlib/master/games/images/miniclock.png mini clock image]
 
===Analog===
<langsyntaxhighlight Redlang="red">Red [
Needs: 'View
Purpose: {simple analog clock based on Nenad Rakocevic's eve-clock.red,
Line 4,931:
sec/2: 6 * time/second
]]
</syntaxhighlight>
</lang>
{{out}}
[https://raw.githubusercontent.com/Palaing/redlib/master/games/images/analogclock.png analog clock image]
Line 4,950:
:::* &nbsp; '''ROO'''
the color of the display can be specified.
<langsyntaxhighlight 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*/
Line 5,027:
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)</langsyntaxhighlight>
;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.
Line 5,081:
{{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 5,121:
 
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 5,169:
end
end
end</langsyntaxhighlight>
 
{{libheader|RubyGems}}
{{libheader|JRubyArt}}
JRubyArt is port of processing to ruby
<langsyntaxhighlight lang="ruby">
def setup
sketch_title 'Clock'
Line 5,221:
end
 
</syntaxhighlight>
</lang>
 
=={{header|Run BASIC}}==
[[File:Rb_clock.png|thumb|Sample display of RB solution]]
<langsyntaxhighlight lang="runbasic">' --------------------------------------------
' clock. I got nothing but time
' ---------------------------------------------
Line 5,319:
#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 5,350:
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._
Line 5,407:
}
(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 5,459:
}
}
}</langsyntaxhighlight>
 
=={{header|Scheme}}==
Line 5,467:
The program displays an analogue clock with three hands, updating once a second.
 
<syntaxhighlight lang="scheme">
<lang Scheme>
(import (scheme base)
(scheme inexact)
Line 5,527:
(hands canvas))
(tk-event-loop tk))
</syntaxhighlight>
</lang>
 
=={{header|Scratch}}==
Line 5,536:
=={{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 5,606:
command := busy_getc(KEYBOARD);
end while;
end func;</langsyntaxhighlight>
 
=={{header|Sidef}}==
{{trans|Perl}}
<langsyntaxhighlight lang="ruby">STDOUT.autoflush(true)
 
var (rows, cols) = `stty size`.nums...
Line 5,640:
print position(1, 1)
Sys.sleep(0.1)
}</langsyntaxhighlight>
{{out}}
<pre>
Line 5,649:
 
=={{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 5,683:
<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 5,720:
}
}
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">
<lang vb>
'ANSI Clock
 
Line 5,797:
wend
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 5,831:
{{trans|Kotlin}}
{{libheader|DOME}}
<langsyntaxhighlight lang="ecmascript">import "graphics" for Canvas, Color
import "dome" for Window
import "math" for Math
Line 5,906:
}
 
var Game = Clock.new(0, 0, 0) // start at midnight</langsyntaxhighlight>
 
=={{header|Yabasic}}==
<langsyntaxhighlight Yabasiclang="yabasic">clear screen
open window 300,100
backcolor 0, 0, 0
Line 5,942:
until(upper$(inkey$(.01))="ESC")
exit
end if</langsyntaxhighlight>
 
=={{header|zkl}}==
{{trans|Nim}}
<langsyntaxhighlight lang="zkl">var
t=T("⡎⢉⢵","⠀⢺⠀","⠊⠉⡱","⠊⣉⡱","⢀⠔⡇","⣏⣉⡉","⣎⣉⡁","⠊⢉⠝","⢎⣉⡱","⡎⠉⢱","⠀⠶⠀"),
b=T("⢗⣁⡸","⢀⣸⣀","⣔⣉⣀","⢄⣀⡸","⠉⠉⡏","⢄⣀⡸","⢇⣀⡸","⢰⠁⠀","⢇⣀⡸","⢈⣉⡹","⠀⠶ ");
Line 5,955:
println(x.pump(String,t.get),"\n",x.pump(String,b.get));
Atomic.sleep(1);
}</langsyntaxhighlight>
{{out}}
<pre>
Line 5,964:
=={{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 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
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}}
10,339

edits