Data update

This commit is contained in:
Ingy döt Net 2026-04-30 12:34:36 -04:00
parent 4bb20c9b71
commit cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions

View file

@ -0,0 +1,99 @@
with Ada.Numerics.Elementary_Functions;
with Ada.Calendar.Formatting;
with Ada.Calendar.Time_Zones;
with SDL.Video.Windows.Makers;
with SDL.Video.Renderers.Makers;
with SDL.Events.Events;
procedure Draw_A_Clock is
use Ada.Calendar;
use Ada.Calendar.Formatting;
Window : SDL.Video.Windows.Window;
Renderer : SDL.Video.Renderers.Renderer;
Event : SDL.Events.Events.Events;
Offset : Time_Zones.Time_Offset;
procedure Draw_Clock (Stamp : Time)
is
use SDL.C;
use Ada.Numerics.Elementary_Functions;
Radi : constant array (0 .. 59) of int := (0 | 15 | 30 | 45 => 2,
5 | 10 | 20 | 25 | 35 | 40 | 50 | 55 => 1,
others => 0);
Diam : constant array (0 .. 59) of int := (0 | 15 | 30 | 45 => 5,
5 | 10 | 20 | 25 | 35 | 40 | 50 | 55 => 3,
others => 1);
Width : constant int := Window.Get_Surface.Size.Width;
Height : constant int := Window.Get_Surface.Size.Height;
Radius : constant Float := Float (int'Min (Width, Height));
R_1 : constant Float := 0.48 * Radius;
R_2 : constant Float := 0.35 * Radius;
R_3 : constant Float := 0.45 * Radius;
R_4 : constant Float := 0.47 * Radius;
Hour : constant Hour_Number := Formatting.Hour (Stamp, Offset);
Minute : constant Minute_Number := Formatting.Minute (Stamp, Offset);
Second : constant Second_Number := Formatting.Second (Stamp);
function To_X (A : Float; R : Float) return int is
(Width / 2 + int (R * Sin (A, 60.0)));
function To_Y (A : Float; R : Float) return int is
(Height / 2 - int (R * Cos (A, 60.0)));
begin
SDL.Video.Renderers.Makers.Create (Renderer, Window.Get_Surface);
Renderer.Set_Draw_Colour ((0, 0, 150, 255));
Renderer.Fill (Rectangle => (0, 0, Width, Height));
Renderer.Set_Draw_Colour ((200, 200, 200, 255));
for A in 0 .. 59 loop
Renderer.Fill (Rectangle => (To_X (Float (A), R_1) - Radi (A),
To_Y (Float (A), R_1) - Radi (A), Diam (A), Diam (A)));
end loop;
Renderer.Set_Draw_Colour ((200, 200, 0, 255));
Renderer.Draw (Line => ((Width / 2, Height / 2),
(To_X (5.0 * (Float (Hour) + Float (Minute) / 60.0), R_2),
To_Y (5.0 * (Float (Hour) + Float (Minute) / 60.0), R_2))));
Renderer.Draw (Line => ((Width / 2, Height / 2),
(To_X (Float (Minute) + Float (Second) / 60.0, R_3),
To_Y (Float (Minute) + Float (Second) / 60.0, R_3))));
Renderer.Set_Draw_Colour ((220, 0, 0, 255));
Renderer.Draw (Line => ((Width / 2, Height / 2),
(To_X (Float (Second), R_4),
To_Y (Float (Second), R_4))));
Renderer.Fill (Rectangle => (Width / 2 - 3, Height / 2 - 3, 7, 7));
end Draw_Clock;
function Poll_Quit return Boolean is
use type SDL.Events.Event_Types;
begin
while SDL.Events.Events.Poll (Event) loop
if Event.Common.Event_Type = SDL.Events.Quit then
return True;
end if;
end loop;
return False;
end Poll_Quit;
begin
Offset := Time_Zones.UTC_Time_Offset;
if not SDL.Initialise (Flags => SDL.Enable_Screen) then
return;
end if;
SDL.Video.Windows.Makers.Create (Win => Window,
Title => "Draw a clock",
Position => SDL.Natural_Coordinates'(X => 10, Y => 10),
Size => SDL.Positive_Sizes'(300, 300),
Flags => SDL.Video.Windows.Resizable);
loop
Draw_Clock (Clock);
Window.Update_Surface;
delay 0.200;
exit when Poll_Quit;
end loop;
Window.Finalize;
SDL.Finalise;
end Draw_A_Clock;

View file

@ -0,0 +1,87 @@
package clock
import rl "vendor:raylib"
import "core:time"
import "core:time/datetime"
import "core:time/timezone"
import "core:os"
import "core:math"
TimePeriod :: enum {
AM,
PM
}
DistanceAngle :: proc(distance: f32, angle: f32) -> (vector: rl.Vector2) {
vector.x = math.sin_f32(angle)
vector.y = -math.cos_f32(angle)
vector *= distance
return
}
main :: proc() {
tz, ok := timezone.region_load("local")
rl.SetConfigFlags({.MSAA_4X_HINT})
rl.InitWindow(640, 480, "Rosetta Code - draw a clock")
screen_center := rl.Vector2 {f32(rl.GetScreenWidth()) / 2, f32(rl.GetScreenHeight()) / 2}
for !rl.WindowShouldClose() {
rl.BeginDrawing()
rl.ClearBackground(rl.RAYWHITE)
conversion_succeeded: bool = true
date_time: datetime.DateTime
date_time, ok = time.time_to_datetime(time.now())
if !ok do conversion_succeeded = false
date_time, ok = timezone.datetime_to_tz(date_time, tz)
if !ok do conversion_succeeded = false
regular_time: time.Time
regular_time, ok = time.datetime_to_time(date_time)
if !ok do conversion_succeeded = false
if !conversion_succeeded do os.exit(1)
period: TimePeriod
hour, min, sec := time.clock_from_time(regular_time)
if hour > 12 {
hour -= 12
period = .PM
}
radius := f32(rl.GetScreenHeight()) / 2.5
rl.DrawCircleV(screen_center, radius, rl.LIGHTGRAY)
rl.DrawLineEx(screen_center, screen_center + DistanceAngle(radius * .75, (f32(hour) / 12) * math.TAU), 4, rl.BLACK)
rl.DrawLineEx(screen_center, screen_center + DistanceAngle(radius * .7, (f32(min) / 60) * math.TAU), 4, rl.DARKGREEN)
rl.DrawLineEx(screen_center, screen_center + DistanceAngle(radius * .5, (f32(sec) / 60) * math.TAU), 4, rl.RED)
for i := 0; i < 60; i += 1 {
angle := (f32(i) / 60) * math.TAU
inside_distance: f32 = .8
thickness: f32 = 1.5
if i % 5 == 0 {
inside_distance = .775
thickness = 3
}
rl.DrawLineEx(screen_center + DistanceAngle(radius * inside_distance, angle), screen_center + DistanceAngle(radius * .95, angle), thickness, rl.DARKGRAY)
}
//fmt.printfln("%2d:%2d:%2d %s", hour, min, sec, period)
rl.EndDrawing()
}
rl.CloseWindow()
timezone.region_destroy(tz)
}

View file

@ -0,0 +1,29 @@
use utf8; # interpret source code as UTF8
binmode STDOUT, ':utf8'; # allow printing wide chars without warning
$|++; # disable output buffering
my ($rows, $cols) = split /\s+/, `stty size`;
my $x = int($rows / 2 - 1);
my $y = int($cols / 2 - 16);
my @chars = map {[ /(...)/g ]}
("┌─┐ ╷╶─┐╶─┐╷ ╷┌─╴┌─╴╶─┐┌─┐┌─┐ ",
"│ │ │┌─┘╶─┤└─┤└─┐├─┐ │├─┤└─┤ : ",
"└─┘ ╵└─╴╶─┘ ╵╶─┘└─┘ ╵└─┘╶─┘ ");
while (1) {
my @indices = map { ord($_) - ord('0') } split //,
sprintf("%02d:%02d:%02d", (localtime(time))[2,1,0]);
clear();
for (0 .. $#chars) {
position($x + $_, $y);
print "@{$chars[$_]}[@indices]";
}
position(1, 1);
sleep 1;
}
sub clear { print "\e[H\e[J" }
sub position { printf "\e[%d;%dH", shift, shift }

View file

@ -0,0 +1,22 @@
#!/usr/bin/perl
use strict; # https://rosettacode.org/wiki/Draw_a_clock
use warnings;
use Tk;
my $halfsize = 200;
my $twopi = 2 * atan2 0, -1;
my $mw = MainWindow->new;
my $c = $mw->Canvas( -width => 2 * $halfsize, -height => 2 * $halfsize)->pack;
$mw->repeat(1000 => \&draw);
MainLoop;
sub draw
{
$c->delete('all');
my $angle = time % 60 / 60 * $twopi;
$c->createLine( $halfsize, $halfsize,
$halfsize * (1 + sin $angle),
$halfsize * (1 - cos $angle),
-width => 5);
}

View file

@ -0,0 +1,26 @@
Rebol [
title: "Rosetta code: Draw a clock (CLI)"
file: %Draw_a_clock.r3
url: https://rosettacode.org/wiki/Draw_a_clock
]
;; two spaced-separated blocks of Braille-like glyphs (top and bottom halves for digits 0-9 and separator)
s: join { ⡎⢉⢵ ⠀⢺⠀ ⠊⠉⡱ ⠊⣉⡱ ⢀⠔⡇ ⣏⣉⡉ ⣎⣉⡁ ⠊⢉⠝ ⢎⣉⡱ ⡎⠉⢱ ⠀⠶ }
{ ⢗⣁⡸ ⢀⣸⣀ ⣔⣉⣀ ⢄⣀⡸ ⠉⠉⡏ ⢄⣀⡸ ⢇⣀⡸ ⢰⠁⠀ ⢇⣀⡸ ⢈⣉⡹ ⠀⠶ }
;; split the big string every 4 chars to get a block of 22 glyph cells (11 top + 11 bottom)
s: split s 4
forever [ ;; loop to update the clock every second
tm: format-date-time now "hh:mm:ss" ;; current time string, e.g., "12:34:56"
l1: clear "" ;; buffer for the top line of the big digits
l2: clear "" ;; buffer for the bottom line of the big digits
foreach c tm [ ;; for each character in the time string
i: 1 + c - #"0" ;; convert digit char to 1-based index
append l1 s/(i) ;; append top-half glyph for the digit (for ":" this will intentionally pick the separator at index 11)
append l2 s/(i + 11) ;; append bottom-half glyph (offset by 11 to access the lower row set)
]
print l1 ;; print top line of large digits
print l2 ;; print bottom line of large digits
wait 1 ;; pause one second
prin "^[[2A" ;; move cursor up 2 lines (ANSI escape) to overwrite in place next iteration
]

View file

@ -0,0 +1,96 @@
# Author: Gal Zsolt (CalmoSoft)
load "libsdl.ring"
load "stdlibcore.ring"
# Settings
screen_w = 640
screen_h = 480
xp = screen_w/2
yp = screen_h/2
size = 200
pi = 3.14159265
sdl_init(SDL_INIT_EVERYTHING)
window = sdl_createwindow("Analog Clock - CalmoSoft", 100, 100, screen_w, screen_h, SDL_WINDOW_SHOWN)
render = sdl_createrenderer(window, -1, SDL_RENDERER_ACCELERATED)
ev = sdl_new_sdl_event()
while true
# Event handling
sdl_pollevent(ev)
if sdl_get_sdl_event_type(ev) = SDL_QUIT exit ok
# Get system time
t = time()
h = 0 + substr(t,1,2)
m = 0 + substr(t,4,2)
s = 0 + substr(t,7,2)
# Clear background (Black)
sdl_setrenderdrawcolor(render, 0, 0, 0, 255)
sdl_renderclear(render)
# Draw the clock components
draw_clock(render, xp, yp, size, h, m, s, pi)
sdl_renderpresent(render)
sdl_delay(100)
end
# Clean up
sdl_destroyrenderer(render)
sdl_destroywindow(window)
sdl_quit()
func draw_clock render, x, y, r, h, m, s, pi
# 1. Draw Clock Face (White circle outline)
sdl_setrenderdrawcolor(render, 255, 255, 255, 255)
for i = 0 to 360 step 1
angle = i * pi / 180
sdl_renderdrawpoint(render, x + r * cos(angle), y + r * sin(angle))
next
# 2. Draw Hour Markers (Ticks)
sdl_setrenderdrawcolor(render, 255, 255, 255, 255)
for i = 1 to 12
angle = i * 30 * pi / 180
x1 = x + r * 0.95 * sin(angle)
y1 = y - r * 0.95 * cos(angle)
x2 = x + r * 0.85 * sin(angle)
y2 = y - r * 0.85 * cos(angle)
sdl_renderdrawline(render, x1, y1, x2, y2)
next
# Calculate angles for hands
s_angle = (s / 60) * 2 * pi
m_angle = ((m + s/60) / 60) * 2 * pi
h_angle = ((h % 12 + m/60) / 12) * 2 * pi
# 3. Draw Hands (Thickened)
# Hour Hand (Green - thickest: 5px)
sdl_setrenderdrawcolor(render, 0, 255, 0, 255)
for i = -2 to 2
sdl_renderdrawline(render, x+i, y+i, x + r*0.5*sin(h_angle)+i, y - r*0.5*cos(h_angle)+i)
next
# Minute Hand (Blue - medium: 3px)
sdl_setrenderdrawcolor(render, 0, 100, 255, 255)
for i = -1 to 1
sdl_renderdrawline(render, x+i, y+i, x + r*0.8*sin(m_angle)+i, y - r*0.8*cos(m_angle)+i)
next
# Second Hand (Red - 2px)
sdl_setrenderdrawcolor(render, 255, 0, 0, 255)
for i = 0 to 1
sdl_renderdrawline(render, x+i, y+i, x + r*0.9*sin(s_angle)+i, y - r*0.9*cos(s_angle)+i)
next
# 4. Center Cap (Axis)
sdl_setrenderdrawcolor(render, 200, 200, 200, 255)
for i = 0 to 360 step 10
angle = i * pi / 180
for radius = 0 to 5
sdl_renderdrawpoint(render, x + radius * cos(angle), y + radius * sin(angle))
next
next

View file

@ -0,0 +1,70 @@
'ANSI Clock
'ansi escape functions
ans0=chr(27)&"["
sub cls() wscript.StdOut.Write ans0 &"2J"&ans0 &"?25l":end sub
sub torc(r,c,s) wscript.StdOut.Write ans0 & r & ";" & c & "f" & s :end sub
'bresenham
Sub draw_line(r1,c1, r2,c2,c)
Dim x,y,xf,yf,dx,dy,sx,sy,err,err2
x =r1 : y =c1
xf=r2 : yf=c2
dx=Abs(xf-x) : dy=Abs(yf-y)
If x<xf Then sx=+1: Else sx=-1
If y<yf Then sy=+1: Else sy=-1
err=dx-dy
Do
torc x,y,c
If x=xf And y=yf Then Exit Do
err2=err+err
If err2>-dy Then err=err-dy: x=x+sx
If err2< dx Then err=err+dx: y=y+sy
Loop
End Sub
const pi180=0.017453292519943
'center of the clock
const r0=13
const c0=26
'angles
nangi=-30*pi180
aangi=-6*pi180
ang0=90*pi180
'lengths of hands
lh=7
lm=9
ls=9
ln=12
while 1
cls
'dial
angn=ang0+nangi
for i=1 to 12
torc r0-cint(ln*sin(angn)),cint(c0+2*ln*cos(angn)),i
angn=angn+nangi
next
'get time and display it in numbers
t=now()
torc 1,1, hour(t) &":"& minute(t) &":"& second(t)
'angle for each hand
angh=ang0+hour(t) *nangi
angm=ang0+minute(t) *aangi
angS=ang0+second(t) *aangi
'draw them
draw_line r0,c0,cint(r0-ls*sin(angs)),cint(c0+2*ls*cos(angs)),"."
draw_line r0,c0,cint(r0-lm*sin(angm)),cint(c0+2*lm*cos(angm)),"*"
draw_line r0,c0,cint(r0-lh*sin(angh)),cint(c0+2*lh*cos(angh)),"W"
torc r0,c0,"O"
'wait one second
wscript.sleep(1000)
wend