Yet another clock

Post Reply
Henko
Posts: 834
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Yet another clock

Post by Henko »

Indeed, yet another clock.

IMG_1347.jpeg
IMG_1347.jpeg (189.69 KiB) Viewed 524 times
I saw it while visiting some bridge friends, and felt an iressistible urge to program it in SB.
IMG_1345.png
IMG_1345.png (485.12 KiB) Viewed 524 times
Here it is, be it the Dutch version.
The clock displays the time with text, in 5-minute intervals. The minutes within the 5-minute interval are displayed by little red spots in the corners of the panel. In the programmed version, a slider is added under the panel, to indicate the seconds within the current minute.
The program works well on iPhones and iPads.

Anyone who cares to do the English version?
The code for this Dutch version follows:

Code: Select all

' Another clock (Dutch version, for iPhones and iPads)
' Idea and physical versions by www.qlocktwo.com
' September 2025 by Henko

pR=0.75 ! pG=0.75 ! pB=0.75    ' panel color
cR=0 ! cG=0 ! cB=0.6           ' character color

init_prog()
ct$=get_clocktext$()
do slowdown
  u=current_hour() ! m=current_minute() ! s=current_second()
  if s<>so then ! seconds_bar(s) ! so=s ! end if
  if m=mo then continue else mo=m
  init_panel(ct$)
  if u=12 and m<16 then u=u else u=u%12 ! u1=u+1
  mm=m%5 ! m5=m-mm
  draw color cR,cG,cB ! draw alpha 1
  highlight(0,1,0,0)
  if m5=0  then highlight(.uur(u),22,0,0)
  if m5=5  then highlight( 2,5,.uur(u),0)
  if m5=10 then highlight(3,5,.uur(u),0)
  if m5=15 then highlight(6,8,.uur(u),0)
  if m5=20 then highlight(3,4,7,.uur(u1))
  if m5=25 then highlight(2,4,7,.uur(u1))
  if m5=30 then highlight(7,.uur(u1),0,0)
  if m5=35 then highlight(2,5,7,.uur(u1))
  if m5=40 then highlight(3,5,7,.uur(u1))
  if m5=45 then highlight(6,9,.uur(u1),0)
  if m5=50 then highlight(3,4,.uur(u1),0)
  if m5=55 then highlight(2,4,.uur(u1),0)
  corner(mm)
  until forever
end

def init_prog()
graphics ! graphics clear 1,1,1 ! draw color 0,0,0
set orientation portrait
get screen size .sw,.sh
.marge=int(.sw/56) ! .tl=.sw-2*.marge
.fs=.tl/6.615 ! .dx=0.6043*.fs ! .dy=0.65*.fs
.mo=-1
end def

def init_panel(t$)
fill color .pR,.pG,.pB
fill rect .marge,.marge to .sw-.marge,.sw-.marge
s=0
draw font size .fs ! draw color 0,0,0 ! draw alpha 0.1
for i=0 to 9
  y=.fs*i*0.65
  a$=mid$(t$,s,11) ! s+=11
  draw text a$ at .marge,y
  next i
end def

def highlight(a,b,c,d)
draw text .w$(a) at .marge+.wx(a)*.dx,.wy(a)*.dy
draw text .w$(b) at .marge+.wx(b)*.dx,.wy(b)*.dy
if c then draw text .w$(c) at .marge+.wx(c)*.dx,.wy(c)*.dy
if d then draw text .w$(d) at .marge+.wx(d)*.dx,.wy(d)*.dy
end def

def corner(k)
m=.marge
fill rect m,m to m+5,m+5
fill rect .sw-m-5,m to .sw-m,m+5
fill rect .sw-m-5,m+.tl-5 to .sw-m,m+.tl
fill rect m,m+.tl-5 to m+5,m+.tl
fill color 1,0,0
if k>=1 then fill rect m,m to m+5,m+5
if k>=2 then fill rect .sw-m-5,m to .sw-m,m+5
if k>=3 then fill rect .sw-m-5,m+.tl-5 to .sw-m,m+.tl
if k>=4 then fill rect m,m+.tl-5 to m+5,m+.tl
end def

def seconds_bar(s)
if not init then
  init=1 ! m=.marge ! y=.sw-m+20
  slider "seconds" value s/59 at m,y size .sw-2*m
  end if
slider "seconds" value s/59
end def

def get_clocktext$()
dim .w$(23),.wx(23),.wy(23),.uur(13)
for i=0 to 22 ! read .w$(i),.wx(i),.wy(i) ! next i
for i=1 to 12 ! read .uur(i) ! next i
data "HET",0,0,  "IS",4,0, "VIJF",7,0, "TIEN",0,1
data "VOOR",7,1, "OVER",0,2, "KWART",6,2, "HALF",0,3
data "OVER",7,3, "VOOR",0,4, "EEN",7,4, "TWEE",0,5
data "DRIE",7,5, "VIER",0,6, "VIJF",4,6, "ZES",8,6
data "ZEVEN",0,7, "NEGEN",6,7, "ACHT",0,8, "TIEN",4,8
data "ELF",8,8, "TWAALF",0,9, "UUR",8,9
data 10,11,12,13,14,15,16,18,17,19,20,21
t$=""
t$&="HETKISAVIJFTIENATZVOOR"
t$&="OVERMEKWARTHALFSPMOVER"
t$&="VOORTHGEENSTWEEAMCDRIE"
t$&="VIERVIJFZESZEVENONEGEN"
t$&="ACHTTIENELFTWAALFPMUUR"
return t$
end def

