Another binary clock...

User projects written in or related to FreeBASIC.
Dr_D
Posts: 2391
Joined: May 27, 2005 4:59
Contact:

Another binary clock...

Postby Dr_D » Jul 27, 2019 21:56

I made this because I was bored, but it looks pretty cool to me, so I decided to post it. I might make an actual mechanical with with an Arduino. :p


Code: Select all

#include once "fbgfx.bi"
using FB


const as single pi = 3.1415926, pi2 = pi*2, pihalf = pi/2

declare sub button( byref x as integer, byref y as integer, byref h as single )

screenres 640,480,32',,GFX_SHAPED_WINDOW


dim as string aTime
dim as single hourH(5), minH(5), secH(5)
dim as double fTime = timer, deltaTime


do

   aTime = time
   deltaTime = timer - fTime
   fTime = timer

   dim as string sHour   = bin(val(mid(aTime,1)), 6)
   dim as string sMinute = bin(val(mid(aTime,4)), 6)
   dim as string sSecond = bin(val(mid(aTime,7)), 6)

   screenlock
   cls
   'line(0,0)-(639,479),rgb(255,0,255),bf

   for i as integer = 0 to 5

      if val(mid(sHour,6-i,1))=0 then
         hourH(i)-=deltaTime*75
         if hourH(i)<5 then
            hourH(i)=5
         end if
      else
         hourH(i)+=deltaTime*75
         if hourH(i)>20 then
            hourH(i)=20
         end if
      end if


      if val(mid(sMinute,6-i,1))=0 then
         minH(i)-=deltaTime*75
         if minH(i)<5 then
            minH(i)=5
         end if
      else
         minH(i)+=deltaTime*75
         if minH(i)>20 then
            minH(i)=20
         end if
      end if


      if val(mid(sSecond,6-i,1))=0 then
         secH(i)-=deltaTime*75
         if secH(i)<5 then
            secH(i)=5
         end if
      else
         secH(i)+=deltaTime*75
         if secH(i)>20 then
            secH(i)=20
         end if
      end if

      button(320-75, (i*40)+120, hourH(i))
      button(320, (i*40)+120, minH(i))
      button(320+75, (i*40)+120, secH(i))

      draw string (320-150, (i*40)+112), str(2^(i))

   next

   dim as string text = "Hours"

   draw string (320-75-len(text)*4, 75), text

   text = "Minutes"
   draw string (320-len(text)*4, 75), text

   text = "Seconds"
   draw string (320+75-len(text)*4, 75), text

   screenunlock
   screensync
   sleep 3,1

loop until multikey(SC_ESCAPE)


sub button( byref x as integer, byref y as integer, byref h as single )


   dim as single x1, y1, x2, y2, xa = 25, yA = 5
   dim as single cell = 10, cellStep = pi2/cell
   dim as uinteger linecol = rgb(145,145,0)
   dim as short c = 96

   if h>10 then c = 196

   for a as single = -pihalf to pihalf step pi2/cell

      x1 = x+xa*sin(a)
      y1 = y+ya*cos(a)

      x2 = x+xa*sin(a-cellStep)
      y2 = y+ya*cos(a-cellStep)

      line(x1,y1)-(x1,y1-h),linecol

   next


   for a as single = 0 to pi2 step pi2/cell

      x1 = x+xa*sin(a)
      y1 = y+ya*cos(a)

      x2 = x+xa*sin(a-cellStep)
      y2 = y+ya*cos(a-cellStep)

      line(x1,y1-h)-(x2,y2-h),linecol

   next


   for a as single = -pihalf+(pi2/cell) to pihalf step pi2/cell

      x1 = x+xa*sin(a)
      y1 = y+ya*cos(a)

      x2 = x+xa*sin(a-cellStep)
      y2 = y+ya*cos(a-cellStep)

      line(x1,y1)-(x2,y2),linecol

   next

   paint(x,y-h),rgb(c,c,0),linecol
   paint(x,y+1),rgb(128,128,0),linecol
   paint(x-10,y+1),rgb(100,100,0),linecol
   paint(x+10,y+1),rgb(100,100,0),linecol
   paint(x-22,y+1),rgb(64,64,0),linecol
   paint(x+22,y+1),rgb(64,64,0),linecol

end sub

Return to “Projects”

Who is online

Users browsing this forum: No registered users and 1 guest