RetroCoders Community

FreeBasic Programming => FreeBasic => Topic started by: ron77_db on Apr 01, 2022, 12:03 PM

Title: mishka's clock
Post by: ron77_db on Apr 01, 2022, 12:03 PM
#lang "qb"
'_TITLE "THE MATHEMATICAL ANALOG CLOCK VERSION 3 - WITHOUT CALIBRATION"
SCREEN 12
'DEVELOPED 2/17/2019 IN QBASIC BY RON77 AND MISHKA AND ITAY :)
'screen half with & height
const SHW = 640 \ 2
const SHH = 480 \ 2
const pi = 3.14159265
const RAD_PER_DEG = 2 * pi / 360

Sub clock()
   DO
      '
      hour = VAL(LEFT$(TIME$, 2))
      minute = VAL(MID$(TIME$, 4, 2))
      sec = VAL(RIGHT$(TIME$, 2))

      hour = hour + minute / 60 + sec / 3600
      minute = minute + sec / 60

      ts = 90 - sec * 6
      tm = 90 - minute * 6
      th = 90 - hour * 30

      CLS
      PRINT TIME$
      PRINT "press ESC to exit  "

      CIRCLE (SHW, SHH), 200
      CIRCLE (SHW, SHH), 215
      'draw minute marks
      FOR j = 0 TO 59
         cosangle = COS((90 - j * 6) * RAD_PER_DEG)
         sinangle = SIN((90 - j * 6) * RAD_PER_DEG)
         LINE (SHW + 190 * cosangle, SHH - 190 * sinangle)-(SHW + 200 * cosangle, SHH - 200 * sinangle), 10
      NEXT
      'draw hour marks
      FOR i = 0 TO 11
         cosangle = COS((90 - i * 30) * RAD_PER_DEG)
         sinangle = SIN((90 - i * 30) * RAD_PER_DEG)
         LINE (SHW + 205 * cosangle, SHH - 205 * sinangle)-(SHW + 210 * cosangle, SHH - 210 * sinangle), 12
      NEXT
      'draw pointers
      LINE (SHW, SHH)-(SHW + 200 * COS(ts * RAD_PER_DEG), (SHH - 200 * SIN(ts * RAD_PER_DEG)))
      LINE (SHW, SHH)-(SHW + 180 * COS(tm * RAD_PER_DEG), (SHH - 180 * SIN(tm * RAD_PER_DEG))), 10
      LINE (SHW, SHH)-(SHW + 120 * COS(th * RAD_PER_DEG), (SHH - 120 * SIN(th * RAD_PER_DEG))), 12
      SLEEP (1)

      k$ = INKEY$
   LOOP UNTIL k$ = CHR$(27)
END SUB

clock()
Title: Re: mishka's clock
Post by: ron77 on Sep 19, 2022, 12:20 PM
hello CharlieJV

nice HTML/js interpreter for basic you have there... however it cannot read/write files nor does it has simple types of freeBASIC - this is why you cannot compare an interpreter to a compiled language... and btw this is a "RETRO PROGRAMMING" forum, and your HTML/js interpreter looks like and feels like a toy compared to the real thing...

I'm sorry maybe it's just me but why would I use your TiddlyWiki toy when I got the real thing?

anyway... welcome to retrocoders community
Title: Re: mishka's clock
Post by: __blackjack__ on Jul 25, 2025, 03:06 PM
There's a bug in the clock program: hour, minute, and sec are defined by three independent calls to TIME$.  But time goes by between those calls and there's a chance that the values don't refer to the same point in time.  For instance if the time at the beginning of the first call is 05:59:59.9999 the result from the calls might be 5, 0, and 0.

But that's simple to fix:
      t$ = TIME$
      hour = VAL(LEFT$(t$, 2))
      minute = VAL(MID$(t$, 4, 2))
      sec = VAL(RIGHT$(t$, 2))