[code] Batch Clock Widget

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: [code] Batch Clock Widget

#31 Post by Aacini » 05 Nov 2013 02:26

Oops! I just fixed a little bug in the clock that incorrectly show the calendar if the first day of the month falls in Thursday, Friday or Saturday (like November/2013). I also give a slightly better appearance to /Size:1 model. Please, copy the code again... :roll:

Antonio

carlos
Expert
Posts: 503
Joined: 20 Aug 2010 13:57
Location: Chile
Contact:

Re: [code] Batch Clock Widget

#32 Post by carlos » 09 Nov 2013 23:37

@Aacini: thanks.

I updated my codes in the first post for use my last improves to getdate function, that now is really more speedy and good.

carlos
Expert
Posts: 503
Joined: 20 Aug 2010 13:57
Location: Chile
Contact:

Re: [code] Batch Clock Widget

#33 Post by carlos » 18 Nov 2013 12:39

I updated the tiny model and model 1 for use less cpu.

carlos
Expert
Posts: 503
Joined: 20 Aug 2010 13:57
Location: Chile
Contact:

Re: [code] Batch Clock Widget

#34 Post by carlos » 18 Nov 2013 13:05

Fixed a bug after post the update. The last updated have this stamp:

Code: Select all

::last updated: 2013, 18 november: reduced cpu usage fixed
note the end word: fixed.

carlos
Expert
Posts: 503
Joined: 20 Aug 2010 13:57
Location: Chile
Contact:

Re: [code] Batch Clock Widget

#35 Post by carlos » 11 Feb 2015 07:21

Today, I updated the clock code with minor changes. I'm using this clock in the desktop of my job :)

btk
Posts: 13
Joined: 17 Apr 2014 21:51

Re: [code] Batch Clock Widget

#36 Post by btk » 11 Feb 2015 07:36

Dont function.

Viewer image.
I copy and past in notepad, save in clock.cmd and execute.

Image

Solution ?

carlos
Expert
Posts: 503
Joined: 20 Aug 2010 13:57
Location: Chile
Contact:

Re: [code] Batch Clock Widget

#37 Post by carlos » 11 Feb 2015 08:47

btk, please copy again the code.
I paste from other text editor, that corrupted the ascii characters.
Now, I copied from notepad.

btk
Posts: 13
Joined: 17 Apr 2014 21:51

Re: [code] Batch Clock Widget

#38 Post by btk » 11 Feb 2015 18:26

Thank you...copy and paste last in Notepad++ now in NOTEPAD and perfect funcionally.



*** My english is soft, i am braziliam sorry any error write ***

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: [code] Batch Clock Widget

#39 Post by Aacini » 20 Mar 2016 13:10

A new Batch clock has just arrived! This new model is an analog clock, instead of the original ones that were digital. The display shown by this model is pretty cool! 8)

Image

I borrowed this einstein1969's method that calculate points in a circle and draw straight lines and modified it in order to made the method more efficient, so I used it to show the clock hands.

Code: Select all

@echo off
setlocal EnableDelayedExpansion

rem AnalogClock.bat by Antonio Perez Ayala

rem http://www.dostips.com/forum/viewtopic.php?f=3&t=5028&p=45842#p45842

rem Size of clock face: use same values in X & Y for square fonts (like bitmap font 8x8)
rem Set to different values for oval face or to adjust aspect ratio; for example, in Lucida Console 8x14 use xres=70, yres=40
set /A xres=70, yres=70

rem Specification parameters
set /A xrad[Hour]=xres/4, yrad[Hour]=yres/4, wide[Hour]=5,  xrad[Min]=xres*3/8, yrad[Min]=yres*3/8, wide[Min]=3,  xrad[Sec]=xres/2-1, yrad[Sec]=yres/2-2, wide[Sec]=1
set "char[Hour]=°" & set "char[Min]=±" & set "char[Sec]=Û"
set /A HourMin=HourMax=MinMin=MinMax=SecMin=SecMax=0