smbstarv
Posts: 100
Joined: Wed Nov 27, 2013 3:44 pm
My devices: Ipad 6th gen
Flag: Netherlands
Contact:

Re: Yet another clock

Post by smbstarv »

Funny !
This brightens my day....

Chooch912
Posts: 50
Joined: Thu Apr 12, 2018 6:16 pm
My devices: iPad
Flag: United States of America

Re: Yet another clock

Post by Chooch912 »

Revised- Sept 7, 3:25 Eastern time US.

Okay, I got some of the program into English.
I noticed that when the time is showing as "TEN BEFORE HALF" & "FIVE BEFORE HALF" my hour is off by 1 ahead.
I just noticed when I run the Dutch version, it is also 1 hour ahead when close to "HALF" hour.
Henko, what do I need to do to correct that?

As you can see, I am not very skilled with !BASIC (my experience in programming was in Business Basic which did not have near the functionality !BASIC does. But I am trying to learn by referencing your works. Thank you!)
————
'' Another clock (English version, for iPhones and iPads)
' Idea physical versions by www.qlocktwo.com
' Original Dutch version by Henko
' Attempt in English by Chooch912

pR=0.75 ! pG=0.75 ! pB=0.75 ' panel color
cR=0 ! cG=0 ! cB=0.6 ' character color

init_prog()
ct$=get_clocktext$()
do slowdown
u=current_hour() ! m=current_minute() ! s=current_second()
if s<>so then ! seconds_bar(s) ! so=s ! end if
if m=mo then continue else mo=m
init_panel(ct$)
if u=12 and m<16 then u=u else u=u%12 ! u1=u+1
mm=m%5 ! m5=m-mm
draw color cR,cG,cB ! draw alpha 1
highlight(0,1,0,0)
if m5=0 then highlight(.uur(u),22,0,0)
if m5=5 then highlight( 2,5,.uur(u),0)
if m5=10 then highlight(3,5,.uur(u),0)
if m5=15 then highlight(6,8,.uur(u),0)
if m5=20 then highlight(3,4,7,.uur(u1))
if m5=25 then highlight(2,4,7,.uur(u1))
if m5=30 then highlight(7,.uur(u1),0,0)
if m5=35 then highlight(2,5,7,.uur(u1))
if m5=40 then highlight(3,5,7,.uur(u1))
if m5=45 then highlight(6,9,.uur(u1),0)
if m5=50 then highlight(3,4,.uur(u1),0)
if m5=55 then highlight(2,4,.uur(u1),0)
corner(mm)
until forever
end

def init_prog()
graphics ! graphics clear 1,1,1 ! draw color 0,0,0
set orientation portrait
get screen size .sw,.sh
.marge=int(.sw/56) ! .tl=.sw-2*.marge
.fs=.tl/6.615 ! .dx=0.6043*.fs ! .dy=0.65*.fs
.mo=-1
end def

def init_panel(t$)
fill color .pR,.pG,.pB
fill rect .marge,.marge to .sw-.marge,.sw-.marge
s=0
draw font size .fs ! draw color 0,0,0 ! draw alpha 0.1
for i=0 to 9
y=.fs*i*0.65
a$=mid$(t$,s,11) ! s+=11
draw text a$ at .marge,y
next i
end def

def highlight(a,b,c,d)
draw text .w$(a) at .marge+.wx(a)*.dx,.wy(a)*.dy
draw text .w$(b) at .marge+.wx(b)*.dx,.wy(b)*.dy
if c then draw text .w$(c) at .marge+.wx(c)*.dx,.wy(c)*.dy
if d then draw text .w$(d) at .marge+.wx(d)*.dx,.wy(d)*.dy
end def

def corner(k)
m=.marge
fill rect m,m to m+5,m+5
fill rect .sw-m-5,m to .sw-m,m+5
fill rect .sw-m-5,m+.tl-5 to .sw-m,m+.tl
fill rect m,m+.tl-5 to m+5,m+.tl
fill color 1,0,0
if k>=1 then fill rect m,m to m+5,m+5
if k>=2 then fill rect .sw-m-5,m to .sw-m,m+5
if k>=3 then fill rect .sw-m-5,m+.tl-5 to .sw-m,m+.tl
if k>=4 then fill rect m,m+.tl-5 to m+5,m+.tl
end def

