Draw a clock: Difference between revisions

m
Replace deprecated functions
No edit summary
m (Replace deprecated functions)
 
(26 intermediate revisions by 11 users not shown)
Line 267:
=={{header|Amazing Hopper}}==
{{Trans|bbcbasic}}
{{Trans|baCon}}
"Clock" dibujado en modo texto con Hopper-Jambo.
[[File:Captura_de_pantalla_de_2022-10-11_01-10-51.png|200px|thumb|right|Caption]]
Line 277 ⟶ 278:
 
#include <jambo.h>
 
#define ONESECOND 1000
 
Main
Line 292 ⟶ 295:
Tic ( last time )
Loop
On time ( 1000ONE SECOND ~= last time ){
Gosub 'draw clock'
}
Line 306 ⟶ 309:
 
Color back '0'
Draw a line (xp, yp, #(xp+(hs*sin(d2r(lasth)))), #(yp+(hs*cos(d2r(lasth)))) )\
Draw a line (#(xp-1), #(yp-1), #(xp+(hs*sin(d2r(lasth)))), #(yp+(hs*cos(d2r(lasth)))) )
Draw a line (#(xp+-1), #(yp+-1), #(xp+(hs*sin(d2r(lasth)))), #(yp+(hs*cos(d2r(lasth)))) )\
#(yp+(hs*cos(d2r(lasth)))) )
Draw a line (#(xp+1), #(yp+1), #(xp+(hs*sin(d2r(lasth)))),\
#(yp+(hs*cos(d2r(lasth)))) )
Draw a line (xp, yp, #(xp+(ms*sin(d2r(lastm)))), #(yp+(ms*cos(d2r(lastm)))) )\
Draw a line (#(xp-1), #(yp-1), #(xp+(ms*sin(d2r(lastm)))), #(yp+(ms*cos(d2r(lastm)))) )
Draw a line (#(xp-1), #(yp-1), #(xp+(ms*sin(d2r(lastm)))),\
#(yp+(ms*cos(d2r(lastm)))) )
Draw a line (xp, yp, #(xp+(ss*sin(d2r(lasts)))), #(yp+(ss*cos(d2r(lasts)))) )\
#(yp+(ss*cos(d2r(lasts)))) )
Let ( lasts := #(s*6-90) )
Line 320 ⟶ 329:
Color back '15'
Draw a line (xp, yp, #(xp+(hs*sin(d2r(lasth)))), #(yp+(hs*cos(d2r(lasth)))) )\
Draw a line (#(xp-1), #(yp-1), #(xp+(hs*sin(d2r(lasth)))), #(yp+(hs*cos(d2r(lasth)))) )
Draw a line (#(xp+-1), #(yp+-1), #(xp+(hs*sin(d2r(lasth)))), #(yp+(hs*cos(d2r(lasth)))) )\
#(yp+(hs*cos(d2r(lasth)))) )
Draw a line (#(xp+1), #(yp+1), #(xp+(hs*sin(d2r(lasth)))),\
#(yp+(hs*cos(d2r(lasth)))) )
Color back '3'
Draw a line (xp, yp, #(xp+(ms*sin(d2r(lastm)))), #(yp+(ms*cos(d2r(lastm)))) )\
Draw a line (#(xp-1), #(yp-1), #(xp+(ms*sin(d2r(lastm)))), #(yp+(ms*cos(d2r(lastm)))) )
Draw a line (#(xp-1), #(yp-1), #(xp+(ms*sin(d2r(lastm)))),\
#(yp+(ms*cos(d2r(lastm)))) )
Color back '13'
Draw a line (xp, yp, #(xp+(ss*sin(d2r(lasts)))), #(yp+(ss*cos(d2r(lasts)))) )\
#(yp+(ss*cos(d2r(lasts)))) )
Return
 
Line 684 ⟶ 699:
ENDSUB
</syntaxhighlight>
 
==={{header|uBasic/4tH}}===
This program requires an ANSI terminal for the best results.
<syntaxhighlight lang="uBasic/4tH">Dim @c(3)
' clock digits
@c(0) := " _ _ _ _ __ _ _ "
@c(1) := "/ \\ /| ) _)|_||_ / /(_)(_) * "
@c(2) := "\\_/ | /_ _) | _)(_) / (_) / * "
 
p = 0 ' previous time equals zero
 
Do ' repeat forever
Do
t = Time() % 86400 ' get the time and encode it
t = ((t / 3600) * 10000) + ((t % 3600) / 60) * 100 + ((t % 3600) % 60)
Until t > p ' until a second has been passed
Loop
 
p = t : Print "\e[2J\e[H" ' set old time to new time
' clear screen
For x = 0 To 2 ' for all rows
d = t ' preserve time
For y = 5 To 0 Step -1 ' get all digit columns
Print Show(FUNC(_Figure(d/(10^y), x)));
If y%2 = 0 Then If y Then Print Show(FUNC(_Figure(10, x)));
d = d%(10^y) ' get next digit column
Next : Print ' next column, terminate row
Next ' next row
Loop ' next second
End
' get figure row/column
_Figure: Param (2) : Return (Clip(Chop(@c(b@), a@ * 3), (10-a@) * 3))</syntaxhighlight>
{{Out}}
<pre> _ _ _ _ _
/ \(_) * / \|_| * |_ (_)
\_/ / * \_/ | * _)(_)</pre>
 
==={{header|BBC BASIC}}===
Line 724 ⟶ 775:
ENDPROC
</syntaxhighlight>
 
 
==={{header|Commodore BASIC}}===
Line 1,892 ⟶ 1,942:
=={{header|EasyLang}}==
 
[https://easylang.onlinedev/apps/clock.html Run it]
 
<syntaxhighlight lang="text"># Clock
proc draw hour min sec . .
#
# dial
func draw hour min sec . .
# dialcolor 333
move 50 50
color 333
move 50circle 5045
color 797
circle 45
circle 44
color 797
color 333
circle 44
for i range0 60
color 333
for a = i range* 606
move 50 + sin a =* i40 50 + cos a * 640
circle 0.25
move 50 + sin a * 40 50 - cos a * 40
circle 0.25
for i range0 12
.
for a = i range* 1230
move 50 + sin a =* i40 50 + cos a * 3040
circle 1
move 50 + sin a * 40 50 - cos a * 40
circle 1.
. # hour
linewidth 2
# hour
color 000
linewidth 2
a = (hour * 60 + min) / 2
color 000
move 50 50
a = (hour * 60 + min) / 2
move line 50 + sin a * 32 50 + cos a * 32
# min
line 50 + sin a * 32 50 - cos a * 32
linewidth 1.5
# min
a = (sec + min * 60) / 10
linewidth 1.5
move 50 50
a = (sec + min * 60) / 10
move line 50 + sin a * 40 50 + cos a * 40
# sec
line 50 + sin a * 40 50 - cos a * 40
# sec linewidth 1
color 700
linewidth 1
a = sec * 6
color 700
a =move sec50 * 650
move line 50 + sin a * 40 50 + cos a * 40
line 50 + sin a * 40 50 - cos a * 40
.
on timer
if t <> floor systime
t = floor systime
h$ = timestr t
sec = number substr h$ 1718 2
min = number substr h$ 1415 2
hour = number substr h$ 1112 2
if hour > 12
hour -= 12
.
call draw hour min sec
.
timer 0.1
.
timer 0</syntaxhighlight>
</syntaxhighlight>
 
 
=={{header|Evaldraw}}==
 
A clock that shows hours, minutes and seconds all moving each millisecond.
 
[[File:Clock.png|Hour minute and second hands move on milli second ticks|right]]
 
<syntaxhighlight lang="C">
(){
cls(0);
drawclock(150);
}
drawclock(rad) {
hand_color = 0x6a6a6a;
seconds_color = 0xff0000;
radius_notches = rad*.95;
radius_numbers = rad*.85;
small_notch_size =rad*0.04;
big_notch_size = rad*0.08;
cx=rad+1;
cy=rad+1;
// Face background
setcol(0x5aaaaa); drawsph(cx,cy,rad);
 
// Highlight from stopwatch.kc
setcol(0xffffff); gldisable(GL_DEPTH_TEST);
glbegin(GL_COMPLEX); glsettex("whitepix.tga");
for(a=3.5;a<=4.5;a+=.25) { gltexcoord(0,0); glvertex(cos(a)*rad*.55+cx,sin(a)*rad*.55+cy); }
for(a=4.5;a>=3.5;a-=.25) { gltexcoord(0,0); glvertex(cos(a)*rad*.45+cx,sin(a)*rad*.45+cy); }
glend();
 
moveto(cx-4*6, cy-.5*rad);
setfont(6,8);
setcol(0); printf("Evaltime");
// Face
setcol(0x015151);
hr=0;
for(i=0; i<60; i++)
{
a = i/60*2*pi - pi/2;
ca=cos(a);
sa=sin(a);
if (i%5==0)
{
hour = hr; if (hour==0) hour=12;
draw_hour(cx,cy,ca,sa,radius_numbers,hour);
hr++;
r=radius_notches;
x=cx + ca*r; y=cy+sa*r;
drawcone(x,y,big_notch_size*.5,x+big_notch_size*ca,y+big_notch_size*sa,-big_notch_size*.5,0);
} else {
r=radius_notches;
x=cx + ca*r; y=cy+sa*r;
drawcone(x,y,small_notch_size*.5,x+small_notch_size*ca,y+small_notch_size*sa,-small_notch_size*.5,0);
}
}
int_hours = klock(6);
int_minutes = klock(7);
int_seconds = klock(8);
int_millis = klock(9);
// Hour and Minute hand
hours = (int_hours+int_minutes/60.0) / 24.0;
a = hours * 2*pi - pi/2;
drawhand(cx,cy,a, rad*.64, 6,4, hand_color);
a = ( (int_minutes+int_seconds/60+int_millis/1000/60) / 60) * 2*pi - pi/2;
drawhand(cx,cy,a, rad*.84, 4,2, hand_color);
a = ((int_seconds+int_millis/1000) / 60) * 2*pi - pi/2;
drawhand(cx,cy,a, rad*.9, 3,1, seconds_color);
}
 
draw_hour(cx,cy,ca,sa,r,hr) {
x=cx + ca*r; y=cy+sa*r;
ofs=0; if(hr>9 || hr==0) ofs=5;
setfont(9,16);
moveto(x-4.5-ofs,y-8);
printf("%g", hr);
}
drawhand(cx,cy,angle,forward,r0,r1,kolor) {
back = .19*forward;
sx=cx - cos(angle)*back;
sy=cy - sin(angle)*back;
ex=cx + cos(angle)*forward;
ey=cy + sin(angle)*forward;
setcol(0);
drawcone(sx,sy,r0+1,ex,ey,r1+1);
setcol(kolor);
drawsph(cx,cy,r0+3);
drawcone(sx,sy,-r0,ex,ey,r1);
}</syntaxhighlight>
 
=={{header|F_Sharp|F#}}==
Line 2,369 ⟶ 2,516:
/__ /__/ . /__ / . / /
</pre>
 
 
 
=={{header|FutureBasic}}==
This FB code produces a stand-alone executable application for a Macintosh.
<syntaxhighlight lang="futurebasic">
output file "Rosetta Code Clock"
 
_window = 1
begin enum 1
_clockView
_one
_two
_three
_four
_five
_six
_seven
_eight
_nine
_ten
_eleven
_twelve
end enum
 
local fn BuildWindow
CALayerRef layer, hoursLayer, minutesLayer, secondsLayer
CAShapeLayerRef shapeLayer, hubLayer
CATextLayerRef textLayer
BezierPathRef circle, hub
CGPoint pt
CGRect r, frame
CFDateRef dt
CFTimeInterval ti
CGFloat h, m, s, ha, ma, sa
NSUInteger i
CFStringRef num
CABasicAnimationRef secondsAnimation, minutesAnimation, hoursAnimation
// Window
r = fn CGRectMake( 0, 0, 500, 500 )
window _window, @"FutureBasic Rosetta Code Clock", r
WindowSetBackgroundColor( _window, fn ColorBlack )
// View to hold clock layers
view _clockView, r, _window
ViewSetWantsLayer( _clockView, YES )
layer = fn ViewLayer( _clockView )
frame = fn ViewFrame( _clockView )
// Blank clock face
shapeLayer = fn CAShapeLayerInit
circle = fn BezierPathWithOvalInRect( fn CGRectInset( r, 35, 35 ) )
CAShapeLayerSetPath( shapeLayer, circle )
CAShapeLayerSetLineWidth( shapeLayer, 6.5 )
CAShapeLayerSetLineCap( shapeLayer, kCALineCapRound )
CAShapeLayerSetFillColor( shapeLayer, fn ColorDarkGray )
CAShapeLayerSetStrokeColor( shapeLayer, fn ColorWithRGB( 0.711, 0.533, 0.258, 1.0 ) )
CALayerAddSublayer( layer, shapeLayer )
// Clock numerals
for i = _one to _twelve
if i = _one then pt = fn CGPointMake( frame.size.width / 2 + 95, frame.size.height / 2 + 115 ) : num = @"1"
if i = _two then pt = fn CGPointMake( frame.size.width / 2 + 160, frame.size.height / 2 + 45 ) : num = @"2"
if i = _three then pt = fn CGPointMake( frame.size.width / 2 + 180, frame.size.height / 2 - 40 ) : num = @"3"
if i = _four then pt = fn CGPointMake( frame.size.width / 2 + 155, frame.size.height / 2 - 125 ) : num = @"4"
if i = _five then pt = fn CGPointMake( frame.size.width / 2 + 90, frame.size.height / 2 - 190 ) : num = @"5"
if i = _six then pt = fn CGPointMake( frame.size.width / 2, frame.size.height / 2 - 215 ) : num = @"6"
if i = _seven then pt = fn CGPointMake( frame.size.width / 2 - 90, frame.size.height / 2 - 190 ) : num = @"7"
if i = _eight then pt = fn CGPointMake( frame.size.width / 2 - 155, frame.size.height / 2 - 125 ) : num = @"8"
if i = _nine then pt = fn CGPointMake( frame.size.width / 2 - 185, frame.size.height / 2 - 40 ) : num = @"9"
if i = _ten then pt = fn CGPointMake( frame.size.width / 2 - 155, frame.size.height / 2 + 45 ) : num = @"10"
if i = _eleven then pt = fn CGPointMake( frame.size.width / 2 - 90, frame.size.height / 2 + 115 ) : num = @"11"
if i = _twelve then pt = fn CGPointMake( frame.size.width / 2, frame.size.height / 2 + 145 ) : num = @"12"
textLayer = fn CATextLayerInit
CATextLayerSetString( textLayer, num )
CATextLayerSetFont( textLayer, @"Times" )
CATextLayerSetFontSize( textLayer, 50.0 )
CATextLayerSetForegroundColor( textLayer, fn ColorGreen )
CALayerSetAnchorPoint( textLayer, fn CGPointMake( 0.5, 0 ) )
CATextLayerSetAlignmentMode( textLayer, kCAAlignmentCenter )
CALayerSetPosition( textLayer, pt )
CALayerSetBounds( textLayer, fn CGRectMake( 0, 0, 70, 65 ) )
CALayerAddSublayer( layer, textLayer )
next
// Hours layer
hoursLayer = fn CALayerInit
CALayerSetBackgroundColor( hoursLayer, fn ColorWhite )
CALayerSetAnchorPoint( hoursLayer, fn CGPointMake( 0.5, 0 ) )
CALayerSetPosition( hoursLayer, fn CGPointMake( frame.size.width / 2, frame.size.height / 2 ) )
CALayerSetBounds( hoursLayer, fn CGRectMake( 0, 0, 10, frame.size.width / 2 -90 ) )
CALayerSetCornerRadius( hoursLayer, 4.0 )
CALayerAddSublayer( layer, hoursLayer )
// Minutes layer
minutesLayer = fn CALayerInit
CALayerSetBackgroundColor( minutesLayer, fn ColorWhite )
CALayerSetAnchorPoint( minutesLayer, fn CGPointMake( 0.5, 0 ) )
CALayerSetPosition( minutesLayer, fn CGPointMake( frame.size.width / 2, frame.size.height / 2 ) )
CALayerSetBounds( minutesLayer, fn CGRectMake( 0, 0, 6, frame.size.width / 2 -45 ) )
CALayerSetCornerRadius( minutesLayer, 3.0 )
CALayerAddSublayer( layer, minutesLayer )
// Seconds layer
secondsLayer = fn CALayerInit
CALayerSetBackgroundColor( secondsLayer, fn ColorWithRGB( 0.502, 0.000, 0.251, 1.0 ) )
CALayerSetAnchorPoint( secondsLayer, fn CGPointMake( 0.5, 0 ) )
CALayerSetPosition( secondsLayer, fn CGPointMake( frame.size.width / 2, frame.size.height / 2 ) )
CALayerSetBounds( secondsLayer, fn CGRectMake( 0, 0, 3, frame.size.width / 2 -35 ) )
CALayerAddSublayer( layer, secondsLayer )
// Timing functions and calculations
dt = fn CalendarStartOfDayForDate( fn CalendarCurrent, fn DateInit )
ti = fn DateTimeIntervalSinceDate( fn DateInit, dt )
h = ti / 3600.0
m = ( h - int(h) ) * 60.0
s = ( m - int(m) ) * 60.0
ha = h / 12.0 * 360.0
ma = m / 60.0 * 360.0
sa = s / 60.0 * 360.0
// Rotation calculation
CALayerSetTransform( secondsLayer, fn CATransform3DMakeRotation( sa / 180.0 * PI, 0, 0, 1 ) )
CALayerSetTransform( minutesLayer, fn CATransform3DMakeRotation( ma / 180.0 * PI, 0, 0, 1 ) )
CALayerSetTransform( hoursLayer, fn CATransform3DMakeRotation( ha / 180.0 * PI, 0, 0, 1 ) )
// Animations for each clock hand
secondsAnimation = fn CABasicAnimationWithKeyPath( @"transform.rotation.z" )
CAMediaTimingSetRepeatCount( secondsAnimation, INFINITY )
CAMediaTimingSetDuration( secondsAnimation, 60 )
CAAnimationSetRemovedOnCompletion( secondsAnimation, NO )
CABasicAnimationSetFromValue( secondsAnimation, @( -sa * PI / 180 ) )
CABasicAnimationSetByValue( secondsAnimation, @( -2 * PI ) )
CAAnimationSetTimingFunction( secondsAnimation, fn CAMediaTimingFunctionWithName( kCAMediaTimingFunctionLinear ) )
CALayerAddAnimation( secondsLayer, secondsAnimation, @"SecondAnimationKey" )
minutesAnimation = fn CABasicAnimationWithKeyPath( @"transform.rotation.z" )
CAMediaTimingSetRepeatCount( minutesAnimation, INFINITY )
CAMediaTimingSetDuration( minutesAnimation, 60 * 60 )
CAAnimationSetRemovedOnCompletion( minutesAnimation, NO )
CABasicAnimationSetFromValue( minutesAnimation, @( -ma * PI / 180 ) )
CABasicAnimationSetByValue( minutesAnimation, @( -2 * PI ) )
CAAnimationSetTimingFunction( minutesAnimation, fn CAMediaTimingFunctionWithName( kCAMediaTimingFunctionLinear ) )
CALayerAddAnimation( minutesLayer, minutesAnimation, @"MinutesAnimationKey" )
hoursAnimation = fn CABasicAnimationWithKeyPath( @"transform.rotation.z" )
CAMediaTimingSetRepeatCount( hoursAnimation, INFINITY )
CAMediaTimingSetDuration( hoursAnimation, 60 * 60 * 12 )
CAAnimationSetRemovedOnCompletion( hoursAnimation, NO )
CABasicAnimationSetFromValue( hoursAnimation, @( -ha * PI / 180 ) )
CABasicAnimationSetByValue( hoursAnimation, @( -2 * PI ) )
CAAnimationSetTimingFunction( hoursAnimation, fn CAMediaTimingFunctionWithName( kCAMediaTimingFunctionLinear ) )
CALayerAddAnimation( hoursLayer, hoursAnimation, @"HoursAnimationKey" )
// Center hub
hubLayer = fn CAShapeLayerInit
r = fn CGRectMake( 244, 242, 16, 16 )
hub = fn BezierPathWithOvalInRect( r )
CAShapeLayerSetPath( hubLayer, hub )
CAShapeLayerSetLineWidth( hubLayer, 1.5 )
CAShapeLayerSetFillColor( hubLayer, fn ColorBlack )
CALayerAddSublayer( layer, hubLayer )
end fn
 
 
local fn DoDialog( ev as long, tag as long )
select ( ev )
case _viewWantsUpdateLayer : DialogEventSetBool(YES)
case _windowWillClose : end
end select
end fn
 
on dialog fn DoDialog
 
fn BuildWindow
 
HandleEvents
</syntaxhighlight>
{{output}}
[[File:Clock in FutureBasic.png]]
 
 
 
=={{header|Go}}==
Line 3,690 ⟶ 4,022:
==={{libheader|LÖVE}}===
Several nice clocks in the [http://love2d.org/forums/viewtopic.php?f=5&t=77346 LÖVE-forum]
 
 
=={{header|M2000 Interpreter}}==
 
Low demand for CPU. A LED style clock. Using Space Bar we can tongle the backround from BLACK to Transparent. Esc for quit.
[[File:DrawClockM2000.png|thumb|center]]
 
 
<syntaxhighlight lang="m2000 interpreter">
\\ if you have two monitors:
\\ Window mode, 1 \\ mode is a read only variable return the size of current font
// Window mode, 2 // selecet monitor 2
cls, 0
window 6, window
 
Module Led_Clock{
Escape Off
Smooth off
Dim D(-1 to 9)
D(-1)=(0,0,0,0,0,0,0)
D(0)=(1,1,1,0,1,1,1)
D(1)=(0,0,1,0,0,1,0)
D(2)=(1,0,1,1,1,0,1)
D(3)=(1,0,1,1,0,1,1)
D(4)=(0,1,1,1,0,1,0)
D(5)=(1,1,0,1,0,1,1)
D(6)=(1,1,0,1,1,1,1)
D(7)=(1,0,1,0,0,1,0)
D(8)=(1,1,1,1,1,1,1)
D(9)=(1,1,1,1,0,1,1)
N=240
XX=(scale.x-N*75) div 2
YY=scale.y-N*22
NN=N
BackColor=0
CLS BackColor, 0
Back {CLS BackColor,0}
desktop 255, BackColor
Forecolor=12
C=BackColor-Forecolor
pen BackColor
for i=0 to 9: cc=d(i): cc*=c:next
m=1
move XX+N*23.2, YY+N*5.2
polygon BackColor-C, N,-N, N,N, -N, N, -N, -N
move XX+N*23.2,YY+N*13.2
polygon BackColor-C, N,-N, N,N, -N, N, -N, -N
move XX+N*49.2,YY+N*5.2
polygon BackColor-C, N,-N, N,N, -N, N, -N, -N
move XX+N*49.2,YY+N*13.2
polygon BackColor-C, N,-N, N,N, -N, N, -N, -N
dsk=True
every 1000/2 {
k=now
k1=val(str$(k, "hh"))
k2=val(str$(k, "nn"))
k3=val(str$(k, "ss"))
LED(XX, D(k1 div 10))
LED(XX+N*12, D(k1 mod 10))
LED(XX+N*26, D(k2 div 10))
LED(XX+N*38, D(k2 mod 10))
LED(XX+N*52, D(k3 div 10))
LED(XX+N*64, D(k3 mod 10))
refresh 1000
if keypress(32) then
dsk~
if dsk then desktop 255 else desktop 255, BackColor
end if
if keypress(27) or mouse=2 then exit
}
desktop 255
pen 14
refresh 50
mode 16
wait 1000
Escape On
 
sub LED(XX, S())
move XX+N*1.2, YY+NN
\\ LED - UPPER
polygon BackColor-S(0), N,-N,N*6,0, N,N, -N, N,-N*6,0, -N, -N
\\ LED | LEFT UPPER
move XX+N*1.2-N*1.2, YY+N*1.2+NN
polygon BackColor-S(1), N,-N,N,N,0,N*6,-N, N, -N, -N, 0, -N*6
move XX+N*1.2+N*7.2, YY+N*1.2+NN
\\ LED | RIGHT UPPER
polygon BackColor-S(2), N,-N,N,N,0,N*6,-N, N, -N, -N, 0, -N*6
move XX+N*1.2, YY+N*8.4+NN
\\ LED - MIDDLE
polygon BackColor-S(3), N,-N,N*6,0, N,N, -N, N,-N*6,0, -N, -N
\\ LED | LEFT BOTTOM
move XX+N*1.2-N*1.2, YY+N*9.6+NN
polygon BackColor-S(4), N,-N,N,N,0,N*6,-N, N, -N, -N, 0, -N*6
\\ LED | RIGHT BOTTOM
move XX+N*1.2+N*7.2, YY+N*9.6+NN
polygon BackColor-S(5), N,-N,N,N,0,N*6,-N, N, -N, -N, 0, -N*6
\\ LED - BOTTOM
move XX+N*1.2, YY+N*16.8+NN
polygon BackColor-S(6), N,-N,N*6,0, N,N, -N, N,-N*6,0, -N, -N
end sub
}
Led_Clock
</syntaxhighlight>
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
Line 4,908 ⟶ 5,343:
There is a 3D analog clock in the
[http://www.vpython.org/contents/contributed/cxvp_clock.py VPython contributed section]
 
=={{header|Quackery}}==
 
<syntaxhighlight lang="Quackery"> [ $ "turtleduck.qky" loadfile
$ "bigrat.qky" loadfile ] now!
 
[ $ \
import datetime
sec = datetime.timedelta(seconds=1)
time_will_be = datetime.datetime.now()+sec
hours = time_will_be.hour
minutes = time_will_be.minute
seconds = time_will_be.second
to_stack([hours, minutes, seconds])
\ python ] is time+1 ( --> [ )
 
 
[ $ \
import time
current_time = time.time()
time_to_sleep = 1.0 - (current_time % 1.0)
time.sleep(time_to_sleep)
\ python ] is wait ( --> )
 
[ 3 wide
60 times
[ 240 1 fly
10 1 walk
-250 1 fly
1 60 turn ]
7 wide
12 times
[ 235 1 fly
12 1 walk
-247 1 fly
1 12 turn ]
9 wide
4 times
[ 233 1 fly
14 1 walk
-247 1 fly
1 4 turn ]
1 wide
' [ 0 0 0 ] fill
[ 10 1 circle ] ] is face ( --> )
 
[ 12 wide
unpack rot dip
[ 43200 rot
720 v+ ]
12 v+
2dup turn
175 1 walk
-175 1 fly
-v turn ] is hour ( [ --> )
 
[ 8 wide
unpack rot drop
3600 rot
60 v+
2dup turn
200 1 walk
-200 1 fly
-v turn ] is minute ( [ --> )
 
[ 4 wide
2 peek
dup 60 turn
225 1 walk
-225 1 fly
negate 60 turn ] is second ( [ --> )
 
[ turtle
0 frames
[ clear -1 4 turn
face
time+1 dup dup
second minute hour
wait
frame 1 4 turn again ] ] is clock ( --> )</syntaxhighlight>
 
{{out}}
 
https://youtu.be/Z0XS9EnADGE
 
The audio, On the Teeth of Wheels by Beat Frequency, is a sonification of the [[Stern-Brocot sequence#Quackery]]. It was discovered independently by Moritz Stern (1858) and Achille Brocot (1861), along with its visualisation, the Stern-Brocot tree. Brocot was a watchmaker, and used the sequence to find best approximations for gear ratios.
 
The book "A Treatise On The Teeth of Wheels, Demonstrating The Best Form Which Can Be Given To Them For The Purposes Of Machinery; Such As Clockwork And Millwork, And The Art Of Finding Their Numbers" predates the sequence, being written by Charles Étienne Louis Camus in 1749-1752, (and translated from French to English by John Isaac Hawkins in 1873), but shows a method relying in part on guesswork to achieve the same end.
 
=={{header|Racket}}==
Line 4,993 ⟶ 5,516:
<pre>⠀⢺⠀ ⢀⠔⡇ ⠀⠶⠀ ⠊⠉⡱ ⠊⣉⡱ ⠀⠶⠀ ⣏⣉⡉ ⡎⢉⢵
⢀⣸⣀ ⠉⠉⡏ ⠀⠶⠀ ⣔⣉⣀ ⢄⣀⡸ ⠀⠶⠀ ⢄⣀⡸ ⢗⣁⡸</pre>
 
A simpler version that does not clear the screen:
 
<syntaxhighlight lang=raku>constant @t = < ⡎⢉⢵ ⠀⢺⠀ ⠊⠉⡱ ⠊⣉⡱ ⢀⠔⡇ ⣏⣉⡉ ⣎⣉⡁ ⠊⢉⠝ ⢎⣉⡱ ⡎⠉⢱ ⠀⠶⠀>;
constant @b = < ⢗⣁⡸ ⢀⣸⣀ ⣔⣉⣀ ⢄⣀⡸ ⠉⠉⡏ ⢄⣀⡸ ⢇⣀⡸ ⢰⠁⠀ ⢇⣀⡸ ⢈⣉⡹ ⠀⠶⠀>;
 
signal(SIGINT).tap: { print "\e[?25h\n"; exit }
print "\e7\e[?25l"; # saves cursor position, make it invisible
loop {
my @x = DateTime.now.Str.substr(11,8).ords X- ord('0');
put ~.[@x] for @t, @b;
sleep 1;
print "\e8"; # restores cursor position
}</syntaxhighlight>
 
Finally a more minimalist version that shows three progress bars (hours, minutes, seconds):
<syntaxhighlight lang=raku>print "\e7";
loop {
my $time = DateTime.now;
put '#' x $_ ~ '.' x (24 - $_) given $time.hour.round;
put '#' x $_ ~ '.' x (60 - $_) given $time.minute.round;
put '#' x $_ ~ '.' x (60 - $_) given $time.second.round;
sleep 1;
print "\e8";
}
END put "\n";</syntaxhighlight>
 
=={{header|Red}}==
Line 5,649 ⟶ 6,198:
clear(curr_win, BACKGROUND);
KEYBOARD := GRAPH_KEYBOARD;
command := busy_getcgetc(KEYBOARD, NO_WAIT);
while command <> 'q' do
start_time := truncToSecond(time(NOW));
Line 5,691 ⟶ 6,240:
fcircle(100, 100, 7, CLOCKCOLOR);
circle(100, 100, 7, FOREGROUND);
DRAW_FLUSHflushGraphic;
await(start_time + 1 . SECONDS);
command := busy_getcgetc(KEYBOARD, NO_WAIT);
end while;
end func;</syntaxhighlight>
Line 5,916 ⟶ 6,465:
 
</pre>
 
=={{header|V (Vlang)}}==
<syntaxhighlight lang="Go">
// Written by Stefan Schroeder in 2021 for the v project examples.
// github.com/vlang/v/blob/master/examples/clock/clock.v
import os
import gg
import gx
import math
import time
 
const (
// All coordinates are designed for a clock size of this many pixel.
// You cannot change the size of the clock by adjusting this value.
design_size = 700
center = 350
 
// Half the width of a tic-mark.
tw = 9
// Height of a minute tic-mark. (hour is twice, 3-hour is thrice)
th = 25
// Padding of tic-mark to window border
tp = 10
 
tic_color = gx.Color{
r: 50
g: 50
b: 50
}
hand_color = gx.black
second_hand_color = gx.red
)
 
struct App {
minutes_tic []f32 = [f32(center - tw), tp, center + tw, tp, center + tw, tp, center + tw,
tp + 1 * th, center - tw, tp + 1 * th]
hours_tic []f32 = [f32(center - tw), tp, center + tw, tp, center + tw, tp, center + tw, tp + 2 * th,
center - tw, tp + 2 * th]
hours3_tic []f32 = [f32(center - tw), tp, center + tw, tp, center + tw, tp, center + tw, tp + 3 * th,
center - tw, tp + 3 * th]
 
hour_hand []f32 = [f32(329), 161, 350, 140, 371, 161, 371, 413, 329, 413]
minute_hand []f32 = [f32(334.25), 40.25, 350, 24.5, 365.75, 40.25, 365.75, 427, 334.25, 427]
second_hand []f32 = [f32(345.8), 38.5, 350, 34.3, 354.2000, 38.5, 358.75, 427, 341.25, 427]
mut:
gg &gg.Context = unsafe { nil }
draw_flag bool = true
dpi_scale f32 = 1.0
}
 
fn on_frame(mut app App) {
if !app.draw_flag {
return
}
app.gg.begin()
 
for i in 0 .. 60 { // draw minute tics
draw_convex_poly_rotate(mut app.gg, app.dpi_scale, app.minutes_tic, tic_color,
i * 6)
}
for i in 0 .. 12 { // hours
draw_convex_poly_rotate(mut app.gg, app.dpi_scale, app.hours_tic, tic_color, i * 30)
}
for i in 0 .. 4 { // 3 hours
draw_convex_poly_rotate(mut app.gg, app.dpi_scale, app.hours3_tic, tic_color,
i * 90)
}
 
n := time.now()
 
// draw hour hand
i := f32(n.hour) + f32(n.minute) / 60.0
draw_convex_poly_rotate(mut app.gg, app.dpi_scale, app.hour_hand, hand_color, i * 30)
 
// draw minute hand
mut j := f32(n.minute)
if n.second == 59 { // make minute hand move smoothly
j += f32(math.sin(f32(n.microsecond) / 1e6 * math.pi / 2.0))
}
draw_convex_poly_rotate(mut app.gg, app.dpi_scale, app.minute_hand, hand_color, j * 6)
 
// draw second hand with smooth transition
k := f32(n.second) + f32(math.sin(f32(n.microsecond) / 1e6 * math.pi / 2.0))
draw_convex_poly_rotate(mut app.gg, app.dpi_scale, app.second_hand, second_hand_color,
0 + k * 6)
 
app.gg.end()
}
 
// Rotate a polygon round the centerpoint
[manualfree]
fn draw_convex_poly_rotate(mut ctx gg.Context, dpi_scale f32, points []f32, c gx.Color, angle f32) {
sa := math.sin(math.pi * angle / 180.0)
ca := math.cos(math.pi * angle / 180.0)
 
mut rotated_points := []f32{cap: points.len}
for i := 0; i < points.len / 2; i++ {
x := points[2 * i]
y := points[2 * i + 1]
xn := f32((x - center) * ca - (y - center) * sa)
yn := f32((x - center) * sa + (y - center) * ca)
rotated_points << (xn + center) * dpi_scale
rotated_points << (yn + center) * dpi_scale
}
ctx.draw_convex_poly(rotated_points, c)
unsafe { rotated_points.free() }
}
 
fn (mut app App) resize() {
size := gg.window_size()
// avoid calls when minimized
if size.width < 2 && size.height < 2 {
return
}
w := f32(size.width) / design_size
h := f32(size.height) / design_size
app.dpi_scale = if w < h { w } else { h }
}
 
fn on_event(e &gg.Event, mut app App) {
match e.typ {
.resized, .resumed {
app.resize()
}
.iconified {
app.draw_flag = false
}
.restored {
app.draw_flag = true
app.resize()
}
else {
if e.typ == .key_down {
match e.key_code {
.q {
println('Good bye.')
// do we need to free anything here?
app.gg.quit()
}
else {}
}
}
}
}
}
 
fn on_init(mut app App) {
app.resize()
}
 
fn main() {
println("Press 'q' to quit.")
mut font_path := os.resource_abs_path(os.join_path('..', 'assets', 'fonts', 'RobotoMono-Regular.ttf'))
$if android {
font_path = 'fonts/RobotoMono-Regular.ttf'
}
 
mut app := &App{}
 
app.gg = gg.new_context(
width: design_size
height: design_size
window_title: 'Clock!'
bg_color: gx.white
user_data: app
frame_fn: on_frame
event_fn: on_event
init_fn: on_init
font_path: font_path
)
 
app.gg.run()
}
</syntaxhighlight>
 
=={{header|Wren}}==
{{trans|Kotlin}}
{{libheader|DOME}}
<syntaxhighlight lang="ecmascriptwren">import "graphics" for Canvas, Color
import "dome" for Window
import "math" for Math
Line 5,998 ⟶ 6,721:
 
=={{header|Yabasic}}==
===digital clock===
<syntaxhighlight lang="yabasic">clear screen
open window 300,100
Line 6,032 ⟶ 6,756:
exit
end if</syntaxhighlight>
 
===graphical analog clock===
<syntaxhighlight lang="yabasic">
#!/usr/bin/yabasic
REM yaclock
DEG_PER_RAD = 57.257751
 
winx = 480
winy = 480
 
radius = min(winx,winy) / 2 - 1
hx = (winx/2) - 1
hy = (winy/2) - 1
 
REM length of the hands (90% of the radius of the clock face)
shand = int(radius * .9)
mhand = int(radius * .9)
hhand = int(radius * .5)
 
REM drop coords by one since graphics are 0 based
 
winx = winx - 1
winy = winy - 1
 
clear screen
 
open window winx,winy
 
clockface()
 
do
 
hour = val(mid$(time$,1,2))
mins = val(mid$(time$,4,2))
sec = val(mid$(time$,7,2))
updatehand("sec")
updatehand("mins")
updatehand("hour")
 
pause .25
 
loop
 
sub updatehand(hand$)
switch(hand$)
case "sec"
h_len = shand
angle = sec * 6
width = 6
color 255,0,0
ox = osx
oy = osy
oxm1 = osxm1
oxm2 = osxm2
oym1 = osym1
oym2 = osym2
break
case "mins"
h_len = mhand
angle = mins * 6 + int(sec/10)
width = 12
color 0,255,0
ox = omx
oy = omy
oxm1 = omxm1
oxm2 = omxm2
oym1 = omym1
oym2 = omym2
break
case "hour"
h_len = hhand
angle = ((hour * 30) + (minutes / 12) * 6) + int(mins/2)
width = 15
color 0,0,255
ox = ohx
oy = ohy
oxm1 = ohxm1
oxm2 = ohxm2
oym1 = ohym1
oym2 = ohym2
break
end switch
 
h_angle1 = angle - width
if h_angle1 < 0 then
h_angle1 = h_angle1 + 360
endif
h_angle1 = h_angle1 / DEG_PER_RAD
h_angle2 = angle + width
if h_angle2 > 360 then
h_angle2 = h_angle2 - 360
endif
h_angle2 = h_angle2 / DEG_PER_RAD
angle = angle / DEG_PER_RAD
x = (hx + (sin(angle) * h_len))
xm1 = (hx + (sin(h_angle1) * int(h_len * .2)))
xm2 = (hx + (sin(h_angle2) * int(h_len * .2)))
 
y = (hy - (cos(angle) * h_len))
ym1 = (hy - (cos(h_angle1) * int(h_len * .2)))
ym2 = (hy - (cos(h_angle2) * int(h_len * .2)))
 
clear line hx,hy,oxm1,oym1
clear line hx,hy,oxm2,oym2
clear line oxm1,oym1,ox,oy
clear line oxm2,oym2,ox,oy
line hx,hy,xm1,ym1
line hx,hy,xm2,ym2
line xm1,ym1,x,y
line xm2,ym2,x,y
REM save off the old vals
switch(hand$)
case "sec"
osx = x
osy = y
osxm1 = xm1
osxm2 = xm2
osym1 = ym1
osym2 = ym2
break
case "mins"
omx = x
omy = y
omxm1 = xm1
omxm2 = xm2
omym1 = ym1
omym2 = ym2
break
case "hour"
ohx = x
ohy = y
ohxm1 = xm1
ohxm2 = xm2
ohym1 = ym1
ohym2 = ym2
break
end switch
end sub
 
sub clockface()
circle hx,hy,radius
htick = radius / 10
mtick = htick / 2
for z=0 to 360 step 6
REM Begin at zero deg and stop before 360 deg
 
REM draw the hour markers
angle = z
angle = angle / DEG_PER_RAD
x2 = (hx + (sin(angle) * radius))
y2 = (hy - (cos(angle) * radius))
if mod(z,30) = 0 then
tick = htick
else
tick = mtick
endif
x3 = (hx + (sin(angle) * (radius - tick)))
y3 = (hy - (cos(angle) * (radius - tick)))
color 255,0,0
line x2,y2,x3,y3
color 0,0,0
next z
end sub
 
</syntaxhighlight>
 
=={{header|zkl}}==
29

edits