rem Define SIN(x) function; PI=31416
set "SIN=a-a*a/1920*a/312500+a*a/1920*a/15625*a/15625*a/2560000-a*a/1875*a/15360*a/15625*a/15625*a/16000*a/44800000"
set "SIN(x)=(a=(x)%%62832, c=(a>>31|1)*a, a-=(((c-47125)>>31)+1)*(a>>31|1)*62832 - ((c-47125)>>31)*(((c-15709)>>31)+1)*(2*a-(a>>31|1)*31416), %SIN%)"
set "SIN="

rem Initialize the clock face
for /L %%x in (1,1,%xres%) do set "line=!line! "
for /L %%y in (1,1,%yres%) do set "line[%%y]=%line%"
set /A col=(xres-14)/2, line=yres/4
for %%a in (" ²²²  ²²²  ²²²"
            " ² ²  ² ²  ² ²"
            " ²²²  ²²²  ²²²"
            " ² ²  ²    ² ²"
            " ² ²  ²    ² ²") do (
   for /F "tokens=1,2" %%x in ("!col! !line!") do set "c=!line[%%y]:~%%x!" & set "line[%%y]=!line[%%y]:~0,%%x!%%~a!c:~14!"
   set /A line+=1
)
set /A xradius=xrad[Sec], yradius=yrad[Sec]
for /L %%a in (6,6,354) do (
   set "Angle=%%a"
   set /A "x2=xres/2+%SIN(x):x=15708-Angle*31416/180%*xradius/10000, y2=yres/2+%SIN(x):x=Angle*31416/180%*yradius/10000"
   for /F "tokens=1,2" %%x in ("!x2! !y2!") do set "c=!line[%%y]:~%%x!" & set "line[%%y]=!line[%%y]:~0,%%x!.!c:~1!"
)
for /L %%a in (0,30,330) do (
   set "Angle=%%a"
   set /A "x2=xres/2+%SIN(x):x=15708-Angle*31416/180%*xradius/10000, y2=yres/2+%SIN(x):x=Angle*31416/180%*yradius/10000"
   for /F "tokens=1,2" %%x in ("!x2! !y2!") do set "c=!line[%%y]:~%%x!" & set "line[%%y]=!line[%%y]:~0,%%x!Û!c:~1!"
)
set /A xradius+=1, yradius+=1
for /L %%a in (0,90,270) do (
   set "Angle=%%a"
   set /A "x2=xres/2+%SIN(x):x=15708-Angle*31416/180%*xradius/10000, y2=yres/2+%SIN(x):x=Angle*31416/180%*yradius/10000"
   for /F "tokens=1,2" %%x in ("!x2! !y2!") do set "c=!line[%%y]:~%%x!" & set "line[%%y]=!line[%%y]:~0,%%x!Û!c:~1!"
)
for /F "tokens=1-3 delims=:.," %%a in ("%time: =0%") do (
   set /A "angHour=(10%%a%%100*30+270)%%360, Min=1%%b%%100, angMin=(Min*6+270)%%360, lastSec=1%%c%%100, angSec=(lastSec*6+270)%%360,  angHour+=Min/20*10"
)
call :DrawHand Hour
call :DrawHand Min

rem Show the clock and start it
title APA - Analog Clock
color 0B
chcp 850 > NUL
set /A col=xres+1, line=yres+1
mode %col%,%line%
for /L %%# in () do (

   ping -n 2 localhost >NUL
   for /F "tokens=1-3 delims=:.," %%a in ("!time: =0!") do set /A "Hour=10%%a%%100, Min=1%%b%%100, Sec=1%%c%%100"
   if !lastSec! lss 59 (  rem Just advance Sec hand
      set /A "lastSec+=1"
   ) else (  rem Update Min hand

      rem Remove Sec hand from clock face
      for /L %%i in (!SecMin!,1,!SecMax!) do (
         set "line[%%i]=!Sec[%%i]!"
         set "Sec[%%i]="
      )
      set /A "SecMin=SecMax=0"

      set /A "MinMod20=Min%%20"
      if !MinMod20! leq 2 (  rem Update Hour hand, every 20 minutes; 3 times to be sure...

         rem Remove Min hand from clock face
         for /L %%i in (!MinMin!,1,!MinMax!) do (
            set "line[%%i]=!Min[%%i]!"
            set "Min[%%i]="
         )
         set /A "MinMin=MinMax=0"

         set /A "angHour=(Hour*30+Min/20*10+270)%%360"
         call :DrawHand Hour
      )
      set /A "angMin=(Min*6+270)%%360"
      call :DrawHand Min
      set /A "lastSec=0"

   )
   set /A "angSec=(lastSec*6+270)%%360"
   call :DrawHand Sec

   cls & for /L %%i in (1,1,%yres%) do echo/!line[%%i]!

)
never exit /B


