DigiClock

Post Reply
User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

DigiClock

Post by rbytes »

A day and date digital clock. You can make your Windows tablet work for you even when you aren't actually using it! :mrgreen:
Thanks agaIn to Mr. K for answering all of my questions. Sometimes what I type does not equal what I think I have typed!

The text on the right side is right-justified using the #textwidth() function.

You will need the Ranchers font, downloadable from 1001 Fonts (1001fonts.com)

Code: Select all

' DigiClock by rbytes
' September 2017
' Quit by tapping the screen

#.scrview(#.normal)
days = ["Monday"," Tuesday"," Wednesday","Thursday","Friday","Saturday","Sunday"]
months = ["January","February","March","April","May","June","July","August","September","October","November","December"]
d,m,y = #.today() 
n = #.weekday(d,m,y) 

sw,sh = #.scrsize()
rw=sw/1232 ; rh=sh/813
#.fontname("Ranchers")
#.fontsize(100)
ap = ""
md = ""
sd = ""
#.scroff()

' main program loop
> 
  ' end program if screen tapped
  ? #.tap(), #.end()

  #.scrclear(0,0,0)
  ? sh>sw, port=1 ! port=0

  year   =  y
  month  =  m
  date   =  d
  day    =  n

  hour,minute,second = #.now() ' returns current hour h, minute m and second s.

  ' Conversion to a 12-hour clock
  ? hour > 11
    ap = "PM"
    hour -= 12.                 
  !
    ap = "AM"
  .

  ' SPL gives military time, so midnight to one am is 00 hours. Change to 12 hours.
  ? hour = 0, hour = 12         

  ' add leading zero to minutes if needed
  ? minute < 10
    md = "0"
  !
    md = ""
  .

  ' add leading zero to seconds if needed
  ? second < 10
    sd = "0"
  !
    sd = ""
  .

  '? port                         ' if device is in portrait mode

  ' draw year
  #.drawcolor(1,.2,.2)
  #.fontsize(180) 'FONT SIZE (140+port*30)*mc
  #.drawtext(sw-50-#.textwidth(year),sh*.7,year)

  ' draw month and date
  #.fontsize(140)  'DRAW FONT SIZE (110+port*15)*mc
  dater = months[month]+" "+date
  #.drawcolor(1,.8,0)
  #.drawtext(sw-50-#.textwidth(dater),sh*.38,dater)

  ' draw day of week
  #.drawcolor(.3,1,0)
  #.fontsize(140)
  #.drawtext(sw-50-#.textwidth(days[day]),sh*.1,days[day])
  
  ' draw am/pm
  #.fontsize(120)
  #.drawcolor(0,1,1)
  #.drawtext(40,sh*.4,ap)

  ' draw hour and minutes
  #.fontsize(220)
  hourmin = hour+":"+md+minute
  #.drawtext(40,sh*.65,hourmin)

  ' draw seconds
  #.fontsize(160)
  #.drawcolor(1,.3,1)
  #.drawtext(40,sh*.1,":"+sd+#.int(second))
  #.scr()
  #.delay(.05)
<
Attachments
Screenshot (85).png
Screenshot (85).png (97.49 KiB) Viewed 3850 times
The only thing that gets me down is gravity...

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: DigiClock

Post by Mr. Kibernetik »

It is Ok when running full screen.
But I usually run SPL not full screen, so I get what I show below.
It will be better if output text will be autosized.
Снимок.JPG
Снимок.JPG (51.96 KiB) Viewed 3849 times

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: DigiClock

Post by rbytes »

Is there a simple autosize procedure?

I admit, I like the freedom of using the whole screen. I even shut off the Windows taskbar. I hope I will not be visited by the Windows police! :lol:
The only thing that gets me down is gravity...

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: DigiClock

Post by Mr. Kibernetik »

rbytes wrote:
Thu Sep 28, 2017 7:23 pm
Is there a simple autosize procedure?

I admit, I like the freedom of using the whole screen. I even shut off the Windows taskbar. I hope I will not be visited by the Windows police! :lol:
Screen sizes, proportions and rotations can be different, so this should be taken into account when defining text size and placement.
It will be even better if it will autofit the screen when screen size is changed during runtime.

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: DigiClock

Post by rbytes »

I added a variable fs as the second line of code. A value of 1 gives my preferred size. Set the value to a fraction to scale all text smaller, or a value greater than 1 to make it larger. (.5 and 2 shown)

Code: Select all

' DigiClock by rbytes
' September 2017
' Quit by tapping the screen

#.scrview(#.normal)
fs = 1                ' set this variable to scale your font sizes as desired

' hi res screen
'#.point(#.pix)
'#.aaoff()

days = ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]
months = ["January","February","March","April","May","June","July","August","September","October","November","December"]
d,m,y = #.today() 
n = #.weekday(d,m,y) 

sw,sh = #.scrsize()
rw=sw/1232 ; rh=sh/813
#.fontname("Ranchers")
#.fontsize(100*fs)
ap = ""
md = ""
sd = ""
#.scroff()

' main program loop
> 
  ' end program if screen tapped
  ? #.tap(), #.end()

  #.scrclear(0,0,0)
  ? sh>sw, port=1 ! port=0

  year   =  y
  month  =  m
  date   =  d
  day    =  n

  hour,minute,second = #.now() ' returns current hour h, minute m and second s.

  ' Conversion to a 12-hour clock
  ? hour > 11
    ap = "PM"
    hour -= 12.                 
  !
    ap = "AM"
  .

  ' SPL gives military time, so midnight to one am is 00 hours. Change to 12 hours.
  ? hour = 0, hour = 12         

  ' add leading zero to minutes if needed
  ? minute < 10
    md = "0"
  !
    md = ""
  .

  ' add leading zero to seconds if needed
  ? second < 10
    sd = "0"
  !
    sd = ""
  .

  '? port                         ' if device is in portrait mode

  ' draw year
  #.drawcolor(1,.2,.2)
  #.fontsize(180*fs) 'FONT SIZE (140+port*30)*mc
  #.drawtext(sw-50-#.textwidth(year),sh*.7,year)

  ' draw month and date
  #.fontsize(140*fs)  'DRAW FONT SIZE (110+port*15)*mc
  dater = months[month]+" "+date
  #.drawcolor(1,.8,0)
  #.drawtext(sw-50-#.textwidth(dater),sh*.38,dater)

  ' draw day of week
  #.drawcolor(.3,1,0)
  #.fontsize(140*fs)
  #.drawtext(sw-50-#.textwidth(days[day]),sh*.1,days[day])
  
  ' draw am/pm
  #.fontsize(120*fs)
  #.drawcolor(0,1,1)
  #.drawtext(40,sh*.4,ap)

  ' draw hour and minutes
  #.fontsize(220*fs)
  hourmin = hour+":"+md+minute
  #.drawtext(40,sh*.65,hourmin)

  ' draw seconds
  #.fontsize(160*fs)
  #.drawcolor(1,.3,1)
  #.drawtext(40,sh*.1,":"+sd+#.int(second))
  #.scr()
  #.delay(.05)
<
Attachments
Screenshot (87).png
Screenshot (87).png (55.13 KiB) Viewed 3841 times
Screenshot (86).png
Screenshot (86).png (132.24 KiB) Viewed 3841 times
The only thing that gets me down is gravity...

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: DigiClock

Post by rbytes »

I will continue to work on automatic features for this program, such as adjusting to screen rotation and size.
The only thing that gets me down is gravity...

Post Reply