Clock (repost and modified) - 1micha.elok - 12-21-2024
Clock (repost and modified)
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
RE: Clock (repost and modified) - johnno56 - 12-21-2024
Ah, Timeless application... Moo Ha Ha Ha...
RE: Clock (repost and modified) - 1micha.elok - 12-21-2024
I'm thinking of making Klingon clock ....
RE: Clock (repost and modified) - 1micha.elok - 12-21-2024
Klingon Clock
click the image to zoom in
Code: '============================================================
'Klingon Clock
'
'References :
'- The Klingon Language Institute version of the pIqaD script
' https://en.wikipedia.org/wiki/Klingon_scripts
'============================================================
'set window size
#win32
set window "Klingon Clock", 545, 386
set redraw off
'color definition
black = [0,0,0]
white = [255,255,255]
green = [0,255,0]
darkgreen = [0,150,0,200]
'font
bigfont = createfont("arial", 20, false, false, false, false)
visible klingonScript = loadimage("assets/kscript.png",13,1)
'background
backImg = loadimage("assets/Kli_piqad.png")
'initial value
j = 0 'counter
'-----------
' MAIN LOOP
'-----------
do
'background
draw image backImg,0,0
'system date and time
t = datetime()
'klingon clock
for i = 1 to 10 step 4.2
set color darkgreen
draw rect 55+30*i,20,120,90,true
set color green
draw rect 55+30*i,20,120,90
next
convertKlingon(t.hour,90)
convertKlingon(t.minute,210)
convertKlingon(t.second,340)
'human digital clock
set color white
set font bigfont
set caret width()/2,120
myhour = needZero(t.hour)
myminute = needZero(t.minute)
mysecond = needZero(t.second)
center myhour+":"+myminute+":"+mysecond
if keydown(KEY_ESCAPE,true) then end
'just simple animation
set color green
if j >=80 then
j = 0
else
j = j + 1
endif
centerx = width()/4
centery = 250
r = 10+j
a = rad(360*t.second/60 - 90)
for i = 0 to 11
draw ellipse centerx+(r-15)*cos(30/180*PI*i),centery+(r-15)*sin(30/180*PI*i),2,2,true
draw ellipse 2*centerx+(r-15)*cos(30/180*PI*i),centery+(r-15)*sin(30/180*PI*i),2,2,true
draw ellipse 3*centerx+(r-15)*cos(30/180*PI*i),centery+(r-15)*sin(30/180*PI*i),2,2,true
draw line centerx, centery, centerx + cos(a)*(centerx*0.3), centery + sin(a)*(centery*0.3)
draw line 2*centerx, centery, centerx + cos(a)*(centerx*0.3), centery + sin(a)*(centery*0.3)
draw line 3*centerx, centery, centerx + cos(a)*(centerx*0.3), centery + sin(a)*(centery*0.3)
next
redraw
fwait 30
loop
'------------
' FUNCTIONS
'------------
function needZero(myclock)
if len(myclock) = 1 then
return "0"+myclock
else
return myclock
endif
endfunc
function convertKlingon(x,i)
if len(x) = 1 then
x1 = 0
x2 = x
else
x1 = left(x,1)
x2 = right(x,1)
endif
draw image klingonScript,10+i,40,x1
draw image klingonScript,50+i,40,x2
endfunc
RE: Clock (repost and modified) - johnno56 - 12-21-2024
Qapla'
|