:DrawHand Type

set /A xradius=xrad[%1], yradius=yrad[%1], Wide=wide[%1], Wide2=Wide/2, Angle=ang%1
set "Char="
for /L %%i in (1,1,%Wide%) do set "Char=!Char!!char[%1]!"

rem Recover clock face as it was before this hand was shown
for /L %%i in (!%1Min!,1,!%1Max!) do (
   set "line[%%i]=!%1[%%i]!"
   set "%1[%%i]="
)
set /A %1Min=xres, %1Max=0

rem Place this hand in face
set /A "x1=xres/2, y1=yres/2, x2=xres/2+%SIN(x):x=15708-Angle*31416/180%*xradius/10000, y2=yres/2+%SIN(x):x=Angle*31416/180%*yradius/10000, dx=x2-x1, dx=dx*(dx>>31|1), dy=y2-y1, dy=dy*(dy>>31|1)"
if !dy! leq !dx! (set "A=x" & set "B=y") else (set "A=y" & set "B=x" & set /A x1-=Wide2, x2-=Wide2)
for /F "tokens=1,2" %%X in ("!A! !B!") do (
   if !%%X2! lss !%%X1! set /A t=x2, x2=x1, x1=t, t=y2, y2=y1, y1=t
   set /A "yincr=-((%%Y1-%%Y2)>>31|1), d=2*d%%Y-d%%X, Eincr=2*d%%Y, NEincr=2*(d%%Y-d%%X)"
   for /L %%I in (!%%X1!,1,!%%X2!) do (
      if %%X equ x (
         set /A yL=y1-Wide2, yR=y1+Wide2
         for /L %%y in (!yL!,1,!yR!) do (
            if %%y gtr !%1Max! set "%1Max=%%y"
            if %%y lss !%1Min! set "%1Min=%%y"
            if not defined %1[%%y] set "%1[%%y]=!line[%%y]!"
            set "c=!line[%%y]:~%%I!" & set "line[%%y]=!line[%%y]:~0,%%I!%Char:~0,1%!c:~1!"
         )
      ) else (
         if %%I gtr !%1Max! set "%1Max=%%I"
         if %%I lss !%1Min! set "%1Min=%%I"
         if not defined %1[%%I] set "%1[%%I]=!line[%%I]!"
         for /F "tokens=1,2" %%x in ("!x1! !Wide!")  do set "c=!line[%%I]:~%%x!" & set "line[%%I]=!line[%%I]:~0,%%x!!Char:~0,%%y!!c:~%%y!"
      )
      set /A "dP=(d>>31)+1, d+=^!dP*Eincr+dP*NEincr, %%Y1+=dP*yincr"
   )
)
exit /B

This program was designed to show a visually pleasant output, although it is not very exact. The problem is the "ping -n 2 localhost" command used to wait one second without use too much CPU. This command usually takes a little less than 1 second, so the time displayed by the clock loses a few seconds every minute. Altough the clock time could be synchronized at each minute, this would cause an unpleasant and frequent jump of the seconds hand. For this reason, the seconds hand will always move with the lapse given by ping, whichever such interval be, and the minute hand will be synchronized every time it loses one minute. This adjustment cause a two-minute jump of the minute hand now and then.

Enjoy it! :D