def seconds_bar(s)
if not init then
init=1 ! m=.marge ! y=.sw-m+20
slider "seconds" value s/59 at m,y size .sw-2*m
end if
slider "seconds" value s/59
end def

def get_clocktext$()
dim .w$(23),.wx(23),.wy(23),.uur(13)
for i=0 to 22 ! read .w$(i),.wx(i),.wy(i) ! next i
for i=1 to 12 ! read .uur(i) ! next i
data "IT",0,0, "IS",4,0, "FIVE",7,0, "TEN",0,1
data "BEFORE",5,1, "AFTER",0,2, "QUARTER",5,2, "HALF",0,3
data "AFTER",5,3, "BEFORE",0,4, "ONE",7,4, "TWO",0,5
data "THREE",5,5, "FOUR",0,6, "FIVE",4,6, "SIX",8,6
data "SEVEN",0,7, "NINE",6,7, "EIGHT",0,8, "TEN",4,8
data "ELEVEN",6,8, "TWELVE",0,9, "HOUR",6,9
data 10,11,12,13,14,15,16,18,17,19,20,21
t$=""
t$&="HETKISAVIJFTIENATZVOOR"
t$&="OVERMEKWARTHALFSPMOVER"
t$&="VOORTHGONESTWO AMTHREE"
t$&="FOURFIVESIXSEVENNINE "
t$&="ACHTTIENELFTWAALFPMUUR"
' t$&="EIGHTTENELEVENTWELVEPM"
return t$
end def

Henko
Posts: 834
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Re: Yet another clock

Post by Henko »

Hi,

This conversion from a Dutch version into an English version is not only a translation from Dutch words into their English equivalents.
There is also a syntactic difference in the way that an actual time is textually expressed.
In English, all spoken times refer to either the current hour, or the next hour, hence there are two “anchor points” for all time expressions.
In Dutch, the “half hour” (at 6) is also an “anchor point”.
For instance, 14.20 hr. Is expressed as “twenty past two” in English, and as ”ten before half three” in Dutch (“tien voor half drie”). The English syntax is less complex than the Dutch syntax.

Therefore, the conversion is not only a question of substiting some words, but also requires adaptation of the logic, the code.

In the Dutch version, in the function “init_prog()” you will find the line: “ if u=12 and m<16 then u=u else u=u%12 ! u1=u+1”
After 15 minutes (quarter PAST current hour), we already switch to “minutes BEFORE” the next coming (half)hour.
In the English version this switch from “minutes after” to “minutes befor” happens only once, at half way the hour, 30 minutes.
The long coding block with the “if m=xx then highlight….” can be much simplified for the English version.

I hope this helps in the conversion.

Chooch912
Posts: 50
Joined: Thu Apr 12, 2018 6:16 pm
My devices: iPad
Flag: United States of America

Re: Yet another clock

Post by Chooch912 »

Thanks for the explanation. I will work on this more now that I know exactly how the Dutch time is expressed and hope I can correct my "English" version of the program. I really like this program! You create so many awesome programs.

Chooch912
Posts: 50
Joined: Thu Apr 12, 2018 6:16 pm
My devices: iPad
Flag: United States of America

Re: Yet another clock

Post by Chooch912 »

So, what do I change to make the hour read FIVE instead of SIX (when it is still "minutes after FIVE" in English)? I like this much better than the English "twenty to SIX".
IMG_9792.png
IMG_9792.png (505.62 KiB) Viewed 231 times

Henko
Posts: 834
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Re: Yet another clock

Post by Henko »

Hi,

In this code block:

if m5=0 then highlight(.uur(u),22,0,0)
if m5=5 then highlight( 2,5,.uur(u),0)
if m5=10 then highlight(3,5,.uur(u),0)
if m5=15 then highlight(6,8,.uur(u),0)
if m5=20 then highlight(3,4,7,.uur(u1))
if m5=25 then highlight(2,4,7,.uur(u1))
if m5=30 then highlight(7,.uur(u1),0,0)
if m5=35 then highlight(2,5,7,.uur(u1))
if m5=40 then highlight(3,5,7,.uur(u1))
if m5=45 then highlight(6,9,.uur(u1),0)
if m5=50 then highlight(3,4,.uur(u1),0)
if m5=55 then highlight(2,4,.uur(u1),0)

the array index in uur(x), “u” means the current hour, and “u1” produces the next coming hour.
Hence change “u1” into “u”, where the indicated hour hhas to be reduced into the current hour.

By the way, i realize that my coding style may be difficult to understand by other people. I learned programming in the period that available memory and processor speed were real bottlenecks. :cry:

Chooch912
Posts: 50
Joined: Thu Apr 12, 2018 6:16 pm
My devices: iPad
Flag: United States of America

Re: Yet another clock

Post by Chooch912 »

Thank you. Changing u1 to u worked perfectly. I really like this program. BTW, I like the way you code. I try to learn more coding details using your programs. I learned Business Basic on a mainframe - text only, no graphics.

Post Reply