Yesterday, 04:12 AM
(This post was last modified: Yesterday, 04:29 AM by 1micha.elok.)
Clock (repost and modified)
Repost from an old archive N7 Marcus
Date : 10-15-2022
Repost from an old archive N7 Marcus
Date : 10-15-2022
Code:
'====================================
'Clock (repost and modified)
'
'Repost from an old archive N7 Marcus
'Date : 10-15-2022
'
'Control key
'- ESC to quit
'====================================
'set window size
#win32
set window "Clock", 400, 400
set redraw off
'color definition
gray = [200,200,200]
black = [0,0,0]
white = [255,255,255]
red = [255,0,0]
yellow = [255,255,0]
green = [0,255,0]
orange = [255,165,0]
'font
bigfont = createfont("arial", 48, true, false, false, true)
'main loop
do
'background
set color black;cls
t = datetime()
'clock center
centerx = width()/2
centery = height()/3+20
'clock border
set color white
rx = width()/3
ry = height()/3
draw ellipse centerx, centery, rx, ry, true
'clock body
set color rnd(150,200),rnd(150,200),rnd(150,200) 'random color
draw ellipse centerx, centery, rx - 4, ry - 4, true
'clock marks
set color yellow
for i = 0 to 11
draw ellipse centerx+(rx-15)*cos(30/180*PI*i),centery+(ry-15)*sin(30/180*PI*i),4,4,true
next
set color black
i = t.hour-3
draw ellipse centerx+(rx-15)*cos(30/180*PI*i),centery+(ry-15)*sin(30/180*PI*i),6,6,true
'arrow second
set color red
a = rad(360*t.second/60 - 90)
DrawThickLine(centerx, centery, centerx + cos(a)*(centerx*0.6 - 4), centery + sin(a)*(centery*0.6 - 4), 2)
'arrow long hand
set color black
a = rad((t.minute/5*30) - 90)
DrawArrow(centerx, centery, centerx + cos(a)*(centerx*0.6 - 4), centery + sin(a)*(centery*0.6 - 4), 6)
'arrow short hand
set color black
a2 = rad(360*(t.hour%12)/12 - 90)+rad(((t.minute/5*30)+5 - 90)/12)
DrawArrow(centerx, centery, centerx + cos(a2)*(centerx*0.3 - 4), centery + sin(a2)*(centery*0.3 - 4), 5)
'clock center
set color black
draw ellipse centerx, centery, 8, 8, true
'digital clock
set color green
set font bigfont
set caret width()/2,height()-70
if len(t.hour) = 1 then
myhour = "0"+t.hour
else
myhour = t.hour
endif
if len(t.minute) = 1 then
myminute = "0"+t.minute
else
myminute = t.minute
endif
if len(t.second) = 1 then
mysecond = "0"+t.second
else
mysecond = t.second
endif
center myhour+":"+myminute+":"+mysecond
if keydown(KEY_ESCAPE,true) then end
redraw
fwait 1
loop
'functions
function DrawThickLine(x1, y1, x2, y2, thickness)
dx = x2 - x1
dy = y2 - y1
k = 0.5*thickness/sqr(dx*dx + dy*dy)
ddx = -dy*k
ddy = dx*k
p = [
round(x1 + ddx), round(y1 + ddy),
round(x2 + ddx), round(y2 + ddy),
round(x2 - ddx), round(y2 - ddy),
round(x1 - ddx), round(y1 - ddy)]
draw poly p, true
endfunc
function DrawArrow(x1, y1, x2, y2, thickness)
dx = x2 - x1
dy = y2 - y1
k = 0.5*thickness/sqr(dx*dx + dy*dy)
ddx = -dy*k
ddy = dx*k
p = [
x1, y1,
x1*0.25 + x2*0.75 - ddx, y1*0.25 + y2*0.75 - ddy,
x2, y2,
x1*0.25 + x2*0.75 + ddx, y1*0.25 + y2*0.75 + ddy]
draw poly p, true
endfunc