Antonio
Last edited by Aacini on 23 Mar 2016 23:42, edited 1 time in total.

einstein1969
Expert
Posts: 960
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: [code] Batch Clock Widget

#40 Post by einstein1969 » 21 Mar 2016 03:21

Wow!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Very good work Antonio.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: [code] Batch Clock Widget

#41 Post by foxidrive » 21 Mar 2016 05:07

That is certainly impressive.

I can time my boiled eggs on the computer now. :)

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: [code] Batch Clock Widget

#42 Post by Squashman » 21 Mar 2016 06:32

+1

miskox
Posts: 630
Joined: 28 Jun 2010 03:46

Re: [code] Batch Clock Widget

#43 Post by miskox » 21 Mar 2016 10:40

Very gooood.

Thanks.
Saso

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: [code] Batch Clock Widget

#44 Post by Aacini » 03 Apr 2016 19:36

I added the day of week and day number to the analog clock, and the option of give the horizontal and vertical sizes of the clock in the parameters. I defined English and Spanish names for the days of week, but you may add your own language names in a very simple way if you wish; an example of how to do that is given in the program code, in the part that insert the clock brand ("APA"). If you define day names for other languages, I encourage you to post the new definitions here.

Code: Select all

@echo off
setlocal EnableDelayedExpansion

rem AnalogClock.bat by Antonio Perez Ayala
rem - 2016/04/03: Version 1.1: Several small improvements, show day of week and date.
rem http://www.dostips.com/forum/viewtopic.php?f=3&t=5028&p=46049#p46049

rem Size of clock face optionally given in the parameters in X Y order (default: 60x60).
rem Use same values in X & Y for square fonts (like bitmap font 8x8)
rem Use different values for oval face or to adjust aspect ratio; for example, in Lucida Console 8x14 use X=70, Y=40
if "%~1" equ "" (
   set /A xres=60, yres=60
) else (
   set "xres=%~1"
   if "%~2" equ "" (
      set "yres=%~1"
   ) else (
      set "yres=%~2"
   )
)

rem Specification parameters
set /A xrad[Hour]=xres/4, yrad[Hour]=yres/4, wide[Hour]=5,  xrad[Min]=xres*3/8, yrad[Min]=yres*3/8, wide[Min]=3,  xrad[Sec]=xres/2-1, yrad[Sec]=yres/2-2, wide[Sec]=1
set "char[Hour]=°" & set "char[Min]=±" & set "char[Sec]=Û"

rem Initialize clock face and date/time values
for /L %%x in (1,1,%xres%) do set "line=!line! "
for /L %%y in (1,1,%yres%) do set "line[%%y]=%line%"
for /F "tokens=1,4 delims=.-+{" %%a in ('wmic OS Get LocalDateTime^,MUILanguages') do if "%%~b" neq "" set "daTi=%%a" & set "lang=%%~b"

