Draw a clock: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) 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}} |
||
< |
<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;</ |
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+ |
||
< |
<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</ |
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}}=== |
||
< |
<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</ |
RETURN</syntaxhighlight> |
||
==={{header|BaCon}}=== |
==={{header|BaCon}}=== |
||
Using GTK3 as a graphical toolkit. |
Using GTK3 as a graphical toolkit. |
||
< |
<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}}=== |
||
< |
<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. |
||
< |
<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</ |
1560 return</syntaxhighlight> |
||
==={{header|IS-BASIC}}=== |
==={{header|IS-BASIC}}=== |
||
< |
<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</ |
310 TEXT</syntaxhighlight> |
||
=={{header|Batch File}}== |
=={{header|Batch File}}== |
||
< |
<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</ |
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>. |
||
< |
<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; |
||
}</ |
}</syntaxhighlight> |
||
===Clock in xlib (for X windows)=== |
===Clock in xlib (for X windows)=== |
||
< |
<syntaxhighlight lang="c">// clockrosetta.c - https://rosettacode.org/wiki/Draw_a_clock |
||
// # Makefile |
// # Makefile |
||
Line 1,121: | Line 1,121: | ||
} |
} |
||
// END</ |
// END</syntaxhighlight> |
||
=={{header|C sharp|C#}}== |
=={{header|C sharp|C#}}== |
||
< |
<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()); |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|C++}}== |
=={{header|C++}}== |
||
[[File:clock_cpp.png]] |
[[File:clock_cpp.png]] |
||
< |
<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</ |
timer 0</syntaxhighlight> |
||
=={{header|F_Sharp|F#}}== |
=={{header|F_Sharp|F#}}== |
||
< |
<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</ |
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 ;</ |
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}}== |
||
< |
<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</ |
End</syntaxhighlight> |
||
=={{header|FunL}}== |
=={{header|FunL}}== |
||
< |
<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' )</ |
print( '\u001B[?25h' )</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 2,282: | Line 2,282: | ||
=={{header|Go}}== |
=={{header|Go}}== |
||
< |
<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 |
||
}</ |
}</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. |
||
< |
<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></ |
</html></syntaxhighlight> |
||
=={{header|GUISS}}== |
=={{header|GUISS}}== |
||
<lang |
<syntaxhighlight lang="guiss">Start,Programs,Accessories,Analogue Clock</syntaxhighlight> =={{header|GUISS}}== |
||
<lang |
<syntaxhighlight lang="guiss">Start,Programs,Accessories,Analogue Clock</syntaxhighlight> |
||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
{{libheader|ansi-terminal}} |
{{libheader|ansi-terminal}} |
||
< |
<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</ |
main</syntaxhighlight> |
||
Output:<pre> ██ ██████ ██████ ██████ ██████ ██████ |
Output:<pre> ██ ██████ ██████ ██████ ██████ ██████ |
||
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ |
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ |
||
Line 2,608: | Line 2,608: | ||
1. Clock using conventional Graphics |
1. Clock using conventional Graphics |
||
< |
<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 |
||
< |
<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</ |
}}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): |
||
< |
<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''</ |
delay@1:@clock^:9e99''</syntaxhighlight> |
||
=={{header|Java}}== |
=={{header|Java}}== |
||
{{works with|Java|8}} |
{{works with|Java|8}} |
||
< |
<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: | ||
}); |
}); |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|JavaScript}}== |
=={{header|JavaScript}}== |
||
Tested on Gecko. Put the following in a <script> tag somewhere, and call <code>init_clock()</code> after body load. |
Tested on Gecko. Put the following in a <script> tag somewhere, and call <code>init_clock()</code> after body load. |
||
< |
<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); |
||
}</ |
}</syntaxhighlight> |
||
=== digital === |
=== digital === |
||
< |
<syntaxhighlight lang="javascript"><!DOCTYPE html> |
||
<html lang="en"> |
<html lang="en"> |
||
<head> |
<head> |
||
Line 3,262: | Line 3,262: | ||
</body> |
</body> |
||
</html></ |
</html></syntaxhighlight> |
||
=={{header|Julia}}== |
=={{header|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}} |
||
< |
<syntaxhighlight lang="scala">// version 1.1 |
||
import java.awt.* |
import java.awt.* |
||
Line 3,423: | Line 3,423: | ||
f.isVisible = true |
f.isVisible = true |
||
} |
} |
||
}</ |
}</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 |
||
< |
<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. |
||
< |
<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</ |
460 return</syntaxhighlight> |
||
=={{header|Lua}}== |
=={{header|Lua}}== |
||
Line 3,603: | Line 3,603: | ||
=={{header|Mathematica}} / {{header|Wolfram Language}}== |
=={{header|Mathematica}} / {{header|Wolfram Language}}== |
||
< |
<syntaxhighlight lang="mathematica">Dynamic[ClockGauge[], UpdateInterval -> 1]</syntaxhighlight> |
||
=={{header|MATLAB}} / {{header|Octave}}== |
=={{header|MATLAB}} / {{header|Octave}}== |
||
< |
<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;</ |
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. |
||
< |
<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</ |
end while</syntaxhighlight> |
||
=={{header|NetRexx}}== |
=={{header|NetRexx}}== |
||
{{trans|Java}} |
{{trans|Java}} |
||
< |
<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}} |
||
< |
<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</ |
sleep 1000</syntaxhighlight> |
||
==={{header|Using SDL}}=== |
==={{header|Using SDL}}=== |
||
{{libheader|SDL2}} |
{{libheader|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</ |
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: |
||
< |
<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 ()</ |
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 |
||
< |
<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 ()</ |
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. |
||
< |
<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</ |
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 |
||
< |
<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</ |
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}} |
||
< |
<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 }</ |
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]. |
||
<!--< |
<!--<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> |
||
<!--</ |
<!--</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].< |
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) )</ |
(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. |
||
< |
<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); |
||
}</ |
}</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: |
||
< |
<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(); |
||
} |
} |
||
}</ |
}</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}}=== |
||
< |
<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)</ |
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]] |
||
< |
<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</ |
Until event = #PB_Event_CloseWindow</syntaxhighlight> |
||
=={{header|Python}}== |
=={{header|Python}}== |
||
Line 4,784: | Line 4,784: | ||
===Textmode=== |
===Textmode=== |
||
< |
<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)</ |
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: |
||
< |
<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 |
<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; |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>⠀⢺⠀ ⢀⠔⡇ ⠀⠶⠀ ⠊⠉⡱ ⠊⣉⡱ ⠀⠶⠀ ⣏⣉⡉ ⡎⢉⢵ |
<pre>⠀⢺⠀ ⢀⠔⡇ ⠀⠶⠀ ⠊⠉⡱ ⠊⣉⡱ ⠀⠶⠀ ⣏⣉⡉ ⡎⢉⢵ |
||
Line 4,907: | Line 4,907: | ||
=={{header|Red}}== |
=={{header|Red}}== |
||
===Minimalistic=== |
===Minimalistic=== |
||
< |
<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=== |
||
< |
<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: | ||
:::* '''ROO''' |
:::* '''ROO''' |
||
the color of the display can be specified. |
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*/ |
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)</ |
syntax: !sigl= sigl; call er 13,!fid(2) !fid(3) !sigl !cal() condition('D') sourceline(!sigl)</syntaxhighlight> |
||
;Programming notes: |
;Programming notes: |
||
The '''$CLOCK.REX''' REXX program makes use of '''$T.REX''' REXX program which is used to display text and/or create big blocked characters. |
The '''$CLOCK.REX''' REXX program makes use of '''$T.REX''' 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]] |
||
< |
<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</ |
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]] |
||
< |
<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</ |
end</syntaxhighlight> |
||
{{libheader|RubyGems}} |
{{libheader|RubyGems}} |
||
{{libheader|JRubyArt}} |
{{libheader|JRubyArt}} |
||
JRubyArt is port of processing to ruby |
JRubyArt is port of processing to 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]] |
||
< |
<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</ |
RETURN</syntaxhighlight> |
||
=={{header|Rust}}== |
=={{header|Rust}}== |
||
< |
<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); |
||
}</ |
}</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 |
||
< |
<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) |
||
}</ |
}</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]] |
||
< |
<syntaxhighlight lang="scala">import java.time.LocalTime |
||
import java.awt.{ Color, Graphics } |
import java.awt.{ Color, Graphics } |
||
Line 5,459: | Line 5,459: | ||
} |
} |
||
} |
} |
||
}</ |
}</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. |
||
< |
<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;</ |
end func;</syntaxhighlight> |
||
=={{header|Sidef}}== |
=={{header|Sidef}}== |
||
{{trans|Perl}} |
{{trans|Perl}} |
||
< |
<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) |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 5,649: | Line 5,649: | ||
=={{header|SVG}}== |
=={{header|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}} |
||
< |
<syntaxhighlight lang="tcl">package require Tcl 8.5 |
||
package require Tk |
package require Tk |
||
Line 5,720: | Line 5,720: | ||
} |
} |
||
} |
} |
||
ticker</ |
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}} |
||
< |
<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</ |
var Game = Clock.new(0, 0, 0) // start at midnight</syntaxhighlight> |
||
=={{header|Yabasic}}== |
=={{header|Yabasic}}== |
||
< |
<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</ |
end if</syntaxhighlight> |
||
=={{header|zkl}}== |
=={{header|zkl}}== |
||
{{trans|Nim}} |
{{trans|Nim}} |
||
< |
<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); |
||
}</ |
}</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. |
||
< |
<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</ |
230 LET t1=t: GO TO 120</syntaxhighlight> |
||
{{omit from|ACL2|No access to system time}} |
{{omit from|ACL2|No access to system time}} |