if %yres% leq 30 goto drawMarks

   rem Insert clock brand and date/day banners
   set "setlocal="
   setlocal EnableDelayedExpansion

   rem Insert clock brand
   set /A "col=xres/2-6, line=yres/4"
   rem Brand encoding in hexadecimal:
   rem "@@@..@@@..@@@"  =  1 1100 1110 0111  =  0x1CE7
   rem "@.@..@.@..@.@"  =  1 0100 1010 0101  =  0x14A5
   rem "@@@..@@@..@@@"  =  1 1100 1110 0111  =  0x1CE7
   rem "@.@..@....@.@"  =  1 0100 1000 0101  =  0x1485
   rem "@.@..@....@.@"  =  1 0100 1000 0101  =  0x1485
   for %%n in (1CE7 14A5 1CE7 1485 1485) do (
      set /A "num=0x%%n"
      set "banner="
      for /L %%b in (1,1,13) do (
         set /A "bit=num&1, num>>=1"
         if !bit! equ 1 (set "banner=²!banner!") else (set "banner= !banner!")
      )
      for /F "tokens=1,2" %%x in ("!col! !line!") do set "c=!line[%%y]:~%%x!" & set "line[%%y]=!line[%%y]:~0,%%x!!banner!!c:~13!"
      set /A line+=1
   )

   rem Define English DOW names (Sun..Sat order)
   set "i=0"
   for %%a in (" 7291  4299  7295  1293  7391"
               "11391 1B299 15295 11293 11391"
               " 1CA7  08A4  08A7  08A4  08E7"
               " 89CE  8909  A9C9  D909  89CE"
               " 1CA5  08A5  08E5  08A5  08A7"
               " 0E71  0849  0E71  0851  0849"
               " 1CE7  10A2  1CE2  04A2  1CA2") do (
      set "en[!i!]=%%~a"
      set /A i+=1
   )

   rem Define Spanish DOW names (Dom..Sab order)
   set "i=0"
   for %%a in ("E391 929B 9295 9291 E391"
               "4291 4299 4295 4293 7391"
               "89CE D949 A9CE 894A 8949"
               "1127 1B24 1527 1124 1127"
               "04A7 04A4 14A7 14A4 1CE7"
               "1127 1124 1127 0A24 0427"
               "39CE 2149 39CE 0949 394E") do (
      set "es[!i!]=%%~a"
      set /A i+=1
   )

   rem Insert day of week
   if not defined %lang%[0] (
      echo Day of week names not defined for language: "%lang%"
      echo Selecting default language: English
      pause
      set "lang=en"
   )
   set /A "yyyy=%daTi:~0,4%, mm=1%daTi:~4,2%%%100, dd=%daTi:~6,2%"
   set /A "a=(mm-14)/12, dow=((1461*(yyyy+4800+a))/4+(367*(mm-2-12*a))/12-(3*((yyyy+4900+a)/100))/4+dd)%%7,  col=xres/2-23, line=yres*3/4-5"
   for %%n in (!%lang%[%dow%]!) do (
      set /A "num=0x%%n"
      set "banner="
      for /L %%b in (1,1,20) do (
         set /A "bit=num&1, num>>=1"
         if !bit! equ 1 (set "banner=²!banner!") else (set "banner= !banner!")
      )
      for /F "tokens=1,2" %%x in ("!col! !line!") do set "c=!line[%%y]:~%%x!" & set "line[%%y]=!line[%%y]:~0,%%x!!banner!!c:~20!"
      set /A line+=1
   )

   rem Insert day number
   set "digits=6 9 9 9 6;2 6 2 2 7;6 9 2 4 F;E 1 6 1 E;9 9 F 1 1;F 8 E 1 E;6 8 E 9 6;F 1 2 4 8;6 9 6 9 6;6 9 7 1 6"
   set /A "col=xres/2+4, line=yres*3/4-5, x=dd/10+1, y=dd%%10+1"
   if %x% equ 1 set /A x=y, y=11
   set "xchg="
   if %x% gtr %y% set "xchg=1"
   for /F "tokens=%x%,%y% delims=;" %%x in ("%digits%;0 0 0 0 0") do (
      if not defined xchg (set "x=%%x" & set "y=%%y") else (set "x=%%y" & set "y=%%x")
      for /L %%# in (1,1,5) do  for /F "tokens=1*" %%a in ("!x!") do  for /F "tokens=1*" %%c in ("!y!") do  (
         set /A "n1=0x%%a, n2=0x%%c"
         set "banner="
         for /L %%# in (1,1,4) do (
            set /A "bit=n2&1, n2>>=1"
            if !bit! equ 1 (set "banner=²!banner!") else (set "banner= !banner!")
         )
         set "banner=  !banner!"
         for /L %%# in (1,1,4) do (
            set /A "bit=n1&1, n1>>=1"
            if !bit! equ 1 (set "banner=²!banner!") else (set "banner= !banner!")
         )
         for /F "tokens=1,2" %%x in ("!col! !line!") do set "c=!line[%%y]:~%%x!" & set "line[%%y]=!line[%%y]:~0,%%x!!banner!!c:~10!"
         set /A line+=1
         set "x=%%b"  &  set "y=%%d"
      )
   )

   set "setlocal=1"
   for /F "delims=" %%a in ('set line[') do (if defined setlocal endlocal) & set "%%a"

:drawMarks

rem Define SIN(x) function; PI=31416
set "SIN=a-a*a/1920*a/312500+a*a/1920*a/15625*a/15625*a/2560000-a*a/1875*a/15360*a/15625*a/15625*a/16000*a/44800000"
set "SIN(x)=(a=(x)%%62832, c=(a>>31|1)*a, a-=(((c-47125)>>31)+1)*(a>>31|1)*62832 - ((c-47125)>>31)*(((c-15709)>>31)+1)*(2*a-(a>>31|1)*31416), %SIN%)"
set "SIN="

rem Draw minutes and hours marks
set /A xradius=xrad[Sec], yradius=yrad[Sec]
for /L %%a in (6,6,354) do (
   set "Angle=%%a"
   set /A "x2=xres/2+%SIN(x):x=15708-Angle*31416/180%*xradius/10000, y2=yres/2+%SIN(x):x=Angle*31416/180%*yradius/10000"
   for /F "tokens=1,2" %%x in ("!x2! !y2!") do set "c=!line[%%y]:~%%x!" & set "line[%%y]=!line[%%y]:~0,%%x!ú!c:~1!"
)
for /L %%a in (0,30,330) do (
   set "Angle=%%a"
   set /A "x2=xres/2+%SIN(x):x=15708-Angle*31416/180%*xradius/10000, y2=yres/2+%SIN(x):x=Angle*31416/180%*yradius/10000"
   for /F "tokens=1,2" %%x in ("!x2! !y2!") do set "c=!line[%%y]:~%%x!" & set "line[%%y]=!line[%%y]:~0,%%x!Û!c:~1!"
)
set /A xradius+=1, yradius+=1
for /L %%a in (0,90,270) do (
   set "Angle=%%a"
   set /A "x2=xres/2+%SIN(x):x=15708-Angle*31416/180%*xradius/10000, y2=yres/2+%SIN(x):x=Angle*31416/180%*yradius/10000"
   for /F "tokens=1,2" %%x in ("!x2! !y2!") do set "c=!line[%%y]:~%%x!" & set "line[%%y]=!line[%%y]:~0,%%x!Û!c:~1!"
)

rem Draw clock hands at initial position
set /A "angHour=(1%daTi:~8,2%%%100*30+270)%%360, Min=1%daTi:~10,2%%%100, angMin=(Min*6+270)%%360, lastSec=1%daTi:~12,2%%%100, angSec=(lastSec*6+270)%%360, angHour+=Min/20*10"
set /A HourMin=HourMax=MinMin=MinMax=SecMin=SecMax=0
call :DrawHand Hour
call :DrawHand Min

rem Show the clock and start it
title APA - Analog Clock
color 0B
chcp 850 > NUL
set /A col=xres+1, line=yres+1
mode %col%,%line%
for /L %%# in () do (

   if %xres% lss 100 (
      ping -n 2 localhost > NUL
   ) else if %xres% lss 300 (
      pathping -q 2 -w 1000 localhost > NUL
   )
   for /F "tokens=1,2 delims=:.," %%a in ("!time: =0!") do set /A "Hour=10%%a%%100, Min=1%%b%%100"
   if !lastSec! lss 59 (  rem Just advance Sec hand
      set /A "lastSec+=1"
   ) else (  rem Update Min hand

      rem Remove Sec hand from clock face
      for /L %%i in (!SecMin!,1,!SecMax!) do (
         set "line[%%i]=!Sec[%%i]!"
         set "Sec[%%i]="
      )
      set /A "SecMin=SecMax=0"

      set /A "MinMod20=Min%%20"
      if !MinMod20! leq 1 (  rem Update Hour hand, every 20 minutes; 2 times to be sure...

         rem Remove Min hand from clock face
         for /L %%i in (!MinMin!,1,!MinMax!) do (
            set "line[%%i]=!Min[%%i]!"
            set "Min[%%i]="
         )
         set /A "MinMin=MinMax=0"

         set /A "angHour=(Hour*30+Min/20*10+270)%%360"
         call :DrawHand Hour
      )
      set /A "angMin=(Min*6+270)%%360"
      call :DrawHand Min
      set /A "lastSec=0"

   )
   set /A "angSec=(lastSec*6+270)%%360"
   call :DrawHand Sec

   cls & for /L %%i in (1,1,%yres%) do echo/!line[%%i]!

)
never exit /B


:DrawHand Type

set /A xradius=xrad[%1], yradius=yrad[%1], Wide=wide[%1], Wide2=Wide/2, Angle=ang%1
set "Char="
for /L %%i in (1,1,%Wide%) do set "Char=!Char!!char[%1]!"

rem Recover clock face as it was before this hand was shown
for /L %%i in (!%1Min!,1,!%1Max!) do (
   set "line[%%i]=!%1[%%i]!"
   set "%1[%%i]="
)
set /A %1Min=xres, %1Max=0

rem Place this hand in clock face
set /A "x1=xres/2, y1=yres/2, x2=xres/2+%SIN(x):x=15708-Angle*31416/180%*xradius/10000, y2=yres/2+%SIN(x):x=Angle*31416/180%*yradius/10000, dx=x2-x1, dx=dx*(dx>>31|1), dy=y2-y1, dy=dy*(dy>>31|1)"
if !dy! leq !dx! (set "A=x" & set "B=y") else set "A=y" & set "B=x" & set /A "x1-=Wide2, x2-=Wide2"
for /F "tokens=1,2" %%X in ("!A! !B!") do (
   if !%%X2! lss !%%X1! set /A t=x2, x2=x1, x1=t, t=y2, y2=y1, y1=t
   set /A "yincr=-((%%Y1-%%Y2)>>31|1), d=2*d%%Y-d%%X, Eincr=2*d%%Y, NEincr=2*(d%%Y-d%%X)"
   for /L %%I in (!%%X1!,1,!%%X2!) do (
      if %%X equ x (
         set /A yMin=y1-Wide2, yMax=y1+Wide2
         if !yMin! lss !%1Min! set "%1Min=!yMin!"
         if !yMax! gtr !%1Max! set "%1Max=!yMax!"
         for /L %%y in (!yMin!,1,!yMax!) do (
            if not defined %1[%%y] set "%1[%%y]=!line[%%y]!"
            set "c=!line[%%y]:~%%I!" & set "line[%%y]=!line[%%y]:~0,%%I!%Char:~0,1%!c:~1!"
         )
      ) else (
         set /A "%1Min=y1, %1Max=y2"
         if not defined %1[%%I] set "%1[%%I]=!line[%%I]!"
         for /F %%x in ("!x1!") do set "c=!line[%%I]:~%%x!" & set "line[%%I]=!line[%%I]:~0,%%x!!Char:~0,%Wide%!!c:~%Wide%!"
      )
      set /A "dP=(d>>31)+1, d+=^!dP*Eincr+dP*NEincr, %%Y1+=dP*yincr"
   )
)
exit /B

I completed an interesting test: I selected the 1x1 size raster font in the cmd.exe window as described at this post and then activated the analog clock with a size of 200 characters: a small clock with pixel-resolution graphics appears! I did several tests until I found that at a size of 130 characters, the size of the analog clock is the same of the clock displayed by the Windows Date/Time accessory. However, the clock worked slower because the number of operations needed for a 130x130 size face is much larger than before, so I had to insert an adjustment in the wait time that is activated when the clock size is larger than 100. The result is amazing!

Image

Antonio
Last edited by Aacini on 06 Apr 2016 09:57, edited 1 time in total.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: [code] Batch Clock Widget

#45 Post by foxidrive » 05 Apr 2016 08:24

The pic looks neat Antonio.



Is there a method to set the font and size for one screen only, the one that is running the clock?

Can the settings be changed to open the window, and then changed back so other windows open as usual?

Post Reply